-
Notifications
You must be signed in to change notification settings - Fork 44
/
encode.go
50 lines (38 loc) · 1.04 KB
/
encode.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
package solar
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/qtumproject/solar/contract"
)
func init() {
cmd := app.Command("encode", "ABI encoding for a method call")
contractName := cmd.Arg("contractName", "Name of contract").Required().String()
methodName := cmd.Arg("methodName", "Method name of contract").Required().String()
jsonParams := cmd.Arg("jsonParams", "Parameters as a json array").Default("[]").String()
appTasks["encode"] = func() (err error) {
repo := solar.ContractsRepository()
c, ok := repo.Get(*contractName)
if !ok {
return errors.Errorf("Cannot find contract: %s", *contractName)
}
abi, err := c.EncodingABI()
if err != nil {
return
}
var params []interface{}
if jsonParams != nil {
jsonParams := solar.ExpandJSONParams(*jsonParams)
err := json.Unmarshal([]byte(jsonParams), ¶ms)
if err != nil {
return err
}
}
data, err := abi.Pack(*methodName, params...)
if err != nil {
return err
}
fmt.Println(contract.Bytes(data).String())
return nil
}
}