Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse L1-> L2 deposit transaction #2

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.idea/
/bin/
/cli-data/*
rosetta-cli-conf/*
42 changes: 41 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,18 +16,55 @@ 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"
)

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...)

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down