forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setcode.go
54 lines (48 loc) · 1.12 KB
/
setcode.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
package system
import (
"encoding/json"
"fmt"
"io/ioutil"
eos "github.com/eoscanada/eos-go"
)
func NewSetCodeTx(account eos.AccountName, wasmPath, abiPath string) (out *eos.Transaction, err error) {
codeContent, err := ioutil.ReadFile(wasmPath)
if err != nil {
return nil, err
}
abiContent, err := ioutil.ReadFile(abiPath)
if err != nil {
return nil, err
}
var abiDef eos.ABI
if err := json.Unmarshal(abiContent, &abiDef); err != nil {
return nil, fmt.Errorf("unmarshal ABI file:, %s", err)
}
actions := []*eos.Action{
{
Account: AN("eosio"),
Name: ActN("setcode"),
Authorization: []eos.PermissionLevel{
{account, eos.PermissionName("active")},
},
ActionData: eos.NewActionData(SetCode{
Account: account,
VMType: 0,
VMVersion: 0,
Code: eos.HexBytes(codeContent),
}),
},
{
Account: AN("eosio"),
Name: ActN("setabi"),
Authorization: []eos.PermissionLevel{
{account, eos.PermissionName("active")},
},
ActionData: eos.NewActionData(SetABI{
Account: account,
ABI: abiDef,
}),
},
}
return &eos.Transaction{Actions: actions}, nil
}