Skip to content

Commit

Permalink
Merge pull request #25 from bianjieai/bump-sdk-to-v0.50
Browse files Browse the repository at this point in the history
refactor: bump up cosmos-sdk to v0.50.10
  • Loading branch information
zhangyelong authored Nov 18, 2024
2 parents 2b59262 + ae4023f commit 53fd936
Show file tree
Hide file tree
Showing 187 changed files with 4,298 additions and 3,620 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ format-fix:
### Protobuf ###
###############################################################################

protoVer=0.11.6
protoVer=0.13.0
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

Expand Down
62 changes: 62 additions & 0 deletions api/ethermint/evm/v1/access_list_tx.go
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 &ethtypes.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)
}
66 changes: 66 additions & 0 deletions api/ethermint/evm/v1/dynamic_fee_tx.go
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 &ethtypes.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)
}
450 changes: 216 additions & 234 deletions api/ethermint/evm/v1/evm.pulsar.go

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions api/ethermint/evm/v1/legacy_tx.go
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 &ethtypes.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
}
56 changes: 56 additions & 0 deletions api/ethermint/evm/v1/msg.go
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
}
Loading

0 comments on commit 53fd936

Please sign in to comment.