forked from evmos/ethermint
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from bianjieai/bump-sdk-to-v0.50
refactor: bump up cosmos-sdk to v0.50.10
- Loading branch information
Showing
187 changed files
with
4,298 additions
and
3,620 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
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,62 @@ | ||
package evmv1 | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/evmos/ethermint/types" | ||
) | ||
|
||
// GetChainID returns the chain id field from the AccessListTx | ||
func (tx *AccessListTx) GetChainID() *big.Int { | ||
return stringToBigInt(tx.GetChainId()) | ||
} | ||
|
||
// GetAccessList returns the AccessList field. | ||
func (tx *AccessListTx) GetAccessList() ethtypes.AccessList { | ||
if tx.Accesses == nil { | ||
return nil | ||
} | ||
var ethAccessList ethtypes.AccessList | ||
|
||
for _, tuple := range tx.Accesses { | ||
storageKeys := make([]common.Hash, len(tuple.StorageKeys)) | ||
|
||
for i := range tuple.StorageKeys { | ||
storageKeys[i] = common.HexToHash(tuple.StorageKeys[i]) | ||
} | ||
|
||
ethAccessList = append(ethAccessList, ethtypes.AccessTuple{ | ||
Address: common.HexToAddress(tuple.Address), | ||
StorageKeys: storageKeys, | ||
}) | ||
} | ||
|
||
return ethAccessList | ||
} | ||
|
||
// AsEthereumData returns an AccessListTx transaction tx from the proto-formatted | ||
// TxData defined on the Cosmos EVM. | ||
func (tx *AccessListTx) AsEthereumData() ethtypes.TxData { | ||
v, r, s := tx.GetRawSignatureValues() | ||
return ðtypes.AccessListTx{ | ||
ChainID: tx.GetChainID(), | ||
Nonce: tx.GetNonce(), | ||
GasPrice: stringToBigInt(tx.GetGasPrice()), | ||
Gas: tx.GetGas(), | ||
To: stringToAddress(tx.GetTo()), | ||
Value: stringToBigInt(tx.GetValue()), | ||
Data: tx.GetData(), | ||
AccessList: tx.GetAccessList(), | ||
V: v, | ||
R: r, | ||
S: s, | ||
} | ||
} | ||
|
||
// GetRawSignatureValues returns the V, R, S signature values of the transaction. | ||
// The return values should not be modified by the caller. | ||
func (tx *AccessListTx) GetRawSignatureValues() (v, r, s *big.Int) { | ||
return types.RawSignatureValues(tx.V, tx.R, tx.S) | ||
} |
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,66 @@ | ||
// Copyright Tharsis Labs Ltd.(Evmos) | ||
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE) | ||
|
||
package evmv1 | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/evmos/ethermint/types" | ||
) | ||
|
||
// GetChainID returns the chain id field from the DynamicFeeTx | ||
func (tx *DynamicFeeTx) GetChainID() *big.Int { | ||
return stringToBigInt(tx.GetChainId()) | ||
} | ||
|
||
// AsEthereumData returns an DynamicFeeTx transaction tx from the proto-formatted | ||
// TxData defined on the Cosmos EVM. | ||
func (tx *DynamicFeeTx) AsEthereumData() ethtypes.TxData { | ||
v, r, s := tx.GetRawSignatureValues() | ||
return ðtypes.DynamicFeeTx{ | ||
ChainID: tx.GetChainID(), | ||
Nonce: tx.GetNonce(), | ||
GasTipCap: stringToBigInt(tx.GetGasTipCap()), | ||
GasFeeCap: stringToBigInt(tx.GetGasFeeCap()), | ||
Gas: tx.GetGas(), | ||
To: stringToAddress(tx.GetTo()), | ||
Value: stringToBigInt(tx.GetValue()), | ||
Data: tx.GetData(), | ||
AccessList: tx.GetAccessList(), | ||
V: v, | ||
R: r, | ||
S: s, | ||
} | ||
} | ||
|
||
// GetAccessList returns the AccessList field. | ||
func (tx *DynamicFeeTx) GetAccessList() ethtypes.AccessList { | ||
if tx.Accesses == nil { | ||
return nil | ||
} | ||
var ethAccessList ethtypes.AccessList | ||
|
||
for _, tuple := range tx.Accesses { | ||
storageKeys := make([]common.Hash, len(tuple.StorageKeys)) | ||
|
||
for i := range tuple.StorageKeys { | ||
storageKeys[i] = common.HexToHash(tuple.StorageKeys[i]) | ||
} | ||
|
||
ethAccessList = append(ethAccessList, ethtypes.AccessTuple{ | ||
Address: common.HexToAddress(tuple.Address), | ||
StorageKeys: storageKeys, | ||
}) | ||
} | ||
|
||
return ethAccessList | ||
} | ||
|
||
// GetRawSignatureValues returns the V, R, S signature values of the transaction. | ||
// The return values should not be modified by the caller. | ||
func (tx *DynamicFeeTx) GetRawSignatureValues() (v, r, s *big.Int) { | ||
return types.RawSignatureValues(tx.V, tx.R, tx.S) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,42 @@ | ||
package evmv1 | ||
|
||
import ( | ||
"math/big" | ||
|
||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
"github.com/evmos/ethermint/types" | ||
) | ||
|
||
// GetChainID returns the chain id field from the derived signature values | ||
func (tx *LegacyTx) GetChainID() *big.Int { | ||
v, _, _ := tx.GetRawSignatureValues() | ||
return types.DeriveChainID(v) | ||
} | ||
|
||
// AsEthereumData returns an LegacyTx transaction tx from the proto-formatted | ||
// TxData defined on the Cosmos EVM. | ||
func (tx *LegacyTx) AsEthereumData() ethtypes.TxData { | ||
v, r, s := tx.GetRawSignatureValues() | ||
return ðtypes.LegacyTx{ | ||
Nonce: tx.GetNonce(), | ||
GasPrice: stringToBigInt(tx.GetGasPrice()), | ||
Gas: tx.GetGas(), | ||
To: stringToAddress(tx.GetTo()), | ||
Value: stringToBigInt(tx.GetValue()), | ||
Data: tx.GetData(), | ||
V: v, | ||
R: r, | ||
S: s, | ||
} | ||
} | ||
|
||
// GetRawSignatureValues returns the V, R, S signature values of the transaction. | ||
// The return values should not be modified by the caller. | ||
func (tx *LegacyTx) GetRawSignatureValues() (v, r, s *big.Int) { | ||
return types.RawSignatureValues(tx.V, tx.R, tx.S) | ||
} | ||
|
||
// GetAccessList returns nil | ||
func (tx *LegacyTx) GetAccessList() ethtypes.AccessList { | ||
return nil | ||
} |
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,56 @@ | ||
package evmv1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
protov2 "google.golang.org/protobuf/proto" | ||
) | ||
|
||
// supportedTxs holds the Ethereum transaction types | ||
// supported by Evmos. | ||
// Use a function to return a new pointer and avoid | ||
// possible reuse or racing conditions when using the same pointer | ||
var supportedTxs = map[string]func() TxDataV2{ | ||
"/ethermint.evm.v1.DynamicFeeTx": func() TxDataV2 { return &DynamicFeeTx{} }, | ||
"/ethermint.evm.v1.AccessListTx": func() TxDataV2 { return &AccessListTx{} }, | ||
"/ethermint.evm.v1.LegacyTx": func() TxDataV2 { return &LegacyTx{} }, | ||
} | ||
|
||
// getSender extracts the sender address from the signature values using the latest signer for the given chainID. | ||
func getSender(txData TxDataV2) (common.Address, error) { | ||
signer := ethtypes.LatestSignerForChainID(txData.GetChainID()) | ||
from, err := signer.Sender(ethtypes.NewTx(txData.AsEthereumData())) | ||
if err != nil { | ||
return common.Address{}, err | ||
} | ||
return from, nil | ||
} | ||
|
||
// GetSigners is the custom function to get signers on Ethereum transactions | ||
// Gets the signer's address from the Ethereum tx signature | ||
func GetSigners(msg protov2.Message) ([][]byte, error) { | ||
msgEthTx, ok := msg.(*MsgEthereumTx) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid type, expected MsgEthereumTx and got %T", msg) | ||
} | ||
|
||
txDataFn, found := supportedTxs[msgEthTx.Data.TypeUrl] | ||
if !found { | ||
return nil, fmt.Errorf("invalid TypeUrl %s", msgEthTx.Data.TypeUrl) | ||
} | ||
txData := txDataFn() | ||
|
||
// msgEthTx.Data is a message (DynamicFeeTx, LegacyTx or AccessListTx) | ||
if err := msgEthTx.Data.UnmarshalTo(txData); err != nil { | ||
return nil, err | ||
} | ||
|
||
sender, err := getSender(txData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return [][]byte{sender.Bytes()}, nil | ||
} |
Oops, something went wrong.