Skip to content

Commit

Permalink
support contract call bytes array
Browse files Browse the repository at this point in the history
  • Loading branch information
yfl92 committed Sep 26, 2024
1 parent 6b9a6ce commit fcb7545
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions services/construction/contract_call_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package construction

import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"log"
Expand Down Expand Up @@ -176,6 +177,24 @@ func encodeMethodArgsStrings(methodID []byte, methodSig string, methodArgs []str
copy(value[:], bytes)
argData = value
}
// Note: we must handle "bytes[]" before "bytes"
case v == "bytes[]":
{
var bytesArgs []string
if err := json.Unmarshal([]byte(methodArgs[i]), &bytesArgs); err != nil {
log.Fatal(err)
}

value := make([][]byte, len(bytesArgs))
for j, bytesArg := range bytesArgs {
bytes, err := hexutil.Decode(bytesArg)
if err != nil {
log.Fatal(err)
}
value[j] = bytes
}
argData = value
}
case strings.HasPrefix(v, "bytes"):
{
// No fixed size set as it would make it an "array" instead
Expand Down

0 comments on commit fcb7545

Please sign in to comment.