Skip to content

Commit ef3dd2b

Browse files
committed
fix(): fix bundler tx
1 parent 468b1a0 commit ef3dd2b

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

README.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ bundle, err := utils.NewBundle(items...)
324324
#### Send Item to Bundler
325325
Bundler network provides guaranteed data seeding and instant data accessibility
326326
```go
327-
resp, err := w.Client.BatchSendItemToBundler(items)
327+
resp, err := w.Client.BatchSendItemToBundler(items,"") // The second parameter is the bundler gateway url,"" means use default url
328328
```
329329

330330
#### Send Bundle Tx
@@ -343,4 +343,36 @@ for _, item := range bundle.Items {
343343
assert.NoError(t, err)
344344
}
345345
```
346+
347+
### notice
348+
if you call `w.Client.BatchSendItemToBundler(items,"")`
349+
and return `panic: send to bundler request failed; http code: 402`
350+
means that you have to pay ar to the bundler service address
351+
must use item signature address to transfer funds
352+
353+
##### how to get bundler service address?
354+
```go
355+
curl --location --request GET 'https://node1.bundlr.network/info'
356+
357+
response:
358+
{
359+
"uptime": 275690.552536824,
360+
"address": "OXcT1sVRSA5eGwt2k6Yuz8-3e3g9WJi5uSE99CWqsBs",
361+
"gateway": "arweave.net"
362+
}
363+
```
364+
This "address" is the bundler service receive ar address.
365+
You need to transfer a certain amount of ar to this address
366+
and wait for 25 blocks to confirm the transaction before you can use the bundler service.
367+
368+
You can also use the following api to query the balance in the bundler service.
369+
```
370+
curl --location --request GET 'https://node1.bundlr.network/account/balance?address=Ii5wAMlLNz13n26nYY45mcZErwZLjICmYd46GZvn4ck'
371+
372+
response:
373+
{
374+
"balance": 1000000000
375+
}
376+
```
377+
346378
---

client_bundle.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ func (c *Client) GetBundle(arId string) (*types.Bundle, error) {
2020
}
2121

2222
// SendItemToBundler send bundle bundleItem to bundler gateway
23-
func (c *Client) SendItemToBundler(itemBinary []byte) (*types.BundlerResp, error) {
23+
func (c *Client) SendItemToBundler(itemBinary []byte, gateway string) (*types.BundlerResp, error) {
24+
if gateway == "" {
25+
gateway = types.BUNDLER_HOST
26+
}
2427
// post to bundler
25-
resp, err := http.DefaultClient.Post(types.BUNDLER_HOST+"/tx", "application/octet-stream", bytes.NewReader(itemBinary))
28+
resp, err := http.DefaultClient.Post(gateway+"/tx", "application/octet-stream", bytes.NewReader(itemBinary))
2629
if err != nil {
2730
return nil, err
2831
}
@@ -43,7 +46,7 @@ func (c *Client) SendItemToBundler(itemBinary []byte) (*types.BundlerResp, error
4346
return br, nil
4447
}
4548

46-
func (c *Client) BatchSendItemToBundler(bundleItems []types.BundleItem) ([]*types.BundlerResp, error) {
49+
func (c *Client) BatchSendItemToBundler(bundleItems []types.BundleItem, gateway string) ([]*types.BundlerResp, error) {
4750
respList := make([]*types.BundlerResp, 0, len(bundleItems))
4851
for _, item := range bundleItems {
4952
itemBinary := item.ItemBinary
@@ -53,7 +56,7 @@ func (c *Client) BatchSendItemToBundler(bundleItems []types.BundleItem) ([]*type
5356
}
5457
itemBinary = item.ItemBinary
5558
}
56-
resp, err := c.SendItemToBundler(itemBinary)
59+
resp, err := c.SendItemToBundler(itemBinary, gateway)
5760
if err != nil {
5861
return nil, err
5962
}

example/bundle_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ func TestBundle_SendBundleTx(t *testing.T) {
4747

4848
// // send item to bundler gateway
4949
// for _, item := range items {
50-
// resp, err := w.Client.SendItemToBundler(item.ItemBinary)
50+
// resp, err := w.Client.SendItemToBundler(item.ItemBinary,"")
5151
// assert.NoError(t, err)
5252
// t.Log(resp.Id)
5353
// }
54-
resp, err := w.Client.BatchSendItemToBundler(items)
54+
resp, err := w.Client.BatchSendItemToBundler(items, "")
5555
assert.NoError(t, err)
5656
t.Log(resp)
5757

types/const.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ var FATAL_CHUNK_UPLOAD_ERRORS = map[string]struct{}{
4545

4646
// about bundle
4747
const (
48-
BUNDLER_HOST = "http://bundler.arweave.net:10000"
48+
BUNDLER_HOST = "https://node1.bundlr.network"
4949
MIN_BUNDLE_BINARY_SIZE = 1044
5050
)

0 commit comments

Comments
 (0)