-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.go
64 lines (49 loc) · 1.27 KB
/
adapter.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
package tbsdk
import (
"encoding/hex"
"math/big"
"strings"
"github.com/ethereum/go-ethereum/common"
)
type Adapter func(...AdapterArgs) string
type AdapterArgs interface{}
var BIG_INT_ADAPTER Adapter = func(aa ...AdapterArgs) string {
nonce, ok := aa[0].(*big.Int)
if !ok || nonce == nil {
return ""
}
return "0x" + nonce.Text(16)
}
var ADDRESS_ADAPTER Adapter = func(aa ...AdapterArgs) string {
address, ok := aa[0].(*common.Address)
if !ok || address == nil {
return common.Address{}.Hex()
}
return address.Hex()
}
var ADDRESS_PACKED_DATA_ADAPTER Adapter = func(aa ...AdapterArgs) string {
factoryAddress, ok := aa[0].(*common.Address)
if !ok || factoryAddress == nil {
return "0x"
}
factoryHex := factoryAddress.Hex()
if len(aa) != 2 {
return factoryHex
}
args, ok := aa[1].([]interface{})
if !ok || len(args) != 1 {
return factoryHex
}
factoryAddressData, ok := args[0].([]byte)
if !ok || len(factoryAddressData) == 0 {
return factoryHex
}
return strings.Join([]string{factoryHex, hex.EncodeToString(factoryAddressData)}, "")
}
var PACKED_DATA_ADAPTER Adapter = func(aa ...AdapterArgs) string {
callData, ok := aa[0].([]byte)
if !ok || len(callData) == 0 {
return "0x"
}
return strings.Join([]string{"0x", hex.EncodeToString(callData)}, "")
}