Skip to content

Commit

Permalink
[action] add EvmTransaction interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Apr 11, 2024
1 parent 66d8a51 commit b8e0ef2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
15 changes: 15 additions & 0 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ type (
ToEthTx(uint32) (*types.Transaction, error)
}

// EvmTransaction represents an action to be executed by EVM protocol
// as of now 3 types of transactions are supported:
// 1. regular Execution
// 2. EIP-2930 access list
// 3. EIP-4844 shard blob transaction
EvmTransaction interface {
Nonce() uint64
GasLimit() uint64
GasPrice() *big.Int
Amount() *big.Int
To() string
Data() []byte
AccessList() types.AccessList
}

actionPayload interface {
Cost() (*big.Int, error)
IntrinsicGas() (uint64, error)
Expand Down
3 changes: 2 additions & 1 deletion action/execution.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 IoTeX Foundation
// Copyright (c) 2024 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
Expand Down Expand Up @@ -33,6 +33,7 @@ const (
var (
_ hasDestination = (*Execution)(nil)
_ EthCompatibleAction = (*Execution)(nil)
_ EvmTransaction = (*Execution)(nil)
)

// Execution defines the struct of account-based contract execution
Expand Down
8 changes: 4 additions & 4 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 IoTeX Foundation
// Copyright (c) 2024 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
Expand Down Expand Up @@ -108,7 +108,7 @@ type (
// newParams creates a new context for use in the EVM.
func newParams(
ctx context.Context,
execution *action.Execution,
execution action.EvmTransaction,
stateDB *StateDBAdapter,
) (*Params, error) {
var (
Expand Down Expand Up @@ -237,7 +237,7 @@ func securityDeposit(ps *Params, stateDB vm.StateDB, gasLimit uint64) error {
func ExecuteContract(
ctx context.Context,
sm protocol.StateManager,
execution *action.Execution,
execution action.EvmTransaction,
) ([]byte, *action.Receipt, error) {
ctx, span := tracer.NewSpan(ctx, "evm.ExecuteContract")
defer span.End()
Expand Down Expand Up @@ -332,7 +332,7 @@ func ExecuteContract(
return retval, receipt, nil
}

func processSGD(ctx context.Context, sm protocol.StateManager, execution *action.Execution, consumedGas uint64, sgd SGDRegistry,
func processSGD(ctx context.Context, sm protocol.StateManager, execution action.EvmTransaction, consumedGas uint64, sgd SGDRegistry,
) (address.Address, uint64, error) {
if execution.To() == action.EmptyAddress {
return nil, 0, nil
Expand Down
4 changes: 2 additions & 2 deletions action/protocol/execution/protocol.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 IoTeX Foundation
// Copyright (c) 2024 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
Expand Down Expand Up @@ -64,7 +64,7 @@ func FindProtocol(registry *protocol.Registry) *Protocol {

// Handle handles an execution
func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.StateManager) (*action.Receipt, error) {
exec, ok := act.(*action.Execution)
exec, ok := act.(action.EvmTransaction)
if !ok {
return nil, nil
}
Expand Down

0 comments on commit b8e0ef2

Please sign in to comment.