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

Support Rosetta Currency to be passed as argument #116

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
29 changes: 23 additions & 6 deletions services/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func TransferOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaType
return ops
}

func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
func FeeOps(tx *evmClient.LoadedTransaction, args ...interface{}) []*RosettaTypes.Operation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function argument change can potentially break all upstream Rosetta (e.g. Base, Arbitrum, BSC). regression tests for different chains are needed for this change

var currency = getCurrency(args)

var minerEarnedAmount *big.Int
if tx.FeeBurned == nil {
minerEarnedAmount = tx.FeeAmount
Expand All @@ -157,7 +159,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
Account: &RosettaTypes.AccountIdentifier{
Address: evmClient.MustChecksum(tx.From.String()),
},
Amount: evmClient.Amount(new(big.Int).Neg(minerEarnedAmount), sdkTypes.Currency),
Amount: evmClient.Amount(new(big.Int).Neg(minerEarnedAmount), currency),
},

{
Expand All @@ -174,7 +176,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
Account: &RosettaTypes.AccountIdentifier{
Address: evmClient.MustChecksum(feeRewarder),
},
Amount: evmClient.Amount(minerEarnedAmount, sdkTypes.Currency),
Amount: evmClient.Amount(minerEarnedAmount, currency),
},
}

Expand All @@ -197,13 +199,28 @@ func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
return ops
}

func getCurrency(params []interface{}) *RosettaTypes.Currency {
var nativeCurrency *RosettaTypes.Currency
if len(params) > 0 {
if currencyParam, ok := params[0].(*RosettaTypes.Currency); ok {
nativeCurrency = currencyParam
}
}
if nativeCurrency == nil {
nativeCurrency = sdkTypes.Currency
}
return nativeCurrency
}

// TraceOps returns all *RosettaTypes.Operation for a given
// array of flattened traces.
// nolint:gocognit
func TraceOps(
calls []*evmClient.FlatCall,
startIndex int,
args ...interface{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function argument change can potentially break all upstream Rosetta (e.g. Base, Arbitrum, BSC). regression tests for different chains are needed for this change

) []*RosettaTypes.Operation { // nolint: gocognit
var currency = getCurrency(args)
var ops []*RosettaTypes.Operation
if len(calls) == 0 {
return ops
Expand Down Expand Up @@ -250,7 +267,7 @@ func TraceOps(
},
Amount: &RosettaTypes.Amount{
Value: new(big.Int).Neg(trace.Value).String(),
Currency: sdkTypes.Currency,
Currency: currency,
},
Metadata: metadata,
}
Expand Down Expand Up @@ -311,7 +328,7 @@ func TraceOps(
},
Amount: &RosettaTypes.Amount{
Value: trace.Value.String(),
Currency: sdkTypes.Currency,
Currency: currency,
},
Metadata: metadata,
}
Expand Down Expand Up @@ -355,7 +372,7 @@ func TraceOps(
},
Amount: &RosettaTypes.Amount{
Value: new(big.Int).Neg(val).String(),
Currency: sdkTypes.Currency,
Currency: currency,
},
})
}
Expand Down
Loading