-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[action] add EvmTransaction to represent actions that run in EVM (#4227)
- Loading branch information
Showing
7 changed files
with
94 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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. | ||
|
||
package action | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
type ( | ||
// EvmTransaction represents an action to be executed by EVM protocol | ||
// as of now 3 types of transactions are supported: | ||
// 1. Legacy transaction | ||
// 2. EIP-2930 access list transaction | ||
// 3. EIP-4844 shard blob transaction | ||
EvmTransaction struct { | ||
inner TxData | ||
} | ||
|
||
TxData interface { | ||
Nonce() uint64 | ||
GasLimit() uint64 | ||
GasPrice() *big.Int | ||
Amount() *big.Int | ||
To() *common.Address | ||
Data() []byte | ||
AccessList() types.AccessList | ||
} | ||
) | ||
|
||
func NewEvmTx(a Action) *EvmTransaction { | ||
tx := new(EvmTransaction) | ||
switch act := a.(type) { | ||
case *Execution: | ||
tx.inner = act | ||
default: | ||
panic("unsupported action type") | ||
} | ||
return tx | ||
} | ||
|
||
func (tx *EvmTransaction) Nonce() uint64 { | ||
return tx.inner.Nonce() | ||
} | ||
|
||
func (tx *EvmTransaction) Gas() uint64 { | ||
return tx.inner.GasLimit() | ||
} | ||
|
||
func (tx *EvmTransaction) GasPrice() *big.Int { | ||
return tx.inner.GasPrice() | ||
} | ||
|
||
func (tx *EvmTransaction) Value() *big.Int { | ||
return tx.inner.Amount() | ||
} | ||
|
||
func (tx *EvmTransaction) To() *common.Address { | ||
return tx.inner.To() | ||
} | ||
|
||
func (tx *EvmTransaction) Data() []byte { | ||
return tx.inner.Data() | ||
} | ||
|
||
func (tx *EvmTransaction) AccessList() types.AccessList { | ||
return tx.inner.AccessList() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters