-
Notifications
You must be signed in to change notification settings - Fork 13
/
microstellar_test.go
643 lines (497 loc) · 21.4 KB
/
microstellar_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
package microstellar
import (
"fmt"
"log"
"time"
)
func Example() {
// Create a new MicroStellar client connected to a mock network. The client is not
// thread-safe, however you can create as many instances as you need.
ms := New("fake")
// Generate a new random keypair.
pair, _ := ms.CreateKeyPair()
// In stellar, you can create all kinds of asset types -- dollars, houses, kittens. These
// customized assets are called credit assets.
//
// However, the native asset is always lumens (XLM). Lumens are used to pay for transactions
// on the stellar network, and are used to fund the operations of Stellar.
//
// When you first create a key pair, you need to fund it with atleast 0.5 lumens. This
// is called the "base reserve", and makes the account valid. You can only transact to
// and from accounts that maintain the base reserve.
ms.FundAccount("S6H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", pair.Address, "1")
// On the test network, you can ask FriendBot to fund your account. You don't need to buy
// lumens. (If you do want to buy lumens for the test network, call me!)
FundWithFriendBot(pair.Address)
// Now load the account from the ledger and check its balance.
account, _ := ms.LoadAccount(pair.Address)
log.Printf("Native Balance: %v XLM", account.GetNativeBalance())
// Note that we used GetNativeBalance() above, which implies lumens as the asset. You
// could also do the following.
log.Printf("Native Balance: %v XLM", account.GetBalance(NativeAsset))
// Pay your buddy 3 lumens.
ms.PayNative("S6H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA",
"GAUYTZ24ATLEBIV63MXMPOPQO2T6NHI6TQYEXRTFYXWYZ3JOCVO6UYUM", "3")
// Alternatively, be explicit about lumens.
ms.Pay("S6H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA",
"GAUYTZ24ATLEBIV63MXMPOPQO2T6NHI6TQYEXRTFYXWYZ3JOCVO6UYUM", "3", NativeAsset)
// Create a credit asset called USD issued by anchor GAT5GKDILNY2G6NOBEIX7XMGSPPZD5MCHZ47MGTW4UL6CX55TKIUNN53
USD := NewAsset("USD", "GAT5GKDILNY2G6NOBEIX7XMGSPPZD5MCHZ47MGTW4UL6CX55TKIUNN53", Credit4Type)
// Pay your buddy 3 USD and add a memo
ms.Pay("S6H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA",
"GAUYTZ24ATLEBIV63MXMPOPQO2T6NHI6TQYEXRTFYXWYZ3JOCVO6UYUM",
"3", USD,
Opts().WithMemoText("for beer"))
// Create a trust line to the USD credit asset with a limit of 1000.
ms.CreateTrustLine("S4H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", USD, "10000")
// Check your balances.
account, _ = ms.LoadAccount("GAUYTZ24ATLEBIV63MXMPOPQO2T6NHI6TQYEXRTFYXWYZ3JOCVO6UYUM")
log.Printf("USD Balance: %v USD", account.GetBalance(USD))
log.Printf("Native Balance: %v XLM", account.GetNativeBalance())
// Find your home domain.
log.Printf("Home domain: %s", account.HomeDomain)
// Who are the signers on the account?
for i, s := range account.Signers {
log.Printf("Signer %d (weight: %v): %v", i, s.PublicKey, s.Weight)
}
log.Printf("ok")
}
func Example_multisig() {
// Create a new MicroStellar client connected to a mock network.
ms := New("fake")
// Add two signers to the source account with weight 1 each
ms.AddSigner(
"S8H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", // source account
"G6H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", // signer address
1) // weight
ms.AddSigner(
"S8H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", // source account
"G9H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGB", // signer address
1) // weight
// Set the low, medium, and high thresholds of the account. (Here we require a minimum
// total signing weight of 2 for all operations.)
ms.SetThresholds("S8H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", 2, 2, 2)
// Kill the master weight of account, so only the new signers can sign transactions
ms.SetMasterWeight("S8H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", 0,
Opts().WithSigner("S2H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA"))
// Make a payment (and sign with new signers). Note that the first parameter (source) here
// can be an address instead of a seed (since the seed can't sign anymore.)
ms.PayNative(
"G6H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA", // from
"GAUYTZ24ATLEBIV63MXMPOPQO2T6NHI6TQYEXRTFYXWYZ3JOCVO6UYUM", // to
"3", // amount
Opts().
WithSigner("S1H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA").
WithSigner("S2H4HQPE6BRZKLK3QNV6LTD5BGS7S6SZPU3PUGMJDJ26V7YRG3FRNPGA"))
log.Printf("ok")
}
// This example creates a key pair and displays the private and
// public keys. In stellar-terminology, the private key is typically
// called a "seed", and the publick key. an "address."
func ExampleMicroStellar_CreateKeyPair() {
ms := New("test")
// Generate a new random keypair.
pair, err := ms.CreateKeyPair()
if err != nil {
log.Fatalf("CreateKeyPair: %v", err)
}
// Display address and key
log.Printf("Private seed: %s, Public address: %s", pair.Seed, pair.Address)
fmt.Printf("ok")
// Output: ok
}
// This example creates a key pair and funds the account with lumens. FundAccount is
// used for the initial funding of the account -- it is what turns a public address
// into an account.
func ExampleMicroStellar_FundAccount() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Generate a new random keypair.
pair, err := ms.CreateKeyPair()
if err != nil {
log.Fatalf("CreateKeyPair: %v", err)
}
// Fund the account with 1 lumen from an existing account.
err = ms.FundAccount("SD3M3RG4G54JSFIG4RJYPPKTB4G77IPSXKZPTMN5CKAFWNRQP6V24ZDQ", pair.Address, "1")
if err != nil {
log.Fatalf("FundAccount: %v", ErrorString(err))
}
fmt.Printf("ok")
// Output: ok
}
// This example loads and displays the native and a non-native balance on an account.
func ExampleMicroStellar_LoadAccount_balance() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
// Load account from ledger.
account, err := ms.LoadAccount("GCCRUJJGPYWKQWM5NLAXUCSBCJKO37VVJ74LIZ5AQUKT6KPVCPNAGC4A")
if err != nil {
log.Fatalf("LoadAccount: %v", err)
}
// See balances
log.Printf("Native Balance: %v", account.GetNativeBalance())
log.Printf("USD Balance: %v", account.GetBalance(USD))
fmt.Printf("ok")
// Output: ok
}
// This example makes a native asset (lumens) payment from one account to another.
func ExampleMicroStellar_PayNative() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Pay 1 XLM to targetAddress
err := ms.PayNative("SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", "GDS2DXCCTW5VO5A2KCEBHAP3W4XOCJSI2QVHNN63TXVGBUIIW4DI3BCW", "1")
if err != nil {
log.Fatalf("PayNative: %v", ErrorString(err))
}
fmt.Printf("ok")
// Output: ok
}
// This example makes a payment of a credit asset from one account to another.
func ExampleMicroStellar_Pay() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
// Pay 1 USD to targetAddress
err := ms.Pay("SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", "GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD)
if err != nil {
log.Fatalf("Pay: %v", ErrorString(err))
}
fmt.Printf("ok")
// Output: ok
}
// Payments with memotext and memoid
func ExampleMicroStellar_Pay_memotext() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GALC5V4UUUICHENN3ZZLQY6UWAC67CMKVXYT4MT7YGQRD6RMXXCAMHP6", Credit4Type)
// Pay 1 USD to targetAddress and set the memotext field
err := ms.Pay("SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", "GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD, Opts().WithMemoText("boo"))
if err != nil {
log.Fatalf("Pay (memotext): %v", ErrorString(err))
}
// Pay 1 USD to targetAddress and set the memotext field
err = ms.Pay("SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", "GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD, Opts().WithMemoID(42))
if err != nil {
log.Fatalf("Pay (memoid): %v", ErrorString(err))
}
fmt.Printf("ok")
// Output: ok
}
// Payments with memohash and memoreturn
func ExampleMicroStellar_Pay_memohash() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GALC5V4UUUICHENN3ZZLQY6UWAC67CMKVXYT4MT7YGQRD6RMXXCAMHP6", Credit4Type)
// Pay 1 USD to targetAddress and set the memohash field
var hash [32]byte
copy(hash[:], "boo"[:])
err := ms.Pay("SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", "GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD,
Opts().WithMemoHash(hash))
if err != nil {
log.Fatalf("Pay (memohash): %v", ErrorString(err))
}
// Pay 1 USD to targetAddress and set the memoreturn field
err = ms.Pay("SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", "GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD, Opts().WithMemoReturn(hash))
if err != nil {
log.Fatalf("Pay (memoreturn): %v", ErrorString(err))
}
fmt.Printf("ok")
// Output: ok
}
// Payments with time bounds
func ExampleMicroStellar_Pay_timebounds() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GALC5V4UUUICHENN3ZZLQY6UWAC67CMKVXYT4MT7YGQRD6RMXXCAMHP6", Credit4Type)
// Start a new timebound transaction, valid between 1 and 24 hours from now
ms.Start("GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E",
Opts().WithTimeBounds(time.Now().Add(1*time.Hour), time.Now().Add(24*time.Hour)))
// Pay 1 USD to targetAddress, only valid between 1 and 24 hours from now.
ms.Pay("GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ",
"GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD)
// Get the transaction to submit later.
payload, err := ms.Payload()
if err != nil {
log.Fatalf("Could not generate payload: %v", err)
}
/*
// A few hours later, sign and submit transaction...
signedPayload, err := ms.SignTransaction(payload, "SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC")
if err != nil {
log.Fatalf("Could not sign transaction: %v", err)
}
_, err = ms.SubmitTransaction(signedPayload)
if err != nil {
log.Fatalf("Pay (timebounds): %v", ErrorString(err))
}
*/
_ = payload
fmt.Printf("ok")
// Output: ok
}
// Makes a multisignature payment
func ExampleMicroStellar_Pay_multisig() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
// Pay 1 USD to targetAddress and set the memotext field
err := ms.Pay("SDKORMIXFL2QW2UC3HWJ4GKL4PYFUMDOPEJMGWVQBW4GWJ5W2ZBOGRSZ", "GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD,
Opts().WithMemoText("multisig").
WithSigner("SAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ").
WithSigner("SBIUIQNMSXTGR4TGZETSQCGBTIF32G2L5D4AML4LFTMTHKM44UABFDMS"))
if err != nil {
log.Fatalf("Pay (memotext): %v", ErrorString(err))
}
// Pay 1 USD to targetAddress and set the memotext field
err = ms.Pay("SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", "GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", "1", USD, Opts().WithMemoID(73223))
if err != nil {
log.Fatalf("Pay (memoid): %v", ErrorString(err))
}
fmt.Printf("ok")
// Output: ok
}
// This example makes a path payment from XLM to INR via USD and EUR.
func ExampleMicroStellar_Pay_path() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
XLM := NativeAsset
// Custom USD, EUR, and INR assets issued by Bank of America
USD := NewAsset("USD", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
EUR := NewAsset("EUR", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
INR := NewAsset("INR", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
// Pay 5000 INR with XLM, going through USD and EUR. Spend no more than 40 lumens on this
// transaction.
err := ms.Pay(
"SAED4QHN3USETFHECASIM2LRI3H4QTVKZK44D2RC27IICZPZQEGXGXFC", // from
"GAGTJGMT55IDNTFTF2F553VQBWRBLGTWLU4YOOIFYBR2F6H6S4AEC45E", // to
"5000", INR, // they receive 5000 INR
Opts().
WithAsset(XLM, "40"). // we spend no more than 40 XLM
Through(USD, EUR)) // go through USD and EUR
if err != nil {
log.Fatalf("Pay: %v", ErrorString(err))
}
fmt.Printf("ok")
// Output: ok
}
// This example creates a trust line to a credit asset.
func ExampleMicroStellar_CreateTrustLine() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
// Create a trustline to the custom asset with no limit
err := ms.CreateTrustLine("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", USD, "")
if err != nil {
log.Fatalf("CreateTrustLine: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example removes a trust line to a credit asset.
func ExampleMicroStellar_RemoveTrustLine() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer
USD := NewAsset("USD", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
// Remove the trustline (if exists)
err := ms.RemoveTrustLine("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", USD)
if err != nil {
log.Fatalf("RemoveTrustLine: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example authorizes an account to create a trustline to an asset.
func ExampleMicroStellar_AllowTrust() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Custom USD asset issued by specified issuer.
USD := NewAsset("USD", "GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", Credit4Type)
// Issuer sets AUTH_REQUIRED flag on account.
err := ms.SetFlags("SDPLQEABOETMI7PPKJZYBHHW2BSA3424CI3V5ZRNN3NP2H7KYQOKY5ST", FlagAuthRequired)
if err != nil {
log.Fatalf("SetFlags: %v", ErrorString(err))
}
// Customer creates a trustline to the custom asset with no limit.
err = ms.CreateTrustLine("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", USD, "")
if err != nil {
log.Fatalf("CreateTrustLine: %v", err)
}
// Issuer then authorizes the trustline that was just created.
err = ms.AllowTrust("SDPLQEABOETMI7PPKJZYBHHW2BSA3424CI3V5ZRNN3NP2H7KYQOKY5ST",
"GAIUIQNMSXTTR4TGZETSQCGBTIF32G2L5P4AML4LFTMTHKM44UHIN6XQ", "USD", true)
if err != nil {
log.Fatalf("AllowTrust: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example sets the weight of the accounts primary signer (the master weight) to
// zero. This effectively kills the account.
func ExampleMicroStellar_SetMasterWeight() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Set master weight to zero.
err := ms.SetMasterWeight("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", 0)
if err != nil {
log.Fatalf("SetMasterWeight: %v", err)
}
// Load the account and check its master weight
account, err := ms.LoadAccount("GCCRUJJGPYWKQWM5NLAXUCSBCJKO37VVJ74LIZ5AQUKT6KPVCPNAGC4A")
if err != nil {
log.Fatalf("LoadAccount: %v", err)
}
log.Printf("Master weight: %v", account.GetMasterWeight())
fmt.Printf("ok")
// Output: ok
}
// This example adds a signer to an account.
func ExampleMicroStellar_AddSigner() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Add signer to account
err := ms.AddSigner("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", "GCCRUJJGPYWKQWM5NLAXUCSBCJKO37VVJ74LIZ5AQUKT6KPVCPNAGC4A", 10)
if err != nil {
log.Fatalf("AddSigner: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example removes a signer from an account.
func ExampleMicroStellar_RemoveSigner() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Remove signer from account
err := ms.RemoveSigner("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", "GCCRUJJGPYWKQWM5NLAXUCSBCJKO37VVJ74LIZ5AQUKT6KPVCPNAGC4A")
if err != nil {
log.Fatalf("RemoveSigner: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example sets the signing thresholds for an account
func ExampleMicroStellar_SetThresholds() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Set the low, medium, and high thresholds for an account
err := ms.SetThresholds("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", 2, 2, 2)
if err != nil {
log.Fatalf("SetThresholds: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example sets the home domain for an account
func ExampleMicroStellar_SetHomeDomain() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Set the home domain to qubit.sh
err := ms.SetHomeDomain("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", "qubit.sh")
if err != nil {
log.Fatalf("SetHomeDomain: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example sets flags on an issuer's account
func ExampleMicroStellar_SetFlags() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Set the AUTH_REQUIRED and AUTH_REVOCABLE flags on the account.
err := ms.SetFlags("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", FlagAuthRequired|FlagAuthRevocable)
if err != nil {
log.Fatalf("SetFlags: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example sets some data values on an account
func ExampleMicroStellar_SetData() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
// Set some string data
err := ms.SetData("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK",
"foo", []byte("this is a string"))
if err != nil {
log.Fatalf("SetData: %v", err)
}
// Set some byte data
err = ms.SetData("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK",
"bytes", []byte{0xFF, 0xFF})
if err != nil {
log.Fatalf("SetData: %v", err)
}
// Read the data values that were just set
account, err := ms.LoadAccount("GAKMTB3D6AOE5HZ3QK726TZG6A22NGN7B46B2UALVYCLLHLOBMUBXZBJ")
if err != nil {
log.Fatalf("LoadAccount: %v", err)
}
if v, ok := account.GetData("foo"); ok {
fmt.Printf("foo = %s", string(v))
}
if v, ok := account.GetData("bytes"); ok {
fmt.Printf("bytes = %v", v)
}
// Clear data
err = ms.ClearData("SCSMBQYTXKZYY7CLVT6NPPYWVDQYDOQ6BB3QND4OIXC7762JYJYZ3RMK", "bytes")
if err != nil {
log.Fatalf("ClearData: %v", err)
}
fmt.Printf("ok")
// Output: ok
}
// This example demonstrates multi-op transactions.
func ExampleMicroStellar_Start() {
// Create a new MicroStellar client connected to a fake network. To
// use a real network replace "fake" below with "test" or "public".
ms := New("fake")
feeSource := "GAKMTB3D6AOE5HZ3QK726TZG6A22NGN7B46B2UALVYCLLHLOBMUBXZBJ"
signer := "SDPLQEABOETMI7PPKJZYBHHW2BSA3424CI3V5ZRNN3NP2H7KYQOKY5ST"
// Start a new multi-op transaction and bill the fee to feeSource. Also provide the
// seed of the signer with authority to sign all operations.
ms.Start(feeSource, Opts().WithMemoText("multi-op").WithSigner(signer))
// Set the home domain to qubit.sh
err := ms.SetHomeDomain("GAD3LPHSTZHNZOJOPRS7OZ2P74VXFCP5J4QNYIGGHZ246XINHGKPJIQR", "qubit.sh")
if err != nil {
log.Fatalf("SetHomeDomain: %v", err)
}
// Set the AUTH_REQUIRED and AUTH_REVOCABLE flags on the account.
err = ms.SetFlags("GAD3LPHSTZHNZOJOPRS7OZ2P74VXFCP5J4QNYIGGHZ246XINHGKPJIQR", FlagAuthRequired|FlagAuthRevocable)
if err != nil {
log.Fatalf("SetFlags: %v", err)
}
// Sign and submit the transaction to the network
err = ms.Submit()
if err != nil {
log.Fatalf("Submit: %v", err)
}
fmt.Printf("ok")
// Output: ok
}