예제 #1
0
func MakeAbi(abiData []byte) (abi.ABI, error) {
	if len(abiData) == 0 {
		return abi.NullABI, nil
	}

	abiSpec := new(abi.ABI)
	if err := abiSpec.UnmarshalJSON(abiData); err != nil {
		log.Println("failed to unmarshal", err)
		return abi.NullABI, err
	}

	return *abiSpec, nil
}
예제 #2
0
func PackArgsABI(abiSpec abi.ABI, data ...string) (string, error) {

	funcName := data[0]
	args := data[1:]

	a := []interface{}{}
	for _, aa := range args {
		bb, _ := hex.DecodeString(common.StripHex(common.CoerceHexAndPad(aa, true)))
		a = append(a, bb)
	}

	packedBytes, err := abiSpec.Pack(funcName, args)
	if err != nil {
		return "", err
	}

	packed := hex.EncodeToString(packedBytes)

	return packed, nil
}