8 chainjson "github.com/vapor/encoding/json"
10 "github.com/vapor/equity/compiler"
13 // InstantiateContract instantiate contract parameters
14 func InstantiateContract(contract *compiler.Contract, args []compiler.ContractArg) ([]byte, error) {
15 program, err := compiler.Instantiate(contract.Body, contract.Params, contract.Recursive, args)
23 func ConvertArguments(contract *compiler.Contract, args []string) ([]compiler.ContractArg, error) {
24 var contractArgs []compiler.ContractArg
25 for i, p := range contract.Params {
26 var argument compiler.ContractArg
30 if args[i] == "true" || args[i] == "1" {
32 } else if args[i] == "false" || args[i] == "0" {
35 return nil, errors.New("mismatch Boolean argument")
37 argument.B = &boolValue
40 amount, err := strconv.ParseUint(args[i], 10, 64)
45 if amount > uint64(1<<uint(63)) {
46 return nil, errors.New("the Amount argument exceeds max int64")
48 amountValue := int64(amount)
49 argument.I = &amountValue
52 integerValue, err := strconv.ParseInt(args[i], 10, 64)
56 argument.I = &integerValue
58 case "Asset", "Hash", "PublicKey":
59 if len(args[i]) != 64 {
60 return nil, errors.New("mismatch length for Asset/Hash/PublicKey argument")
63 commonValue, err := hex.DecodeString(args[i])
67 argument.S = (*chainjson.HexBytes)(&commonValue)
70 program, err := hex.DecodeString(args[i])
74 argument.S = (*chainjson.HexBytes)(&program)
77 strValue := []byte(args[i])
78 argument.S = (*chainjson.HexBytes)(&strValue)
81 contractArgs = append(contractArgs, argument)
84 return contractArgs, nil