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

op-chain-ops: `Withdrawal` type use `hexutil.Bytes`

Use `hexutil.Bytes` in the `Withdrawal` type so that
when writing and reading from JSON, it correctly serializes
the data as a 0x prefixed hex string. Without this, it will
some base64 looking serialization. Be sure to cast to a byte
slice before doing any abi packing, otherwise it will cause
errors.
parent e65a7bb0
...@@ -76,7 +76,7 @@ func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *com ...@@ -76,7 +76,7 @@ func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *com
withdrawal.Target, withdrawal.Target,
value, value,
new(big.Int), new(big.Int),
withdrawal.Data, []byte(withdrawal.Data),
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot abi encode relayMessage: %w", err) return nil, fmt.Errorf("cannot abi encode relayMessage: %w", err)
......
...@@ -2,11 +2,13 @@ package crossdomain ...@@ -2,11 +2,13 @@ package crossdomain
import ( import (
"errors" "errors"
"fmt"
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
...@@ -28,7 +30,7 @@ type Withdrawal struct { ...@@ -28,7 +30,7 @@ type Withdrawal struct {
Target *common.Address `json:"target"` Target *common.Address `json:"target"`
Value *big.Int `json:"value"` Value *big.Int `json:"value"`
GasLimit *big.Int `json:"gasLimit"` GasLimit *big.Int `json:"gasLimit"`
Data []byte `json:"data"` Data hexutil.Bytes `json:"data"`
} }
// NewWithdrawal will create a Withdrawal // NewWithdrawal will create a Withdrawal
...@@ -44,7 +46,7 @@ func NewWithdrawal( ...@@ -44,7 +46,7 @@ func NewWithdrawal(
Target: target, Target: target,
Value: value, Value: value,
GasLimit: gasLimit, GasLimit: gasLimit,
Data: data, Data: hexutil.Bytes(data),
} }
} }
...@@ -58,9 +60,9 @@ func (w *Withdrawal) Encode() ([]byte, error) { ...@@ -58,9 +60,9 @@ func (w *Withdrawal) Encode() ([]byte, error) {
{Name: "gasLimit", Type: Uint256Type}, {Name: "gasLimit", Type: Uint256Type},
{Name: "data", Type: BytesType}, {Name: "data", Type: BytesType},
} }
enc, err := args.Pack(w.Nonce, w.Sender, w.Target, w.Value, w.GasLimit, w.Data) enc, err := args.Pack(w.Nonce, w.Sender, w.Target, w.Value, w.GasLimit, []byte(w.Data))
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("cannot encode withdrawal: %w", err)
} }
return enc, nil return enc, nil
} }
...@@ -110,7 +112,7 @@ func (w *Withdrawal) Decode(data []byte) error { ...@@ -110,7 +112,7 @@ func (w *Withdrawal) Decode(data []byte) error {
w.Target = &target w.Target = &target
w.Value = value w.Value = value
w.GasLimit = gasLimit w.GasLimit = gasLimit
w.Data = msgData w.Data = hexutil.Bytes(msgData)
return nil return nil
} }
...@@ -150,6 +152,6 @@ func (w *Withdrawal) WithdrawalTransaction() bindings.TypesWithdrawalTransaction ...@@ -150,6 +152,6 @@ func (w *Withdrawal) WithdrawalTransaction() bindings.TypesWithdrawalTransaction
Target: *w.Target, Target: *w.Target,
Value: w.Value, Value: w.Value,
GasLimit: w.GasLimit, GasLimit: w.GasLimit,
Data: w.Data, Data: []byte(w.Data),
} }
} }
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