Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dajuguan committed Oct 9, 2024
1 parent 3d9e698 commit 8db70b8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion op-challenger/game/fault/contracts/faultdisputegame.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (f *FaultDisputeGameContractLatest) GetSubClaims(ctx context.Context, block
txHash := moveIter.Event.Raw.TxHash

// todo: replace hardcoded method name
txCall := batching.NewTxCall(f.contract.Abi(), txHash, "move")
txCall := batching.NewTxGetByHash(f.contract.Abi(), txHash, "move")
result, err := f.multiCaller.SingleCall(ctx, rpcblock.Latest, txCall)
if err != nil {
return nil, fmt.Errorf("failed to load claim calldata: %w", err)
Expand All @@ -481,6 +481,7 @@ func (f *FaultDisputeGameContractLatest) GetSubClaims(ctx context.Context, block

if len(txn.BlobHashes()) > 0 {
// todo: fetch Blobs and unpack it into subClaims
return nil, fmt.Errorf("blob tx hasn't been supported")
} else {
inputMap, err := txCall.UnpackCallData(txn)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions op-service/sources/batching/tx_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

type TxCall struct {
type TxGetByHashCall struct {
Abi *abi.ABI
TxHash common.Hash
Method string
}

func NewTxCall(abi *abi.ABI, txhash common.Hash, method string) *TxCall {
return &TxCall{
func NewTxGetByHash(abi *abi.ABI, txhash common.Hash, method string) *TxGetByHashCall {
return &TxGetByHashCall{
Abi: abi,
TxHash: txhash,
Method: method,
}
}

func (b *TxCall) ToBatchElemCreator() (BatchElementCreator, error) {
func (b *TxGetByHashCall) ToBatchElemCreator() (BatchElementCreator, error) {
return func(block rpcblock.Block) (any, rpc.BatchElem) {
out := new(hexutil.Bytes)
return out, rpc.BatchElem{
Expand All @@ -34,12 +34,12 @@ func (b *TxCall) ToBatchElemCreator() (BatchElementCreator, error) {
}, nil
}

func (c *TxCall) HandleResult(result interface{}) (*CallResult, error) {
func (c *TxGetByHashCall) HandleResult(result interface{}) (*CallResult, error) {
res := result.(*hexutil.Bytes)
return &CallResult{out: []interface{}{*res}}, nil
}

func (c *TxCall) DecodeTxParams(data []byte) (map[string]interface{}, error) {
func (c *TxGetByHashCall) DecodeTxParams(data []byte) (map[string]interface{}, error) {
m, err := c.Abi.MethodById(data[:4])
v := map[string]interface{}{}
if err != nil {
Expand All @@ -51,7 +51,7 @@ func (c *TxCall) DecodeTxParams(data []byte) (map[string]interface{}, error) {
return v, nil
}

func (c *TxCall) DecodeToTx(res *CallResult) (*types.Transaction, error) {
func (c *TxGetByHashCall) DecodeToTx(res *CallResult) (*types.Transaction, error) {
txn := new(types.Transaction)
hex := res.out[0].(hexutil.Bytes)
err := txn.UnmarshalBinary(hex)
Expand All @@ -61,7 +61,7 @@ func (c *TxCall) DecodeToTx(res *CallResult) (*types.Transaction, error) {
return txn, nil
}

func (c *TxCall) UnpackCallData(txn *types.Transaction) (map[string]interface{}, error) {
func (c *TxGetByHashCall) UnpackCallData(txn *types.Transaction) (map[string]interface{}, error) {
input := txn.Data()
return c.DecodeTxParams(input)
}
6 changes: 3 additions & 3 deletions op-service/sources/batching/tx_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/stretchr/testify/require"
)

func TestDecodeTxCall(t *testing.T) {
func TestDecodeTxGetByHash(t *testing.T) {
addr := common.Address{0xbd}
testAbi, err := test.ERC20MetaData.GetAbi()
require.NoError(t, err)
call := NewTxCall(testAbi, common.Hash{0xcc}, "approve")
call := NewTxGetByHash(testAbi, common.Hash{0xcc}, "approve")
expectedAmount := big.NewInt(1234444)
expectedSpender := common.Address{0xcc}
contractCall := NewContractCall(testAbi, addr, "approve", expectedSpender, expectedAmount)
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestUnpackTxCalldata(t *testing.T) {
stub.AddExpectedCall(test.NewGetTxCall(txHash, rpcblock.Latest, &packed))

caller := NewMultiCaller(stub, DefaultBatchSize)
txCall := NewTxCall(testAbi, txHash, "approve")
txCall := NewTxGetByHash(testAbi, txHash, "approve")
result, err := caller.SingleCall(context.Background(), rpcblock.Latest, txCall)
require.NoError(t, err)

Expand Down

0 comments on commit 8db70b8

Please sign in to comment.