forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_abi_decode_test.go
57 lines (48 loc) · 962 Bytes
/
example_abi_decode_test.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
package eos_test
import (
"encoding/hex"
"fmt"
"strings"
eos "github.com/eoscanada/eos-go"
)
func ExampleABI_DecodeTableRowTyped() {
abi, err := eos.NewABI(strings.NewReader(abiJSON()))
if err != nil {
panic(fmt.Errorf("get ABI: %s", err))
}
tableDef := abi.TableForName(eos.TableName("votes"))
if tableDef == nil {
panic(fmt.Errorf("table be should be present"))
}
bytes, err := abi.DecodeTableRowTyped(tableDef.Type, data())
if err != nil {
panic(fmt.Errorf("decode row: %s", err))
}
fmt.Println(string(bytes))
}
func data() []byte {
bytes, err := hex.DecodeString(`424e544441505000`)
if err != nil {
panic(fmt.Errorf("decode data: %s", err))
}
return bytes
}
func abiJSON() string {
return `{
"structs": [
{
"name": "vote_t",
"fields": [
{ "name": "symbl", "type": "symbol_code" }
]
}
],
"actions": [],
"tables": [
{
"name": "votes",
"type": "vote_t"
}
]
}`
}