@@ -8,15 +8,14 @@ go get github.com/everFinance/goar
8
8
9
9
### Example
10
10
11
- Send winston
11
+ #### Send AR or Winston
12
12
13
13
``` golang
14
14
package main
15
15
16
16
import (
17
17
" fmt"
18
18
" math/big"
19
-
20
19
" github.com/everFinance/goar/types"
21
20
" github.com/everFinance/goar"
22
21
)
@@ -27,54 +26,51 @@ func main() {
27
26
panic (err)
28
27
}
29
28
30
- id , err := wallet.SendWinston (
31
- big.NewInt (1 ), // Winston amount
29
+ id , err := wallet.SendAR (
30
+ // id, err := wallet.SendWinston(
31
+ big.NewFloat (1.0 ), // AR amount
32
32
{{target}}, // target address
33
- []types.Tag {
34
- types.Tag {
35
- Name: " testSendWinston" ,
36
- Value: " 1" ,
37
- },
38
- },
33
+ []types.Tag {},
39
34
)
40
35
41
36
fmt.Println (id, err) // {{id}}, nil
42
37
}
43
38
44
39
```
45
40
46
- Send Data
41
+ #### Send Data
47
42
48
43
``` golang
49
- package main
50
-
51
- import (
52
- " fmt"
53
-
54
- " github.com/everFinance/goar/types"
55
- " github.com/everFinance/goar"
44
+ id , err := wallet.SendData (
45
+ []byte (" 123" ), // Data bytes
46
+ []types.Tag {
47
+ types.Tag {
48
+ Name: " testSendData" ,
49
+ Value: " 123" ,
50
+ },
51
+ },
56
52
)
57
53
58
- func main () {
59
- wallet , err := goar.NewWalletFromPath (" ./test-keyfile.json" , " https://arweave.net" )
60
- if err != nil {
61
- panic (err)
62
- }
54
+ fmt.Println (id, err) // {{id}}, nil
55
+ ```
63
56
64
- id , err := wallet.SendData (
65
- []byte (" 123" ), // Data bytes
66
- []types.Tag {
67
- types.Tag {
68
- Name: " testSendData" ,
69
- Value: " 123" ,
70
- },
71
- },
72
- )
57
+ #### Send Data SpeedUp
73
58
74
- fmt.Println (id, err) // {{id}}, nil
75
- }
76
- ```
59
+ Arweave occasionally experiences congestion, and a low Reward can cause a transaction to fail; use speedUp to accelerate the transaction.
77
60
61
+ ``` golang
62
+ speedUp := int64 (50 ) // means reward = reward * 150%
63
+ id , err := wallet.SendDataSpeedUp (
64
+ []byte (" 123" ), // Data bytes
65
+ []types.Tag {
66
+ types.Tag {
67
+ Name: " testSendDataSpeedUp" ,
68
+ Value: " 123" ,
69
+ },
70
+ },speedUp)
71
+
72
+ fmt.Println (id, err) // {{id}}, nil
73
+ ```
78
74
### Components
79
75
80
76
#### Client
@@ -93,6 +89,8 @@ func main() {
93
89
- [x] GetLastTransactionID
94
90
- [x] GetBlockByID
95
91
- [x] GetBlockByHeight
92
+ - [x] BatchSendItemToBundler
93
+ - [x] GetBundle
96
94
97
95
Initialize the instance:
98
96
@@ -113,6 +111,9 @@ arClient := goar.NewClient("https://arweave.net", proxyUrl)
113
111
- [x] SendData
114
112
- [x] SendDataSpeedUp
115
113
- [x] SendTransaction
114
+ - [x] CreateAndSignBundleItem
115
+ - [x] SendBundleTxSpeedUp
116
+ - [x] SendBundleTx
116
117
117
118
Initialize the instance, use a keyfile.json:
118
119
@@ -144,6 +145,7 @@ Package for Arweave develop toolkit.
144
145
- [x] SignTransaction
145
146
- [x] GetSignatureData
146
147
- [x] VerifyTransaction
148
+ - [x] NewBundle
147
149
148
150
#### RSA Threshold Cryptography
149
151
@@ -175,8 +177,8 @@ signedData01, err := ts.ThresholdSign(signer01)
175
177
176
178
// assemble sign
177
179
signedShares := tcrsa.SigShareList {
178
- signedData01,
179
- ...
180
+ signedData01,
181
+ ...
180
182
}
181
183
signature , err := ts.AssembleSigShares (signedShares)
182
184
@@ -203,66 +205,66 @@ The method of sumbitting a data transaction is to use chunk uploading. This meth
203
205
Simple example:
204
206
205
207
``` golang
206
- arNode := " https://arweave.net"
207
- w , err := goar.NewWalletFromPath (" ../example/testKey.json" , arNode) // your wallet private key
208
- anchor , err := w.Client .GetTransactionAnchor ()
209
- if err != nil {
210
- return
211
- }
212
- data , err := ioutil.ReadFile (" ./2.3MBPhoto.jpg" )
213
- if err != nil {
214
- return
215
- }
216
- tx.LastTx = anchor
217
- reward , err := w.Client .GetTransactionPrice (data, nil )
218
- if err != nil {
219
- return
220
- }
208
+ arNode := " https://arweave.net"
209
+ w , err := goar.NewWalletFromPath (" ../example/testKey.json" , arNode) // your wallet private key
210
+ anchor , err := w.Client .GetTransactionAnchor ()
211
+ if err != nil {
212
+ return
213
+ }
214
+ data , err := ioutil.ReadFile (" ./2.3MBPhoto.jpg" )
215
+ if err != nil {
216
+ return
217
+ }
218
+ tx.LastTx = anchor
219
+ reward , err := w.Client .GetTransactionPrice (data, nil )
220
+ if err != nil {
221
+ return
222
+ }
221
223
222
- tx := &types.Transaction {
223
- Format : 2 ,
224
- Target : " " ,
225
- Quantity : " 0" ,
226
- Tags : utils.TagsEncode (tags),
227
- Data : utils.Base64Encode (data),
228
- DataSize : fmt.Sprintf (" %d " , len (data)),
229
- Reward : fmt.Sprintf (" %d " , reward*(100 +speedFactor)/100 ),
230
- }
231
- if err = utils.SignTransaction (tx, w.PubKey , w.PrvKey ); err != nil {
232
- return
233
- }
224
+ tx := &types.Transaction {
225
+ Format : 2 ,
226
+ Target : " " ,
227
+ Quantity : " 0" ,
228
+ Tags : utils.TagsEncode (tags),
229
+ Data : utils.Base64Encode (data),
230
+ DataSize : fmt.Sprintf (" %d " , len (data)),
231
+ Reward : fmt.Sprintf (" %d " , reward*(100 +speedFactor)/100 ),
232
+ }
233
+ if err = utils.SignTransaction (tx, w.PubKey , w.PrvKey ); err != nil {
234
+ return
235
+ }
234
236
235
- id = tx.ID
237
+ id = tx.ID
236
238
237
- uploader , err := goar.CreateUploader (w.Client , tx, nil )
238
- if err != nil {
239
- return
240
- }
241
- for !uploader.IsComplete () {
242
- err = uploader.UploadChunk ()
243
- if err != nil {
244
- return
245
- }
246
- }
239
+ uploader , err := goar.CreateUploader (w.Client , tx, nil )
240
+ if err != nil {
241
+ return
242
+ }
243
+ for !uploader.IsComplete () {
244
+ err = uploader.UploadChunk ()
245
+ if err != nil {
246
+ return
247
+ }
248
+ }
247
249
```
248
250
249
251
##### Breakpoint continuingly
250
252
251
253
You can resume an upload from a saved uploader object, that you have persisted in storage some using json.marshal(uploader) at any stage of the upload.To resume, parse it back into an object and pass it to getUploader() along with the transactions data:
252
254
253
255
``` golang
254
- uploaderBuf , err := ioutil.ReadFile (" ./jsonUploaderFile.json" )
255
- lastUploader := &txType.TransactionUploader {}
256
- err = json.Unmarshal (uploaderBuf, lastUploader)
257
- assert.NoError (t, err)
258
-
259
- // new uploader object by last time uploader
260
- newUploader , err := txType.CreateUploader (wallet.Client , lastUploader.FormatSerializedUploader (), bigData)
261
- assert.NoError (t, err)
262
- for !newUploader.IsComplete () {
263
- err := newUploader.UploadChunk ()
264
- assert.NoError (t, err)
265
- }
256
+ uploaderBuf , err := ioutil.ReadFile (" ./jsonUploaderFile.json" )
257
+ lastUploader := &txType.TransactionUploader {}
258
+ err = json.Unmarshal (uploaderBuf, lastUploader)
259
+ assert.NoError (t, err)
260
+
261
+ // new uploader object by last time uploader
262
+ newUploader , err := txType.CreateUploader (wallet.Client , lastUploader.FormatSerializedUploader (), bigData)
263
+ assert.NoError (t, err)
264
+ for !newUploader.IsComplete () {
265
+ err := newUploader.UploadChunk ()
266
+ assert.NoError (t, err)
267
+ }
266
268
```
267
269
268
270
When resuming the upload, you must provide the same data as the original upload. When you serialize the uploader object with json.marshal() to save it somewhere, it will not include the data.
@@ -272,17 +274,71 @@ When resuming the upload, you must provide the same data as the original upload.
272
274
You can also resume an upload from just the transaction ID and data, once it has been mined into a block. This can be useful if you didn't save the uploader somewhere but the upload got interrupted. This will re-upload all of the data from the beginning, since we don't know which parts have been uploaded:
273
275
274
276
``` golang
275
- bigData , err := ioutil.ReadFile (filePath)
276
- txId := " myTxId"
277
-
278
- // get uploader by txId and post big data by chunks
279
- uploader , err := goar.CreateUploader (wallet.Client , txId, bigData)
280
- assert.NoError (t, err)
281
- for !uploader.IsComplete () {
282
- err := uploader.UploadChunk ()
283
- assert.NoError (t, err)
284
- }
277
+ bigData , err := ioutil.ReadFile (filePath)
278
+ txId := " myTxId"
279
+
280
+ // get uploader by txId and post big data by chunks
281
+ uploader , err := goar.CreateUploader (wallet.Client , txId, bigData)
282
+ assert.NoError (t, err)
283
+ for !uploader.IsComplete () {
284
+ err := uploader.UploadChunk ()
285
+ assert.NoError (t, err)
286
+ }
285
287
```
286
288
287
289
##### NOTE: About all chunk transfer full example can be viewed in path ` ./example/chunks_tx_test.go `
290
+
288
291
---
292
+ ### About Arweave Bundles
293
+ 1 . ` goar ` implemented creating,editing,reading and verifying bundles tx
294
+ 2 . This is the [ ANS-104] ( https://github.com/joshbenaron/arweave-standards/blob/ans104/ans/ANS-104.md ) standard protocol and refers to the [ arbundles] ( https://github.com/Bundler-Network/arbundles ) js-lib implement
295
+ 3 . more example can be viewed in path ` ./example/bundle_test.go `
296
+
297
+ #### CreateBundle
298
+ ``` go
299
+ w , err := goar.NewWalletFromPath (privateKey, arNode)
300
+ if err != nil {
301
+ panic (err)
302
+ }
303
+
304
+ // Create Item
305
+ data := []byte (" upload update..." )
306
+ signatureType := 1 // currently only supply type 1
307
+ target := " " // option
308
+ anchor := " " // option
309
+ tags := []types.Tags {}{} // bundle item tags
310
+ item01 , err := w.CreateAndSignBundleItem (data, 1 , target, anchor, tags)
311
+ // Same as create item
312
+ item02
313
+ item03
314
+ ....
315
+
316
+ items := []types.BundleItem {item01, item02, item03 ...}
317
+
318
+ bundle , err := utils.NewBundle (items...)
319
+
320
+ ```
321
+
322
+ #### Send Item to Bundler
323
+ It is not necessary, The purpose is to create an index for the Bundler gateway
324
+ ``` go
325
+ resp , err := w.Client .BatchSendItemToBundler (items)
326
+ ```
327
+
328
+ #### Send Bundle Tx
329
+ ``` go
330
+ txId , err := w.SendBundleTx (bd.BundleBinary , arTxtags)
331
+ ```
332
+
333
+ #### Get Bundle and Verify
334
+ ``` go
335
+ id := " lt24bnUGms5XLZeVamSPHePl4M2ClpLQyRxZI7weH1k"
336
+ bundle , err := cli.GetBundle (id)
337
+
338
+ // verify
339
+ for _ , item := range bundle.Items {
340
+ err = utils.VerifyBundleItem (item)
341
+ assert.NoError (t, err)
342
+ }
343
+ ```
344
+ ---
0 commit comments