github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/util/abi_convert.go (about) 1 package util 2 3 import ( 4 "github.com/pkg/errors" 5 ) 6 7 // vars 8 var ( 9 ErrWrongType = errors.New("wrong data type held by interface{}") 10 ) 11 12 // To32Bytes asserts/converts interface{} to [32]byte 13 func To32Bytes(v interface{}) ([32]byte, error) { 14 if b32, ok := v.([32]byte); ok { 15 return b32, nil 16 } 17 return [32]byte{}, ErrWrongType 18 } 19 20 // ToByteSlice asserts/converts interface{} to []byte 21 func ToByteSlice(v interface{}) ([]byte, error) { 22 if b, ok := v.([]byte); ok { 23 return b, nil 24 } 25 return nil, ErrWrongType 26 }