Commit 6d049fea authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: bugfixes

parent 1714c430
...@@ -46,14 +46,7 @@ func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []an ...@@ -46,14 +46,7 @@ func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []an
return fmt.Errorf("%s not found in abi, options are %s", sig, methods) return fmt.Errorf("%s not found in abi, options are %s", sig, methods)
} }
size := 0 if len(args) != len(method.Inputs) {
for _, input := range method.Inputs {
if err := countArgs(&size, input); err != nil {
return err
}
}
if len(args) != len(method.Inputs) && len(args) != size {
return fmt.Errorf("requires %d inputs but got %d for %s", len(method.Inputs), len(args), method.RawName) return fmt.Errorf("requires %d inputs but got %d for %s", len(method.Inputs), len(args), method.RawName)
} }
...@@ -79,16 +72,19 @@ func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []an ...@@ -79,16 +72,19 @@ func (b *Batch) AddCall(to common.Address, value *big.Int, sig string, args []an
inputValues[input.Name] = str inputValues[input.Name] = str
} }
data, err := method.Inputs.PackValues(args) encoded, err := method.Inputs.PackValues(args)
if err != nil { if err != nil {
return err return err
} }
data := make([]byte, len(method.ID)+len(encoded))
copy(data, method.ID)
copy(data[len(method.ID):], encoded)
batchTransaction := BatchTransaction{ batchTransaction := BatchTransaction{
To: to, To: to,
Value: value, Value: value,
Data: data,
Method: contractMethod, Method: contractMethod,
Data: data,
InputValues: inputValues, InputValues: inputValues,
} }
...@@ -180,8 +176,8 @@ func (b *BatchTransaction) MarshalJSON() ([]byte, error) { ...@@ -180,8 +176,8 @@ func (b *BatchTransaction) MarshalJSON() ([]byte, error) {
InputValues: b.InputValues, InputValues: b.InputValues,
} }
if len(b.Data) != 0 { if len(b.Data) != 0 {
hex := hexutil.Encode(b.Data) data := hexutil.Bytes(b.Data)
batch.Data = &hex batch.Data = &data
} }
return json.Marshal(batch) return json.Marshal(batch)
} }
...@@ -190,7 +186,7 @@ func (b *BatchTransaction) MarshalJSON() ([]byte, error) { ...@@ -190,7 +186,7 @@ func (b *BatchTransaction) MarshalJSON() ([]byte, error) {
type batchTransactionMarshaling struct { type batchTransactionMarshaling struct {
To string `json:"to"` To string `json:"to"`
Value uint64 `json:"value,string"` Value uint64 `json:"value,string"`
Data *string `json:"data"` Data *hexutil.Bytes `json:"data"`
Method ContractMethod `json:"contractMethod"` Method ContractMethod `json:"contractMethod"`
InputValues map[string]string `json:"contractInputsValues"` InputValues map[string]string `json:"contractInputsValues"`
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment