@@ -211,17 +211,17 @@ go 1.23.6
211
211
toolchain go1.23.8
212
212
213
213
require (
214
- github.com /celestiaorg/celestia-node v0.22.1
215
- github.com /celestiaorg/go -square/v2 v2.2.0
214
+ github.com /celestiaorg/celestia-node v0.22.1
215
+ github.com /celestiaorg/go -square/v2 v2.2.0
216
216
)
217
217
218
218
replace (
219
- github.com /cosmos/cosmos-sdk => github.com /celestiaorg/cosmos-sdk v1.28.2 -sdk-v0.46.16
220
- github.com /filecoin-project/dagstore => github.com /celestiaorg/dagstore v0.0.0 -20230824094345 -537c012aa403
221
- github.com /gogo/protobuf => github.com /regen-network/protobuf v1.3.3 -alpha.regen .1
222
- github.com /ipfs/boxo => github.com /celestiaorg/boxo v0.29.0 -fork
223
- github.com /syndtr/goleveldb => github.com /syndtr/goleveldb v1.0.1 -0.20210819022825 -2ae1ddf74ef7
224
- github.com /tendermint/tendermint => github.com /celestiaorg/celestia-core v1.51.0 -tm-v0.34.35
219
+ github.com /cosmos/cosmos-sdk => github.com /celestiaorg/cosmos-sdk v1.28.2 -sdk-v0.46.16
220
+ github.com /filecoin-project/dagstore => github.com /celestiaorg/dagstore v0.0.0 -20230824094345 -537c012aa403
221
+ github.com /gogo/protobuf => github.com /regen-network/protobuf v1.3.3 -alpha.regen .1
222
+ github.com /ipfs/boxo => github.com /celestiaorg/boxo v0.29.0 -fork
223
+ github.com /syndtr/goleveldb => github.com /syndtr/goleveldb v1.0.1 -0.20210819022825 -2ae1ddf74ef7
224
+ github.com /tendermint/tendermint => github.com /celestiaorg/celestia-core v1.51.0 -tm-v0.34.35
225
225
)
226
226
```
227
227
@@ -231,126 +231,126 @@ And here's the `main.go` file:
231
231
package main
232
232
233
233
import (
234
- " bytes"
235
- " context"
236
- " fmt"
237
- " os"
238
- " time"
239
-
240
- client " github.com/celestiaorg/celestia-node/api/rpc/client"
241
- " github.com/celestiaorg/celestia-node/blob"
242
- " github.com/celestiaorg/celestia-node/state"
243
- share " github.com/celestiaorg/go-square/v2/share"
234
+ " bytes"
235
+ " context"
236
+ " fmt"
237
+ " os"
238
+ " time"
239
+
240
+ client " github.com/celestiaorg/celestia-node/api/rpc/client"
241
+ " github.com/celestiaorg/celestia-node/blob"
242
+ " github.com/celestiaorg/celestia-node/state"
243
+ share " github.com/celestiaorg/go-square/v2/share"
244
244
)
245
245
246
246
func main () {
247
- // Set up a context with timeout
248
- ctx , cancel := context.WithTimeout (context.Background (), 5 *time.Minute )
249
- defer cancel ()
250
-
251
- // Default RPC URL and token (empty string if using --rpc.skip-auth)
252
- url := " http://localhost:26658"
253
- token := " " // Replace with your auth token if not using --rpc.skip-auth
254
-
255
- // Check if we can connect to the node first
256
- fmt.Println (" Testing connection to Celestia node..." )
257
- c , err := client.NewClient (ctx, url, token)
258
- if err != nil {
259
- fmt.Printf (" Failed to connect to node: %v \n " , err)
260
- os.Exit (1 )
261
- }
262
- defer c.Close ()
263
-
264
- fmt.Println (" Successfully connected to node, checking node status..." )
265
-
266
- // Try a simpler API call first - get network head to verify connectivity
267
- headerHeight , err := GetNetworkHead (ctx, c)
268
- if err != nil {
269
- fmt.Printf (" Failed to get network head: %v \n " , err)
270
- } else {
271
- fmt.Printf (" Current network height: %d \n " , headerHeight)
272
-
273
- // Now try blob submission
274
- err = SubmitBlob (ctx, url, token)
275
- if err != nil {
276
- fmt.Printf (" Blob submission error: %v \n " , err)
277
- }
278
- }
247
+ // Set up a context with timeout
248
+ ctx , cancel := context.WithTimeout (context.Background (), 5 *time.Minute )
249
+ defer cancel ()
250
+
251
+ // Default RPC URL and token (empty string if using --rpc.skip-auth)
252
+ url := " http://localhost:26658"
253
+ token := " " // Replace with your auth token if not using --rpc.skip-auth
254
+
255
+ // Check if we can connect to the node first
256
+ fmt.Println (" Testing connection to Celestia node..." )
257
+ c , err := client.NewClient (ctx, url, token)
258
+ if err != nil {
259
+ fmt.Printf (" Failed to connect to node: %v \n " , err)
260
+ os.Exit (1 )
261
+ }
262
+ defer c.Close ()
263
+
264
+ fmt.Println (" Successfully connected to node, checking node status..." )
265
+
266
+ // Try a simpler API call first - get network head to verify connectivity
267
+ headerHeight , err := GetNetworkHead (ctx, c)
268
+ if err != nil {
269
+ fmt.Printf (" Failed to get network head: %v \n " , err)
270
+ } else {
271
+ fmt.Printf (" Current network height: %d \n " , headerHeight)
272
+
273
+ // Now try blob submission
274
+ err = SubmitBlob (ctx, url, token)
275
+ if err != nil {
276
+ fmt.Printf (" Blob submission error: %v \n " , err)
277
+ }
278
+ }
279
279
}
280
280
281
281
// SubmitBlob submits a blob containing "Hello, World!" to the 0xDEADBEEF namespace
282
282
// and retrieves it from the network to verify the process works.
283
283
func SubmitBlob (ctx context .Context , url string , token string ) error {
284
- // Create a new client
285
- c , err := client.NewClient (ctx, url, token)
286
- if err != nil {
287
- return fmt.Errorf (" failed to create client: % w" , err)
288
- }
289
- defer c.Close () // Important to close the connection after use
284
+ // Create a new client
285
+ c , err := client.NewClient (ctx, url, token)
286
+ if err != nil {
287
+ return fmt.Errorf (" failed to create client: % w" , err)
288
+ }
289
+ defer c.Close () // Important to close the connection after use
290
290
291
- fmt.Println (" Connected to Celestia node" )
291
+ fmt.Println (" Connected to Celestia node" )
292
292
293
- // Create the 0xDEADBEEF namespace
294
- namespace , err := share.NewV0Namespace ([]byte {0xDE , 0xAD , 0xBE , 0xEF })
295
- if err != nil {
296
- return fmt.Errorf (" failed to create namespace: % w" , err)
297
- }
293
+ // Create the 0xDEADBEEF namespace
294
+ namespace , err := share.NewV0Namespace ([]byte {0xDE , 0xAD , 0xBE , 0xEF })
295
+ if err != nil {
296
+ return fmt.Errorf (" failed to create namespace: % w" , err)
297
+ }
298
298
299
- // Create a blob with "Hello, World!" content
300
- message := []byte (" Hello, World!" )
301
- helloWorldBlob , err := blob.NewBlobV0 (namespace, message)
302
- if err != nil {
303
- return fmt.Errorf (" failed to create blob: % w" , err)
304
- }
299
+ // Create a blob with "Hello, World!" content
300
+ message := []byte (" Hello, World!" )
301
+ helloWorldBlob , err := blob.NewBlobV0 (namespace, message)
302
+ if err != nil {
303
+ return fmt.Errorf (" failed to create blob: % w" , err)
304
+ }
305
305
306
- fmt.Println (" Submitting blob to the network..." )
306
+ fmt.Println (" Submitting blob to the network..." )
307
307
308
- // Create basic TxConfig instead of passing nil
309
- options := state.NewTxConfig ()
308
+ // Create basic TxConfig instead of passing nil
309
+ options := state.NewTxConfig ()
310
310
311
- // Submit the blob to the network with the options
312
- height , err := c.Blob .Submit (ctx, []*blob.Blob {helloWorldBlob}, options)
313
- if err != nil {
314
- return fmt.Errorf (" failed to submit blob: % w" , err)
315
- }
311
+ // Submit the blob to the network with the options
312
+ height , err := c.Blob .Submit (ctx, []*blob.Blob {helloWorldBlob}, options)
313
+ if err != nil {
314
+ return fmt.Errorf (" failed to submit blob: % w" , err)
315
+ }
316
316
317
- fmt.Printf (" Success! Blob was included at height %d \n " , height)
317
+ fmt.Printf (" Success! Blob was included at height %d \n " , height)
318
318
319
- // Wait a moment to ensure the blob is available for retrieval
320
- time.Sleep (2 * time.Second )
319
+ // Wait a moment to ensure the blob is available for retrieval
320
+ time.Sleep (2 * time.Second )
321
321
322
- fmt.Println (" Retrieving blob from the network..." )
322
+ fmt.Println (" Retrieving blob from the network..." )
323
323
324
- // Fetch the blob back from the network
325
- retrievedBlobs , err := c.Blob .GetAll (ctx, height, []share.Namespace {namespace})
326
- if err != nil {
327
- return fmt.Errorf (" failed to retrieve blob: % w" , err)
328
- }
324
+ // Fetch the blob back from the network
325
+ retrievedBlobs , err := c.Blob .GetAll (ctx, height, []share.Namespace {namespace})
326
+ if err != nil {
327
+ return fmt.Errorf (" failed to retrieve blob: % w" , err)
328
+ }
329
329
330
- if len (retrievedBlobs) == 0 {
331
- return fmt.Errorf (" no blobs retrieved from height %d " , height)
332
- }
330
+ if len (retrievedBlobs) == 0 {
331
+ return fmt.Errorf (" no blobs retrieved from height %d " , height)
332
+ }
333
333
334
- // Verify the retrieved blob matches the submitted blob
335
- equal := bytes.Equal (helloWorldBlob.Commitment , retrievedBlobs[0 ].Commitment )
336
- fmt.Printf (" Retrieved blob successfully! Blobs are equal? %v \n " , equal)
334
+ // Verify the retrieved blob matches the submitted blob
335
+ equal := bytes.Equal (helloWorldBlob.Commitment , retrievedBlobs[0 ].Commitment )
336
+ fmt.Printf (" Retrieved blob successfully! Blobs are equal? %v \n " , equal)
337
337
338
- // Verify the content is what we expect
339
- fmt.Printf (" Original message: %s \n " , message)
340
- fmt.Printf (" Retrieved message: %s \n " , retrievedBlobs[0 ].Data )
338
+ // Verify the content is what we expect
339
+ fmt.Printf (" Original message: %s \n " , message)
340
+ fmt.Printf (" Retrieved message: %s \n " , retrievedBlobs[0 ].Data )
341
341
342
- return nil
342
+ return nil
343
343
}
344
344
345
345
// GetNetworkHead retrieves the current network height
346
346
func GetNetworkHead (ctx context .Context , c *client .Client ) (uint64 , error ) {
347
- // Get the network head
348
- header , err := c.Header .NetworkHead (ctx)
349
- if err != nil {
350
- return 0 , fmt.Errorf (" failed to get network head: % w" , err)
351
- }
347
+ // Get the network head
348
+ header , err := c.Header .NetworkHead (ctx)
349
+ if err != nil {
350
+ return 0 , fmt.Errorf (" failed to get network head: % w" , err)
351
+ }
352
352
353
- return header.Height (), nil
353
+ return header.Height (), nil
354
354
}
355
355
```
356
356
0 commit comments