-
Notifications
You must be signed in to change notification settings - Fork 43
/
transaction.go
75 lines (63 loc) · 1.72 KB
/
transaction.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
package main
import (
"fmt"
"math/big"
"os"
"strconv"
"github.com/goat-systems/go-tezos/v4/forge"
"github.com/goat-systems/go-tezos/v4/keys"
"github.com/goat-systems/go-tezos/v4/rpc"
)
func main() {
key, err := keys.FromEncryptedSecret("edesk...", "password")
if err != nil {
fmt.Printf("failed to import keys: %s\n", err.Error())
os.Exit(1)
}
client, err := rpc.New("http://tezos_rpc_addr")
if err != nil {
fmt.Printf("failed to initialize rpc client: %s\n", err.Error())
os.Exit(1)
}
resp, counter, err := client.ContractCounter(rpc.ContractCounterInput{
BlockID: &rpc.BlockIDHead{},
ContractID: key.PubKey.GetAddress(),
})
if err != nil {
fmt.Printf("failed to get (%s) counter: %s\n", resp.Status(), err.Error())
os.Exit(1)
}
counter++
big.NewInt(0).SetString("10000000000000000000000000000", 10)
transaction := rpc.Transaction{
Source: key.PubKey.GetPublicKey(),
Fee: "2941",
GasLimit: "26283",
Counter: strconv.Itoa(counter),
Amount: "0",
Destination: "<some_dest>",
}
resp, head, err := client.Block(&rpc.BlockIDHead{})
if err != nil {
fmt.Printf("failed to get (%s) head block: %s\n", resp.Status(), err.Error())
os.Exit(1)
}
op, err := forge.Encode(head.Hash, transaction.ToContent())
if err != nil {
fmt.Printf("failed to forge transaction: %s\n", err.Error())
os.Exit(1)
}
signature, err := key.SignHex(op)
if err != nil {
fmt.Printf("failed to sign operation: %s\n", err.Error())
os.Exit(1)
}
resp, ophash, err := client.InjectionOperation(rpc.InjectionOperationInput{
Operation: signature.AppendToHex(op),
})
if err != nil {
fmt.Printf("failed to inject (%s): %s\n", resp.Status(), err.Error())
os.Exit(1)
}
fmt.Println(ophash)
}