This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stargate: fix ethereum transaction (#604)
* bump cosmos-sdk dependency * fix tx encoding * fix eth tx * update cosmos-sdk to latest version * use cryptotypes.PrivKey
- Loading branch information
1 parent
189d6c7
commit 4ee7eea
Showing
33 changed files
with
265 additions
and
118 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
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 |
---|---|---|
@@ -1,17 +1,72 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
amino "github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/simapp/params" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
|
||
"github.com/cosmos/ethermint/codec" | ||
evmtypes "github.com/cosmos/ethermint/x/evm/types" | ||
) | ||
|
||
// MakeEncodingConfig creates an EncodingConfig for testing | ||
func MakeEncodingConfig() params.EncodingConfig { | ||
encodingConfig := params.MakeTestEncodingConfig() | ||
cdc := amino.NewLegacyAmino() | ||
interfaceRegistry := types.NewInterfaceRegistry() | ||
marshaler := amino.NewProtoCodec(interfaceRegistry) | ||
|
||
encodingConfig := params.EncodingConfig{ | ||
InterfaceRegistry: interfaceRegistry, | ||
Marshaler: marshaler, | ||
TxConfig: NewTxConfig(marshaler), | ||
Amino: cdc, | ||
} | ||
|
||
codec.RegisterLegacyAminoCodec(encodingConfig.Amino) | ||
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino) | ||
codec.RegisterInterfaces(encodingConfig.InterfaceRegistry) | ||
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) | ||
return encodingConfig | ||
} | ||
|
||
type txConfig struct { | ||
cdc amino.ProtoCodecMarshaler | ||
client.TxConfig | ||
} | ||
|
||
// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The | ||
// first enabled sign mode will become the default sign mode. | ||
func NewTxConfig(marshaler amino.ProtoCodecMarshaler) client.TxConfig { | ||
return &txConfig{ | ||
marshaler, | ||
tx.NewTxConfig(marshaler, tx.DefaultSignModes), | ||
} | ||
} | ||
|
||
// TxEncoder overwites sdk.TxEncoder to support MsgEthereumTx | ||
func (g txConfig) TxEncoder() sdk.TxEncoder { | ||
return func(tx sdk.Tx) ([]byte, error) { | ||
ethtx, ok := tx.(*evmtypes.MsgEthereumTx) | ||
if ok { | ||
return g.cdc.MarshalBinaryBare(ethtx) | ||
} | ||
return g.TxConfig.TxEncoder()(tx) | ||
} | ||
} | ||
|
||
// TxDecoder overwites sdk.TxDecoder to support MsgEthereumTx | ||
func (g txConfig) TxDecoder() sdk.TxDecoder { | ||
return func(txBytes []byte) (sdk.Tx, error) { | ||
var ethtx evmtypes.MsgEthereumTx | ||
|
||
err := g.cdc.UnmarshalBinaryBare(txBytes, ðtx) | ||
if err == nil { | ||
return ðtx, nil | ||
} | ||
|
||
return g.TxConfig.TxDecoder()(txBytes) | ||
} | ||
} |
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
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
Oops, something went wrong.