forked from lialvin/uos-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_abi_decode_test.go
57 lines (48 loc) · 956 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 uos_test
import (
"encoding/hex"
"fmt"
"strings"
uos "github.com/tkblack/uos-go"
)
func ExampleABI_DecodeTableRowTyped() {
abi, err := uos.NewABI(strings.NewReader(abiJSON()))
if err != nil {
panic(fmt.Errorf("get ABI: %s", err))
}
tableDef := abi.TableForName(uos.TableName("activebets"))
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(`1358285f09db6dc0`)
if err != nil {
panic(fmt.Errorf("decode data: %s", err))
}
return bytes
}
func abiJSON() string {
return `{
"structs": [
{
"name": "bet",
"fields": [
{ "name": "id", "type": "uint64" }
]
}
],
"actions": [],
"tables": [
{
"name": "activebets",
"type": "bet"
}
]
}`
}