forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (66 loc) · 2.72 KB
/
main.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
package main
import (
"bytes"
"flag"
"fmt"
"log"
"github.com/eoscanada/eos-go"
"github.com/eoscanada/eos-go/system"
)
var flagAccount = flag.String("account", "", "Account to set code")
var flagWasm = flag.String("wasm", "", "WAST file loc")
var flagABI = flag.String("abi", "", "ABI file loc")
var flagPrivKey = flag.String("key", "", "Private key to load to sign transaction")
func main() {
flag.Parse()
// api := eos.New(&url.URL{Scheme: "http", Host: "cbillett.eoscanada.com"}, bytes.Repeat([]byte{0}, 32))
api := eos.New("http://localhost:9999", bytes.Repeat([]byte{0}, 32))
// api := eos.New(&url.URL{Scheme: "http", Host: "localhost:8889"}, bytes.Repeat([]byte{0}, 32))
// api.Debug = true
keyBag := eos.NewKeyBag()
for _, key := range []string{
*flagPrivKey,
"5KE5hGNCAs1YvV74Ho14y1rV1DrnqZpTwLugS8QvYbKbrGAvVA1", // EOS71W8hvF43Eq6GQBRhuc5mvWKtknxzmb9NzNwPGpcEm2xAZaG8c
"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", //... 5CV
"5Jrwky4GxChTSqG29Mj9B1HGqJXx8T8WxkPJULmDaBDsguhiF8m",
} {
if err := keyBag.Add(key); err != nil {
log.Fatalln("Couldn't load private key:", err)
}
}
api.SetSigner(keyBag)
// WTTFFF, it DOESN'T WORK when we use `localhost:6667`, but it DOES work
// when we use `localhost:5555` which is our GO wallet !!!
// Then, it DOESN't work when we sign our transactions directly through
// the KeyBag Signer
// The only difference is that we GO THROUGH JSON SERIALIZATION and BACK ?!?
// walletAPI := eos.New(&url.URL{Scheme: "http", Host: "localhost:6667"}, bytes.Repeat([]byte{0}, 32))
// // walletAPI := eos.New(&url.URL{Scheme: "http", Host: "localhost:5555"}, bytes.Repeat([]byte{0}, 32))
// // walletAPI.Debug = true
// if err := walletAPI.WalletImportKey("default", *flagPrivKey); err != nil {
// fmt.Println("Error adding key to wallet:", err)
// }
// api.SetSigner(eos.NewWalletSigner(walletAPI, "default"))
// Corresponding to the wallet, so we can sign on the live node.
// THIS IS REALLY WEIRD!! IT WORKS WITH KEYBAG BUT NOT WITH THE OFFICIAL WALLET!
// I inspected all bytes.. they sign the same hash.. it's all the same thing..
// isn't it PACKED the same way on the `push_transaction` side ?!?!
setCodeTx, err := system.NewSetCodeTx(eos.AccountName(*flagAccount), *flagWasm, *flagABI)
if err != nil {
log.Fatalln("Couldn't read setcode data:", err)
}
setCodeTx.Actions = []*eos.Action{setCodeTx.Actions[0]}
resp, err := api.SignPushTransaction(setCodeTx, nil)
if err != nil {
fmt.Println("ERROR calling SetCode:", err)
} else {
fmt.Println("RESP:", resp)
}
// api.SetSigner(keyBag)
// resp, err = api.SignPushTransaction(setCodeTx, nil)
// if err != nil {
// fmt.Println("ERROR calling SetCode:", err)
// } else {
// fmt.Println("RESP:", resp)
// }
}