Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 30b2b69

Browse files
committed
[example] update golang examples, and README
1 parent 186d537 commit 30b2b69

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

README.md

+19-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ It has all cryptographic verification algorithms, including validator-signature-
1313

1414
## Features
1515

16-
Compatible with testnet 2020/2/29 (commit hash [63e2d574](https://github.com/libra/libra/commit/63e2d5747d98656296da2f07ae84c8e1eed3c382)).
16+
Compatible with testnet 2020/4/8 (commit hash [718ace82](https://github.com/libra/libra/commit/718ace82250e7bd64e08d7d61951bfaa8cee9ea4)).
1717

1818
- Data models with all necessary cryptographic verification algorithms
1919
- Ledger state: signature-based consensus verification
@@ -60,19 +60,18 @@ import (
6060
)
6161

6262
const (
63-
defaultServer = "ac.testnet.libra.org:8000"
64-
trustedPeersFile = "../consensus_peers.config.toml"
63+
defaultServer = "ac.testnet.libra.org:8000"
64+
waypoint = "0:4d4d0feaa9378069f8fcee71980e142273837e108702d8d7f93a8419e2736f3f"
6565
)
6666

6767
func main() {
68-
c, err := client.New(defaultServer, trustedPeersFile)
68+
c, err := client.New(defaultServer, waypoint)
6969
if err != nil {
7070
log.Fatal(err)
7171
}
7272
defer c.Close()
7373

74-
addrStr := "18b553473df736e5e363e7214bd624735ca66ac22a7048e3295c9b9b9adfc26a"
75-
// Parse hex string into binary address
74+
addrStr := "42f5745128c05452a0c68272de8042b1"
7675
addr := client.MustToAddress(addrStr)
7776

7877
// provenState is cryptographically proven state of account
@@ -86,45 +85,47 @@ func main() {
8685
return
8786
}
8887

89-
provenResource, err := c.GetLibraCoinResourceFromAccountBlob(provenState.GetAccountBlob())
88+
ar, br, err := provenState.GetAccountBlob().GetLibraResources()
9089
if err != nil {
9190
log.Fatal(err)
9291
}
9392

94-
log.Printf("Balance (microLibra): %d", provenResource.GetBalance())
95-
log.Printf("Sequence Number: %d", provenResource.GetSequenceNumber())
93+
log.Printf("Balance: %d", br.Coin)
94+
log.Printf("Sequence Number: %d", ar.SequenceNumber)
95+
log.Printf("Authentication key: %v", hex.EncodeToString(ar.AuthenticationKey))
9696
}
9797
```
9898

9999
### Make peer-to-peer transaction
100100

101101
```golang
102-
// Get current account sequence of sender
103-
seq, err := c.GetAccountSequenceNumber(senderAddr)
102+
log.Printf("Get current account sequence of sender...")
103+
seq, err := c.QueryAccountSequenceNumber(context.TODO(), senderAddr)
104104
if err != nil {
105105
log.Fatal(err)
106106
}
107+
log.Printf("... is %d", seq)
107108

108-
// Build a raw transaction
109-
rawTxn, err := types.NewRawP2PTransaction(
110-
senderAddr, recvAddr, seq,
109+
rawTxn, err := client.NewRawP2PTransaction(
110+
senderAddr, recvAddr, recvAuthKeyPrefix, seq,
111111
amountMicro, maxGasAmount, gasUnitPrice, expiration,
112112
)
113113
if err != nil {
114114
log.Fatal(err)
115115
}
116116

117-
// Sign and submit transaction
118-
err = c.SubmitRawTransaction(context.TODO(), rawTxn, priKey)
117+
log.Printf("Submit transaction...")
118+
expectedSeq, err := c.SubmitRawTransaction(context.TODO(), rawTxn, priKey)
119119
if err != nil {
120120
log.Fatal(err)
121121
}
122122

123-
// Wait until transaction is included in ledger, or timeout
124-
err = c.PollSequenceUntil(context.TODO(), senderAddr, seq+1, expiration)
123+
log.Printf("Waiting until transaction is included in ledger...")
124+
err = c.PollSequenceUntil(context.TODO(), senderAddr, expectedSeq, expiration)
125125
if err != nil {
126126
log.Fatal(err)
127127
}
128+
log.Printf("done.")
128129
```
129130

130131
### Other examples

example/p2p_transaction/p2p.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
const (
1414
defaultServer = "ac.testnet.libra.org:8000"
15-
waypoint = "0:a69511cc7e6d609efcf03e64098056bc3c96d383e0adcf752464a111b081b808"
15+
waypoint = "0:4d4d0feaa9378069f8fcee71980e142273837e108702d8d7f93a8419e2736f3f"
1616
)
1717

1818
func main() {

example/query_account/query_account.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
const (
1212
defaultServer = "ac.testnet.libra.org:8000"
13-
waypoint = "0:a69511cc7e6d609efcf03e64098056bc3c96d383e0adcf752464a111b081b808"
13+
waypoint = "0:4d4d0feaa9378069f8fcee71980e142273837e108702d8d7f93a8419e2736f3f"
1414
)
1515

1616
func main() {

example/query_txn_by_seq/query_txn_by_seq.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
const (
1212
defaultServer = "ac.testnet.libra.org:8000"
13-
waypoint = "0:a69511cc7e6d609efcf03e64098056bc3c96d383e0adcf752464a111b081b808"
13+
waypoint = "0:4d4d0feaa9378069f8fcee71980e142273837e108702d8d7f93a8419e2736f3f"
1414
)
1515

1616
func main() {

example/query_txn_range/query_txn_range.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
const (
1212
defaultServer = "ac.testnet.libra.org:8000"
13-
waypoint = "0:a69511cc7e6d609efcf03e64098056bc3c96d383e0adcf752464a111b081b808"
13+
waypoint = "0:4d4d0feaa9378069f8fcee71980e142273837e108702d8d7f93a8419e2736f3f"
1414
)
1515

1616
func main() {

0 commit comments

Comments
 (0)