diff --git a/.gitignore b/.gitignore index e10deff..bee07ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /.idea/ /bin/ +/cli-data/* +rosetta-cli-conf/* diff --git a/client.go b/client.go index 41d962b..0815aaf 100644 --- a/client.go +++ b/client.go @@ -3,8 +3,10 @@ package main import ( "context" "fmt" - "github.com/coinbase/rosetta-geth-sdk/configuration" "math/big" + "strings" + + "github.com/coinbase/rosetta-geth-sdk/configuration" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -14,6 +16,7 @@ import ( "github.com/coinbase/rosetta-geth-sdk/services" sdkTypes "github.com/coinbase/rosetta-geth-sdk/types" "github.com/coinbase/rosetta-sdk-go/types" + RosettaTypes "github.com/coinbase/rosetta-sdk-go/types" EthTypes "github.com/ethereum/go-ethereum/core/types" ) @@ -21,11 +24,47 @@ type OpClient struct { *evmClient.SDKClient } +const ( + L1ToL2DepositType = 126 +) + func (c *OpClient) ParseOps( tx *evmClient.LoadedTransaction, ) ([]*types.Operation, error) { var ops []*types.Operation + if tx.Receipt.Type == L1ToL2DepositType && len(tx.Trace) > 0 { + trace := tx.Trace[0] + traceType := strings.ToUpper(trace.Type) + opStatus := sdkTypes.SuccessStatus + from := evmClient.MustChecksum(trace.From.String()) + to := evmClient.MustChecksum(trace.To.String()) + metadata := map[string]interface{}{} + + if from != to { + feeOps := services.FeeOps(tx) + ops = append(ops, feeOps...) + } + + toOp := &RosettaTypes.Operation{ + OperationIdentifier: &RosettaTypes.OperationIdentifier{ + Index: int64(len(ops) + 0), + }, + Type: traceType, + Status: RosettaTypes.String(opStatus), + Account: &RosettaTypes.AccountIdentifier{ + Address: to, + }, + Amount: &RosettaTypes.Amount{ + Value: trace.Value.String(), + Currency: sdkTypes.Currency, + }, + Metadata: metadata, + } + ops = append(ops, toOp) + return ops, nil + } + feeOps := services.FeeOps(tx) ops = append(ops, feeOps...) @@ -71,6 +110,7 @@ func (c *OpClient) GetBlockReceipts( feeAmount := new(big.Int).Mul(gasUsed, gasPrice) receipt := &evmClient.RosettaTxReceipt{ + Type: ethReceipts[i].Type, GasPrice: gasPrice, GasUsed: gasUsed, Logs: ethReceipts[i].Logs, diff --git a/go.mod b/go.mod index 034c049..a53b523 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module github.com/mdehoog/op-rosetta go 1.18 require ( - github.com/coinbase/rosetta-geth-sdk v0.0.3 + github.com/coinbase/rosetta-geth-sdk v0.0.4 github.com/coinbase/rosetta-sdk-go v0.7.11 - github.com/ethereum/go-ethereum v1.10.21 + github.com/ethereum/go-ethereum v1.10.26 ) require ( @@ -55,4 +55,4 @@ require ( gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect ) -replace github.com/ethereum/go-ethereum v1.10.21 => github.com/ethereum-optimism/op-geth v0.0.0-20221104231810-30db39cae2be +replace github.com/ethereum/go-ethereum v1.10.26 => github.com/ethereum-optimism/op-geth v0.0.0-20221104231810-30db39cae2be diff --git a/go.sum b/go.sum index 83589ef..a65e3a9 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/cloudflare/cloudflare-go v0.14.0/go.mod h1:EnwdgGMaFOruiPZRFSgn+TsQ3h github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= github.com/coinbase/rosetta-geth-sdk v0.0.3 h1:OSbHmToxwks0cDrbw88zgOGEPaDgegZfHN0KD4aIH3Q= github.com/coinbase/rosetta-geth-sdk v0.0.3/go.mod h1:z8UygO+4oDwEdIIsqAWZXp37jGGhcqsoJ/4eszTl3NU= +github.com/coinbase/rosetta-geth-sdk v0.0.4 h1:mY3tQroU9wpjkysI0chHY3D4WB1Tw2MZZz52FgREuwY= +github.com/coinbase/rosetta-geth-sdk v0.0.4/go.mod h1:MAx4sNfce7jlFXuVRt3nc63fMQi8cRUFYKnLiDLOCSE= github.com/coinbase/rosetta-sdk-go v0.7.11 h1:T7camDGstlX2ENVE0QHR1AVu3asSXED0vg1xDaF6bYE= github.com/coinbase/rosetta-sdk-go v0.7.11/go.mod h1:HLTqSTSnOGLWHGTxoUJQO2TLuKkas1B9i/7ByerK6lM= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ=