-
Notifications
You must be signed in to change notification settings - Fork 5
/
standard.go
69 lines (54 loc) · 1.26 KB
/
standard.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
65
66
67
68
69
package standard
import (
"github.com/benleb/gloomberg/internal/gbl"
"github.com/benleb/gloomberg/internal/nemo/topic"
"github.com/ethereum/go-ethereum/core/types"
)
type (
Standard int64
Standards []Standard
)
const (
UNKNOWN Standard = iota
ERC20
ERC165
ERC721
ERC1155
)
func (s Standard) String() string {
return map[Standard]string{
UNKNOWN: "UNKNOWN", ERC20: "ERC20", ERC165: "ERC165", ERC721: "ERC721", ERC1155: "ERC1155",
}[s]
}
func (st Standards) Contains(standard Standard) bool {
for _, s := range st {
if s == standard {
return true
}
}
return false
}
func (s Standard) IsERC721orERC1155() bool {
return s == ERC721 || s == ERC1155
}
func (s Standard) IsERC20() bool {
return s == ERC20
}
func GetStandard(txLog *types.Log) Standard {
logStandard := UNKNOWN
topic0 := topic.Topic(txLog.Topics[0].String())
switch {
// erc20
case topic0 == topic.Transfer && len(txLog.Topics) <= 3:
logStandard = ERC20
// erc721
case topic0 == topic.Transfer && len(txLog.Topics) >= 4:
logStandard = ERC721
// erc1155
case topic0 == topic.TransferSingle && len(txLog.Topics) >= 4:
logStandard = ERC1155
default:
gbl.Log.Debugf("unknown log standard | len(log.Topics): %d | topic0: %s", len(txLog.Topics), topic0)
}
return logStandard
}