This repository has been archived by the owner on Dec 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathp2p.go
65 lines (55 loc) · 1.76 KB
/
p2p.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
package main
import (
"context"
"encoding/hex"
"log"
"time"
"github.com/the729/go-libra/client"
"golang.org/x/crypto/ed25519"
)
const (
defaultServer = "ac.testnet.libra.org:8000"
waypoint = "0:4d4d0feaa9378069f8fcee71980e142273837e108702d8d7f93a8419e2736f3f"
)
func main() {
c, err := client.New(defaultServer, waypoint)
if err != nil {
log.Fatal(err)
}
defer c.Close()
// We need private key fo the sender to sign the transaction
priKeyBytes, _ := hex.DecodeString("996911072ee011ffa44a1325e0da593ff3b9374e255115f223cbdffb6bfa0bcfba60d1f8edd6923f59cf9125d3ac80e389afa4e2b8d0e4f1183a30a0270fde71")
priKey := ed25519.PrivateKey(priKeyBytes)
// Transaction parameters
senderAddr := client.MustToAddress("42f5745128c05452a0c68272de8042b1")
recvAddr := client.MustToAddress("5817cd6e6e84c110c43efca22df54172")
recvAuthKeyPrefix, _ := hex.DecodeString("26c7bfaa8e0f32206f35bf6d44b43c9c")
amountMicro := uint64(2 * 1000000)
maxGasAmount := uint64(500000)
gasUnitPrice := uint64(0)
expiration := time.Now().Add(1 * time.Minute)
log.Printf("Get current account sequence of sender...")
seq, err := c.QueryAccountSequenceNumber(context.TODO(), senderAddr)
if err != nil {
log.Fatal(err)
}
log.Printf("... is %d", seq)
rawTxn, err := client.NewRawP2PTransaction(
senderAddr, recvAddr, recvAuthKeyPrefix, seq,
amountMicro, maxGasAmount, gasUnitPrice, expiration,
)
if err != nil {
log.Fatal(err)
}
log.Printf("Submit transaction...")
expectedSeq, err := c.SubmitRawTransaction(context.TODO(), rawTxn, priKey)
if err != nil {
log.Fatal(err)
}
log.Printf("Waiting until transaction is included in ledger...")
err = c.PollSequenceUntil(context.TODO(), senderAddr, expectedSeq, expiration)
if err != nil {
log.Fatal(err)
}
log.Printf("done.")
}