Skip to content

Commit

Permalink
internal/ethapi: merge CallArgs and SendTxArgs (ethereum#22718)
Browse files Browse the repository at this point in the history
There are two transaction parameter structures defined in
the codebase, although for different purposes. But most of
the parameters are shared. So it's nice to reduce the code
duplication by merging them together.

Co-authored-by: Martin Holst Swende <[email protected]>
  • Loading branch information
2 people authored and atif-konasl committed Oct 15, 2021
1 parent e9e8b48 commit 14f29f4
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 223 deletions.
2 changes: 1 addition & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ func (api *API) TraceTransaction(ctx context.Context, hash common.Hash, config *
// created during the execution of EVM if the given transaction was added on
// top of the provided block and returns them as a JSON object.
// You can provide -2 as a block number to trace on top of the pending block.
func (api *API) TraceCall(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) {
func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) (interface{}, error) {
// Try to retrieve the specified block
var (
err error
Expand Down
20 changes: 10 additions & 10 deletions eth/tracers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ func TestTraceCall(t *testing.T) {

var testSuite = []struct {
blockNumber rpc.BlockNumber
call ethapi.CallArgs
call ethapi.TransactionArgs
config *TraceCallConfig
expectErr error
expect interface{}
}{
// Standard JSON trace upon the genesis, plain transfer.
{
blockNumber: rpc.BlockNumber(0),
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
Expand All @@ -223,7 +223,7 @@ func TestTraceCall(t *testing.T) {
// Standard JSON trace upon the head, plain transfer.
{
blockNumber: rpc.BlockNumber(genBlocks),
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
Expand All @@ -240,7 +240,7 @@ func TestTraceCall(t *testing.T) {
// Standard JSON trace upon the non-existent block, error expects
{
blockNumber: rpc.BlockNumber(genBlocks + 1),
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
Expand All @@ -252,7 +252,7 @@ func TestTraceCall(t *testing.T) {
// Standard JSON trace upon the latest block
{
blockNumber: rpc.LatestBlockNumber,
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
Expand All @@ -269,7 +269,7 @@ func TestTraceCall(t *testing.T) {
// Standard JSON trace upon the pending block
{
blockNumber: rpc.PendingBlockNumber,
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
Expand Down Expand Up @@ -329,15 +329,15 @@ func TestOverridenTraceCall(t *testing.T) {

var testSuite = []struct {
blockNumber rpc.BlockNumber
call ethapi.CallArgs
call ethapi.TransactionArgs
config *TraceCallConfig
expectErr error
expect *callTrace
}{
// Succcessful call with state overriding
{
blockNumber: rpc.PendingBlockNumber,
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &randomAccounts[0].addr,
To: &randomAccounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
Expand All @@ -361,7 +361,7 @@ func TestOverridenTraceCall(t *testing.T) {
// Invalid call without state overriding
{
blockNumber: rpc.PendingBlockNumber,
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &randomAccounts[0].addr,
To: &randomAccounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestOverridenTraceCall(t *testing.T) {
// }
{
blockNumber: rpc.PendingBlockNumber,
call: ethapi.CallArgs{
call: ethapi.TransactionArgs{
From: &randomAccounts[0].addr,
To: &randomAccounts[2].addr,
Data: newRPCBytes(common.Hex2Bytes("8381f58a")), // call number()
Expand Down
8 changes: 4 additions & 4 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (c *CallResult) Status() Long {
}

func (b *Block) Call(ctx context.Context, args struct {
Data ethapi.CallArgs
Data ethapi.TransactionArgs
}) (*CallResult, error) {
if b.numberOrHash == nil {
_, err := b.resolve(ctx)
Expand All @@ -887,7 +887,7 @@ func (b *Block) Call(ctx context.Context, args struct {
}

func (b *Block) EstimateGas(ctx context.Context, args struct {
Data ethapi.CallArgs
Data ethapi.TransactionArgs
}) (Long, error) {
if b.numberOrHash == nil {
_, err := b.resolveHeader(ctx)
Expand Down Expand Up @@ -937,7 +937,7 @@ func (p *Pending) Account(ctx context.Context, args struct {
}

func (p *Pending) Call(ctx context.Context, args struct {
Data ethapi.CallArgs
Data ethapi.TransactionArgs
}) (*CallResult, error) {
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
result, err := ethapi.DoCall(ctx, p.backend, args.Data, pendingBlockNr, nil, vm.Config{}, 5*time.Second, p.backend.RPCGasCap())
Expand All @@ -957,7 +957,7 @@ func (p *Pending) Call(ctx context.Context, args struct {
}

func (p *Pending) EstimateGas(ctx context.Context, args struct {
Data ethapi.CallArgs
Data ethapi.TransactionArgs
}) (Long, error) {
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
gas, err := ethapi.DoEstimateGas(ctx, p.backend, args.Data, pendingBlockNr, p.backend.RPCGasCap())
Expand Down
Loading

0 comments on commit 14f29f4

Please sign in to comment.