Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta92115 committed Mar 29, 2024
1 parent 14fc62c commit da45a12
Show file tree
Hide file tree
Showing 29 changed files with 113 additions and 157 deletions.
9 changes: 5 additions & 4 deletions app/ante/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import (

"swisstronik/crypto/ethsecp256k1"
"swisstronik/ethereum/eip712"
ethermint "swisstronik/types"

ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/signer/core/apitypes"

evmtypes "swisstronik/x/evm/types"

swisstroniktypes "swisstronik/types"

txsigning "cosmossdk.io/x/tx/signing"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand All @@ -48,7 +49,7 @@ var ethermintCodec codec.ProtoCodecMarshaler

func init() {
registry := codectypes.NewInterfaceRegistry()
ethermint.RegisterInterfaces(registry)
swisstroniktypes.RegisterInterfaces(registry)
ethermintCodec = codec.NewProtoCodec(registry)
}

Expand Down Expand Up @@ -240,7 +241,7 @@ func VerifySignature(
msgs, tx.GetMemo(),
)

signerChainID, err := ethermint.ParseChainID(signerData.ChainID)
signerChainID, err := swisstroniktypes.ParseChainID(signerData.ChainID)
if err != nil {
return errorsmod.Wrapf(err, "failed to parse chain-id: %s", signerData.ChainID)
}
Expand All @@ -254,7 +255,7 @@ func VerifySignature(
return errorsmod.Wrap(errortypes.ErrUnknownExtensionOptions, "tx doesnt contain expected amount of extension options")
}

extOpt, ok := opts[0].GetCachedValue().(*ethermint.ExtensionOptionsWeb3Tx)
extOpt, ok := opts[0].GetCachedValue().(*swisstroniktypes.ExtensionOptionsWeb3Tx)
if !ok {
return errorsmod.Wrap(errortypes.ErrUnknownExtensionOptions, "unknown extension option")
}
Expand Down
5 changes: 3 additions & 2 deletions app/ante/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"

ethermint "swisstronik/types"
"swisstronik/x/evm/types"

swisstroniktypes "swisstronik/types"

sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
Expand Down Expand Up @@ -66,7 +67,7 @@ func NewDynamicFeeChecker(k DynamicFeeEVMKeeper) authante.TxFeeChecker {
// get the priority tip cap from the extension option.
if hasExtOptsTx, ok := tx.(authante.HasExtensionOptionsTx); ok {
for _, opt := range hasExtOptsTx.GetExtensionOptions() {
if extOpt, ok := opt.GetCachedValue().(*ethermint.ExtensionOptionDynamicFeeTx); ok {
if extOpt, ok := opt.GetCachedValue().(*swisstroniktypes.ExtensionOptionDynamicFeeTx); ok {
maxPriorityPrice = extOpt.MaxPriorityPrice
break
}
Expand Down
6 changes: 3 additions & 3 deletions app/ante/fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"

"swisstronik/encoding"
ethermint "swisstronik/types"
swisstroniktypes "swisstronik/types"
"swisstronik/x/evm/types"
evmtypes "swisstronik/x/evm/types"

Expand Down Expand Up @@ -173,7 +173,7 @@ func TestSDKTxFeeChecker(t *testing.T) {
txBuilder.SetGasLimit(1)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("uswtr", sdkmath.NewInt(10).Mul(types.DefaultPriorityReduction))))

option, err := codectypes.NewAnyWithValue(&ethermint.ExtensionOptionDynamicFeeTx{})
option, err := codectypes.NewAnyWithValue(&swisstroniktypes.ExtensionOptionDynamicFeeTx{})
require.NoError(t, err)
txBuilder.SetExtensionOptions(option)
return txBuilder.GetTx()
Expand All @@ -193,7 +193,7 @@ func TestSDKTxFeeChecker(t *testing.T) {
txBuilder.SetGasLimit(1)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin("uswtr", sdkmath.NewInt(10).Mul(types.DefaultPriorityReduction).Add(sdkmath.NewInt(10)))))

option, err := codectypes.NewAnyWithValue(&ethermint.ExtensionOptionDynamicFeeTx{
option, err := codectypes.NewAnyWithValue(&swisstroniktypes.ExtensionOptionDynamicFeeTx{
MaxPriorityPrice: sdkmath.NewInt(5).Mul(types.DefaultPriorityReduction),
})
require.NoError(t, err)
Expand Down
7 changes: 0 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ import (
"swisstronik/ethereum/eip712"

sdkmath "cosmossdk.io/math"
"cosmossdk.io/simapp"
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/x/consensus"
Expand Down Expand Up @@ -312,12 +311,6 @@ func New(
interfaceRegistry := encodingConfig.InterfaceRegistry

eip712.SetEncodingConfig(encodingConfig)
// create and set dummy vote extension handler
voteExtOp := func(bApp *baseapp.BaseApp) {
voteExtHandler := simapp.NewVoteExtensionHandler()
voteExtHandler.SetHandlers(bApp)
}
baseAppOptions = append(baseAppOptions, voteExtOp, baseapp.SetOptimisticExecution())
// Setup Mempool and Proposal Handlers
baseAppOptions = append(baseAppOptions, func(app *baseapp.BaseApp) {
mempool := mempool.NoOpMempool{}
Expand Down
6 changes: 3 additions & 3 deletions cmd/swisstronikd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import (

"swisstronik/utils"

ethermint "swisstronik/types"
swisstroniktypes "swisstronik/types"

"github.com/cosmos/cosmos-sdk/client/snapshot"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -71,7 +71,7 @@ import (
const ShortBlockWindow uint32 = 20

// NewRootCmd creates a new root command for a Cosmos SDK application
func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) {
func NewRootCmd() (*cobra.Command, swisstroniktypes.EncodingConfig) {
// Initialize the SDK config the first before doing anything else.
InitSDKConfig()

Expand Down Expand Up @@ -281,7 +281,7 @@ func addModuleInitFlags(startCmd *cobra.Command) {
}

type appCreator struct {
encodingConfig ethermint.EncodingConfig
encodingConfig swisstroniktypes.EncodingConfig
}

// newApp creates a new Cosmos SDK app
Expand Down
2 changes: 1 addition & 1 deletion crypto/hd/benchmark_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hd

import (
ethermint "swisstronik/types"
"testing"

ethermint "swisstronik/types"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

Expand Down
6 changes: 3 additions & 3 deletions encoding/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

enccodec "swisstronik/encoding/codec"

ethermint "swisstronik/types"
swisstroniktypes "swisstronik/types"

"cosmossdk.io/x/tx/signing"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -47,7 +47,7 @@ func customGetSignerFn(path string) func(msg proto.Message) ([][]byte, error) {
}

// MakeConfig creates an EncodingConfig for testing
func MakeConfig() ethermint.EncodingConfig {
func MakeConfig() swisstroniktypes.EncodingConfig {
cdc := amino.NewLegacyAmino()
addrPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
valAddrPrefix := sdk.GetConfig().GetBech32ValidatorAddrPrefix()
Expand All @@ -68,7 +68,7 @@ func MakeConfig() ethermint.EncodingConfig {
}
codec := amino.NewProtoCodec(interfaceRegistry)

encodingConfig := ethermint.EncodingConfig{
encodingConfig := swisstroniktypes.EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Codec: codec,
TxConfig: tx.NewTxConfig(codec, tx.DefaultSignModes),
Expand Down
3 changes: 1 addition & 2 deletions ethereum/eip712/eip712_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"cosmossdk.io/math"

"swisstronik/ethereum/eip712"
ethermint "swisstronik/types"

"github.com/cosmos/cosmos-sdk/client"

Expand All @@ -25,8 +26,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"

ethermint "swisstronik/types"

v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
Expand Down
10 changes: 5 additions & 5 deletions ethereum/eip712/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
txTypes "github.com/cosmos/cosmos-sdk/types/tx"

ethermint "swisstronik/types"

apitypes "github.com/ethereum/go-ethereum/signer/core/apitypes"

swisstroniktypes "swisstronik/types"

"github.com/cosmos/cosmos-sdk/codec"
)

Expand All @@ -46,7 +46,7 @@ var (
// The process of unmarshaling SignDoc bytes into a SignDoc object requires having a codec
// populated with all relevant message types. As a result, we must call this method on app
// initialization with the app's encoding config.
func SetEncodingConfig(cfg ethermint.EncodingConfig) {
func SetEncodingConfig(cfg swisstroniktypes.EncodingConfig) {
aminoCodec = cfg.Amino
protoCodec = codec.NewProtoCodec(cfg.InterfaceRegistry)
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func decodeAminoSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {
FeePayer: feePayer,
}

chainID, err := ethermint.ParseChainID(aminoDoc.ChainID)
chainID, err := swisstroniktypes.ParseChainID(aminoDoc.ChainID)
if err != nil {
return apitypes.TypedData{}, errors.New("invalid chain ID passed as argument")
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func decodeProtobufSignDoc(signDocBytes []byte) (apitypes.TypedData, error) {

signerInfo := authInfo.SignerInfos[0]

chainID, err := ethermint.ParseChainID(signDoc.ChainId)
chainID, err := swisstroniktypes.ParseChainID(signDoc.ChainId)
if err != nil {
return apitypes.TypedData{}, fmt.Errorf("invalid chain ID passed as argument: %w", err)
}
Expand Down
14 changes: 7 additions & 7 deletions indexer/kv_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/ethereum/go-ethereum/common"

ethermint "swisstronik/types"
swisstroniktypes "swisstronik/types"
evmtypes "swisstronik/x/evm/types"
)

Expand All @@ -43,7 +43,7 @@ const (
TxIndexKeyLength = 1 + 8 + 8
)

var _ ethermint.EVMTxIndexer = &KVIndexer{}
var _ swisstroniktypes.EVMTxIndexer = &KVIndexer{}

// KVIndexer implements a eth tx indexer on a KV db.
type KVIndexer struct {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (kv *KVIndexer) IndexBlock(block *tmtypes.Block, txResults []*abci.ExecTxRe
ethMsg := msg.(*evmtypes.MsgHandleTx)
txHash := common.HexToHash(ethMsg.Hash)

txResult := ethermint.TxResult{
txResult := swisstroniktypes.TxResult{
Height: height,
TxIndex: uint32(txIndex),
MsgIndex: uint32(msgIndex),
Expand Down Expand Up @@ -147,23 +147,23 @@ func (kv *KVIndexer) FirstIndexedBlock() (int64, error) {
}

// GetByTxHash finds eth tx by eth tx hash
func (kv *KVIndexer) GetByTxHash(hash common.Hash) (*ethermint.TxResult, error) {
func (kv *KVIndexer) GetByTxHash(hash common.Hash) (*swisstroniktypes.TxResult, error) {
bz, err := kv.db.Get(TxHashKey(hash))
if err != nil {
return nil, errorsmod.Wrapf(err, "GetByTxHash %s", hash.Hex())
}
if len(bz) == 0 {
return nil, fmt.Errorf("tx not found, hash: %s", hash.Hex())
}
var txKey ethermint.TxResult
var txKey swisstroniktypes.TxResult
if err := kv.clientCtx.Codec.Unmarshal(bz, &txKey); err != nil {
return nil, errorsmod.Wrapf(err, "GetByTxHash %s", hash.Hex())
}
return &txKey, nil
}

// GetByBlockAndIndex finds eth tx by block number and eth tx index
func (kv *KVIndexer) GetByBlockAndIndex(blockNumber int64, txIndex int32) (*ethermint.TxResult, error) {
func (kv *KVIndexer) GetByBlockAndIndex(blockNumber int64, txIndex int32) (*swisstroniktypes.TxResult, error) {
bz, err := kv.db.Get(TxIndexKey(blockNumber, txIndex))
if err != nil {
return nil, errorsmod.Wrapf(err, "GetByBlockAndIndex %d %d", blockNumber, txIndex)
Expand Down Expand Up @@ -226,7 +226,7 @@ func isEthTx(tx sdk.Tx) bool {
}

// saveTxResult index the txResult into the kv db batch
func saveTxResult(codec codec.Codec, batch dbm.Batch, txHash common.Hash, txResult *ethermint.TxResult) error {
func saveTxResult(codec codec.Codec, batch dbm.Batch, txHash common.Hash, txResult *swisstroniktypes.TxResult) error {
bz := codec.MustMarshal(txResult)
if err := batch.Set(TxHashKey(txHash), bz); err != nil {
return errorsmod.Wrap(err, "set tx-hash key")
Expand Down
4 changes: 2 additions & 2 deletions indexer/kv_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"swisstronik/tests"
"swisstronik/x/evm/types"

ethermint "swisstronik/types"
swisstroniktypes "swisstronik/types"

tmlog "cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -185,6 +185,6 @@ func TestKVIndexer(t *testing.T) {
}

// MakeEncodingConfig creates the EncodingConfig
func MakeEncodingConfig() ethermint.EncodingConfig {
func MakeEncodingConfig() swisstroniktypes.EncodingConfig {
return evmenc.MakeConfig()
}
Loading

0 comments on commit da45a12

Please sign in to comment.