github.com/0xsequence/ethkit@v1.25.0/ethcoder/ethcoder.go (about) 1 package ethcoder 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 func BytesToBytes32(slice []byte) [32]byte { 9 var bytes32 [32]byte 10 copy(bytes32[:], slice) 11 return bytes32 12 } 13 14 func AddressPadding(input string) string { 15 if strings.HasPrefix(input, "0x") { 16 input = input[2:] 17 } 18 if len(input) < 64 { 19 input = strings.Repeat("0", 64-len(input)) + input 20 } 21 return input[0:64] 22 } 23 24 func FunctionSignature(functionExpr string) string { 25 return HexEncode(Keccak256([]byte(functionExpr))[0:4]) 26 } 27 28 func StringifyValues(values []interface{}) ([]string, error) { 29 strs := []string{} 30 31 for _, value := range values { 32 stringer, ok := value.(fmt.Stringer) 33 if ok { 34 strs = append(strs, stringer.String()) 35 continue 36 } 37 38 switch v := value.(type) { 39 case nil: 40 strs = append(strs, "") 41 break 42 43 case string: 44 strs = append(strs, v) 45 break 46 47 default: 48 strs = append(strs, fmt.Sprintf("%v", value)) 49 break 50 } 51 } 52 53 return strs, nil 54 }