Skip to content

Commit 5bb63d0

Browse files
committed
feat: first draft of Celestia Node RPC Client
To run the test, running celestia node is needed, version from: celestiaorg/celestia-node#693
1 parent 308322f commit 5bb63d0

File tree

8 files changed

+198
-0
lines changed

8 files changed

+198
-0
lines changed

go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.17
55
require (
66
github.com/dgraph-io/badger/v3 v3.2103.2
77
github.com/go-kit/kit v0.12.0
8+
github.com/go-resty/resty/v2 v2.7.0
89
github.com/gogo/protobuf v1.3.2
910
github.com/google/orderedcode v0.0.1
1011
github.com/gorilla/rpc v1.2.0
@@ -15,6 +16,7 @@ require (
1516
github.com/libp2p/go-libp2p-kad-dht v0.15.0
1617
github.com/libp2p/go-libp2p-pubsub v0.6.1
1718
github.com/multiformats/go-multiaddr v0.5.0
19+
github.com/ory/dockertest v3.3.5+incompatible
1820
github.com/prometheus/client_golang v1.12.2
1921
github.com/rs/cors v1.8.2
2022
github.com/spf13/cobra v1.4.0
@@ -27,22 +29,28 @@ require (
2729
)
2830

2931
require (
32+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
3033
github.com/DataDog/zstd v1.4.5 // indirect
34+
github.com/Microsoft/go-winio v0.5.1 // indirect
35+
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
3136
github.com/Workiva/go-datastructures v1.0.53 // indirect
3237
github.com/benbjohnson/clock v1.3.0 // indirect
3338
github.com/beorn7/perks v1.0.1 // indirect
3439
github.com/btcsuite/btcd v0.22.0-beta // indirect
40+
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
3541
github.com/cespare/xxhash v1.1.0 // indirect
3642
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3743
github.com/cheekybits/genny v1.0.0 // indirect
3844
github.com/containerd/cgroups v1.0.3 // indirect
45+
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 // indirect
3946
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
4047
github.com/cosmos/go-bip39 v1.0.0 // indirect
4148
github.com/davecgh/go-spew v1.1.1 // indirect
4249
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
4350
github.com/dgraph-io/badger/v2 v2.2007.2 // indirect
4451
github.com/dgraph-io/ristretto v0.1.0 // indirect
4552
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
53+
github.com/docker/go-connections v0.4.0 // indirect
4654
github.com/docker/go-units v0.4.0 // indirect
4755
github.com/dustin/go-humanize v1.0.0 // indirect
4856
github.com/elastic/gosigar v0.14.2 // indirect
@@ -143,6 +151,9 @@ require (
143151
github.com/nxadm/tail v1.4.8 // indirect
144152
github.com/onsi/ginkgo v1.16.5 // indirect
145153
github.com/onsi/gomega v1.16.0 // indirect
154+
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
155+
github.com/opencontainers/image-spec v1.0.2 // indirect
156+
github.com/opencontainers/runc v1.0.2 // indirect
146157
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
147158
github.com/opentracing/opentracing-go v1.2.0 // indirect
148159
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
@@ -158,6 +169,7 @@ require (
158169
github.com/raulk/clock v1.1.0 // indirect
159170
github.com/raulk/go-watchdog v1.2.0 // indirect
160171
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
172+
github.com/sirupsen/logrus v1.8.1 // indirect
161173
github.com/smartystreets/assertions v1.0.1 // indirect
162174
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
163175
github.com/spaolacci/murmur3 v1.1.0 // indirect

go.sum

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOv
6363
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
6464
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
6565
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
66+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
6667
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
6768
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
6869
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
@@ -78,6 +79,9 @@ github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go
7879
github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
7980
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
8081
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
82+
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
83+
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
84+
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
8185
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
8286
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
8387
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
@@ -152,6 +156,7 @@ github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46f
152156
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
153157
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
154158
github.com/casbin/casbin/v2 v2.37.0/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg=
159+
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
155160
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
156161
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
157162
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@@ -180,6 +185,7 @@ github.com/containerd/cgroups v0.0.0-20201119153540-4cbc285b3327/go.mod h1:ZJeTF
180185
github.com/containerd/cgroups v1.0.3 h1:ADZftAkglvCiD44c77s5YmMqaP2pzVCFZvBmAlBdAP4=
181186
github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8=
182187
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
188+
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
183189
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
184190
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
185191
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
@@ -235,6 +241,7 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUn
235241
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=
236242
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
237243
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
244+
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
238245
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
239246
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
240247
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
@@ -296,6 +303,8 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
296303
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
297304
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
298305
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
306+
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
307+
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
299308
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
300309
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
301310
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
@@ -423,6 +432,7 @@ github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
423432
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
424433
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
425434
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
435+
github.com/gotestyourself/gotestyourself v2.2.0+incompatible h1:AQwinXlbQR2HvPjQZOmDhRqsv5mZf+Jb1RnSLxcqZcI=
426436
github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY=
427437
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
428438
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
@@ -1109,9 +1119,13 @@ github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je4
11091119
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
11101120
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
11111121
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
1122+
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
11121123
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
11131124
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
1125+
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
1126+
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
11141127
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
1128+
github.com/opencontainers/runc v1.0.2 h1:opHZMaswlyxz1OuGpBE53Dwe4/xF7EZTY0A2L/FpCOg=
11151129
github.com/opencontainers/runc v1.0.2/go.mod h1:aTaHFFwQXuA71CiyxOdFFIorAoemI04suvGRQFzWTD0=
11161130
github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
11171131
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 h1:3snG66yBm59tKhhSPQrQ/0bCrv1LQbKt40LnUPiUxdc=
@@ -1129,6 +1143,7 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
11291143
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
11301144
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
11311145
github.com/openzipkin/zipkin-go v0.2.5/go.mod h1:KpXfKdgRDnnhsxw4pNIH9Md5lyFqKUa4YDFlwRYAMyE=
1146+
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
11321147
github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs=
11331148
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
11341149
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
@@ -1264,6 +1279,7 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
12641279
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
12651280
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
12661281
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
1282+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
12671283
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
12681284
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
12691285
github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w=
@@ -1575,6 +1591,7 @@ golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qx
15751591
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
15761592
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
15771593
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1594+
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
15781595
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
15791596
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
15801597
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
@@ -2011,6 +2028,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
20112028
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20122029
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
20132030
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2031+
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
20142032
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
20152033
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
20162034
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

libs/cnrc/client.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package cnrc
2+
3+
import (
4+
"encoding/hex"
5+
"fmt"
6+
"github.com/go-resty/resty/v2"
7+
"strconv"
8+
)
9+
10+
type Client struct {
11+
c *resty.Client
12+
}
13+
14+
func NewClient(baseURL string, options ...Option) (*Client, error) {
15+
c := &Client{
16+
c: resty.New(),
17+
}
18+
19+
c.c.SetBaseURL(baseURL)
20+
c.c.SetAllowGetMethodPayload(true)
21+
22+
for _, option := range options {
23+
if err := option(c); err != nil {
24+
return nil, err
25+
}
26+
}
27+
28+
return c, nil
29+
}
30+
31+
func (c *Client) Header(height uint64) /* Header */ error {
32+
resp, err := c.c.R().
33+
SetPathParam(heightKey, strconv.FormatUint(height, 10)).
34+
Get(headerPath())
35+
fmt.Println(resp, err)
36+
return err
37+
}
38+
39+
func (c *Client) Balance() error {
40+
panic("Balance not implemented")
41+
return nil
42+
}
43+
44+
func (c *Client) SubmitTx(tx []byte) /* TxResponse */ error {
45+
panic("SubmitTx not implemented")
46+
return nil
47+
}
48+
49+
func (c *Client) SubmitPFD(namespaceID [8]byte, data []byte, gasLimit uint64) /* TxResponse */ error {
50+
panic("SubmitPFD not implemented")
51+
return nil
52+
}
53+
54+
func (c *Client) NamespacedShares(namespaceID [8]byte, height uint64) error {
55+
req := SharesByNamespaceRequest{
56+
NamespaceID: hex.EncodeToString(namespaceID[:]),
57+
Height: height,
58+
}
59+
resp, err := c.c.R().
60+
SetBody(req).
61+
Get(namespacedSharesEndpoint)
62+
if err != nil {
63+
return err
64+
}
65+
66+
fmt.Println(resp.Body())
67+
68+
return nil
69+
}
70+
71+
func headerPath() string {
72+
return fmt.Sprintf("%s/{%s}", headerEndpoint, heightKey)
73+
}

libs/cnrc/client_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package cnrc
2+
3+
import (
4+
"github.com/ory/dockertest"
5+
"github.com/stretchr/testify/assert"
6+
"log"
7+
"os"
8+
"testing"
9+
"time"
10+
)
11+
12+
func TestNewClient(t *testing.T) {
13+
cases := []struct {
14+
name string
15+
options []Option
16+
expectedError error
17+
}{
18+
{"without options", nil, nil},
19+
{"with timeout", []Option{WithTimeout(1 * time.Second)}, nil},
20+
}
21+
22+
for _, c := range cases {
23+
t.Run(c.name, func(t *testing.T) {
24+
client, err := NewClient("", c.options...)
25+
assert.ErrorIs(t, err, c.expectedError)
26+
if c.expectedError != nil {
27+
assert.Nil(t, client)
28+
} else {
29+
assert.NotNil(t, client)
30+
}
31+
})
32+
}
33+
}
34+
35+
func TestNamespacedShares(t *testing.T) {
36+
client, err := NewClient("http://localhost:26658")
37+
assert.NoError(t, err)
38+
assert.NotNil(t, client)
39+
40+
err = client.NamespacedShares([8]byte{0, 0, 0, 0, 0, 0, 0, 1}, 2)
41+
assert.NoError(t, err)
42+
}
43+
44+
var pool *dockertest.Pool
45+
46+
func TestMain(m *testing.M) {
47+
var err error
48+
pool, err = dockertest.NewPool("")
49+
if err != nil {
50+
log.Fatalf("Could not connect to docker: %s", err)
51+
os.Exit(1)
52+
}
53+
code := m.Run()
54+
os.Exit(code)
55+
}

libs/cnrc/consts.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cnrc
2+
3+
const (
4+
headerEndpoint = "/header"
5+
balanceEndpoint = "/balance"
6+
submitTxEndpoint = "/submit_tx"
7+
submitPFDEndpoint = "/submit_pfd"
8+
namespacedSharesEndpoint = "/namespaced_shares"
9+
10+
heightKey = "height"
11+
)

libs/cnrc/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package cnrc implements a Celestia Node RPC Client
2+
package cnrc

libs/cnrc/options.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cnrc
2+
3+
import "time"
4+
5+
type Option func(*Client) error
6+
7+
func WithTimeout(timeout time.Duration) Option {
8+
return func(c *Client) error {
9+
c.c.SetTimeout(timeout)
10+
return nil
11+
}
12+
}

libs/cnrc/types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cnrc
2+
3+
// SubmitPFDRequest represents a request to submit a PayForData transaction.
4+
type SubmitPFDRequest struct {
5+
NamespaceID string `json:"namespace_id"`
6+
Data string `json:"data"`
7+
GasLimit uint64 `json:"gas_limit"`
8+
}
9+
10+
// SharesByNamespaceRequest represents a `GetSharesByNamespace`
11+
// request payload
12+
type SharesByNamespaceRequest struct {
13+
NamespaceID string `json:"namespace_id"`
14+
Height uint64 `json:"height"`
15+
}

0 commit comments

Comments
 (0)