github.com/lmittmann/w3@v0.20.0/internal/fourbyte/fourbyte.go (about) 1 //go:generate go run gen.go 2 3 package fourbyte 4 5 import ( 6 "github.com/ethereum/go-ethereum/common" 7 "github.com/lmittmann/w3" 8 ) 9 10 var ( 11 precompile1 = w3.MustNewFunc("ecRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s)", "address") 12 precompile2 = w3.MustNewFunc("keccak(bytes)", "bytes32") 13 precompile3 = w3.MustNewFunc("ripemd160(bytes)", "bytes32") 14 precompile4 = w3.MustNewFunc("identity(bytes)", "bytes") 15 16 addr1 = common.BytesToAddress([]byte{0x01}) 17 addr2 = common.BytesToAddress([]byte{0x02}) 18 addr3 = common.BytesToAddress([]byte{0x03}) 19 addr4 = common.BytesToAddress([]byte{0x04}) 20 ) 21 22 func Function(sig [4]byte, addr common.Address) (fn *w3.Func, isPrecompile bool) { 23 switch addr { 24 case addr1: 25 return precompile1, true 26 case addr2: 27 return precompile2, true 28 case addr3: 29 return precompile3, true 30 case addr4: 31 return precompile4, true 32 } 33 return functions[sig], false 34 } 35 36 func Event(topic0 [32]byte, addr common.Address) *w3.Event { 37 return events[topic0] 38 }