Skip to content

Commit e8cee1b

Browse files
jacquescaocbxiangliu-cb
authored andcommitted
Fix FeeOps duplicated index issue and improve geth-sdk.
1 parent 57d5089 commit e8cee1b

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

examples/ethereum/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func (c *EthereumClient) ParseOps(
4646
var ops []*RosettaTypes.Operation
4747

4848
// Compute fee operations
49-
feeOps := services.FeeOps(tx)
49+
feeOps := services.FeeOps(tx, sdkTypes.Currency)
5050
ops = append(ops, feeOps...)
5151

52-
traceOps := services.TraceOps(tx.Trace, len(ops))
52+
traceOps := services.TraceOps(tx.Trace, len(ops), sdkTypes.Currency)
5353
ops = append(ops, traceOps...)
5454

5555
return ops, nil

mocks/services/client.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/construction/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
evmClient "github.com/coinbase/rosetta-geth-sdk/client"
2323
"github.com/coinbase/rosetta-geth-sdk/configuration"
2424
RosettaTypes "github.com/coinbase/rosetta-sdk-go/types"
25+
Eth "github.com/ethereum/go-ethereum"
2526
"github.com/ethereum/go-ethereum/common"
2627
EthTypes "github.com/ethereum/go-ethereum/core/types"
2728
"github.com/ethereum/go-ethereum/rpc"
@@ -194,4 +195,10 @@ type Client interface {
194195
ParseOps(
195196
tx *evmClient.LoadedTransaction,
196197
) ([]*RosettaTypes.Operation, error)
198+
199+
// EstimateGas tries to estimate the gas needed to execute a specific transaction based on
200+
// the current pending state of the backend blockchain. There is no guarantee that this is
201+
// the true gas limit requirement as other transactions may be added or removed by miners,
202+
// but it should provide a basis for setting a reasonable default.
203+
EstimateGas(ctx context.Context, msg Eth.CallMsg) (uint64, error)
197204
}

services/mapper.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TransferOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaType
130130
return ops
131131
}
132132

133-
func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
133+
func FeeOps(tx *evmClient.LoadedTransaction, native_currency *RosettaTypes.Currency) []*RosettaTypes.Operation {
134134
var minerEarnedAmount *big.Int
135135
if tx.FeeBurned == nil {
136136
minerEarnedAmount = tx.FeeAmount
@@ -157,7 +157,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
157157
Account: &RosettaTypes.AccountIdentifier{
158158
Address: evmClient.MustChecksum(tx.From.String()),
159159
},
160-
Amount: evmClient.Amount(new(big.Int).Neg(minerEarnedAmount), sdkTypes.Currency),
160+
Amount: evmClient.Amount(new(big.Int).Neg(minerEarnedAmount), native_currency),
161161
},
162162

163163
{
@@ -174,7 +174,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
174174
Account: &RosettaTypes.AccountIdentifier{
175175
Address: evmClient.MustChecksum(feeRewarder),
176176
},
177-
Amount: evmClient.Amount(minerEarnedAmount, sdkTypes.Currency),
177+
Amount: evmClient.Amount(minerEarnedAmount, native_currency),
178178
},
179179
}
180180

@@ -189,7 +189,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
189189
Type: sdkTypes.FeeOpType,
190190
Status: RosettaTypes.String(sdkTypes.SuccessStatus),
191191
Account: evmClient.Account(tx.From),
192-
Amount: evmClient.Amount(new(big.Int).Neg(tx.FeeBurned), sdkTypes.Currency),
192+
Amount: evmClient.Amount(new(big.Int).Neg(tx.FeeBurned), native_currency),
193193
}
194194

195195
ops = append(ops, burntOp)
@@ -203,6 +203,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) []*RosettaTypes.Operation {
203203
func TraceOps(
204204
calls []*evmClient.FlatCall,
205205
startIndex int,
206+
native_currency *RosettaTypes.Currency,
206207
) []*RosettaTypes.Operation { // nolint: gocognit
207208
var ops []*RosettaTypes.Operation
208209
if len(calls) == 0 {
@@ -250,7 +251,7 @@ func TraceOps(
250251
},
251252
Amount: &RosettaTypes.Amount{
252253
Value: new(big.Int).Neg(trace.Value).String(),
253-
Currency: sdkTypes.Currency,
254+
Currency: native_currency,
254255
},
255256
Metadata: metadata,
256257
}
@@ -311,7 +312,7 @@ func TraceOps(
311312
},
312313
Amount: &RosettaTypes.Amount{
313314
Value: trace.Value.String(),
314-
Currency: sdkTypes.Currency,
315+
Currency: native_currency,
315316
},
316317
Metadata: metadata,
317318
}
@@ -355,7 +356,7 @@ func TraceOps(
355356
},
356357
Amount: &RosettaTypes.Amount{
357358
Value: new(big.Int).Neg(val).String(),
358-
Currency: sdkTypes.Currency,
359+
Currency: native_currency,
359360
},
360361
})
361362
}

0 commit comments

Comments
 (0)