forked from cerc-io/laconicd-deprecated
EVM Transaction handler and contract creation (#96)
* WIP implementing state transition function * Error handling and application setup fix * Fixed error comment * Allow creation of state objects with a BaseAccount * Fixed parameters and finalise state after transaction * updated transaction signing and cli signature * Set up consistent account encoding and decoding * Update txbuilder to get sequence before generating eth tx * Added create functionality to the CLI command * Remove need to copy over context for statedb interactions * Updated account retriever * Cleaned up handler code and updated TODO * Make recoverEthSig private again * Add error check for committing to kv store * Remove commented out code * Update evm chain config for state transition * Add time in context for dapps
This commit is contained in:
+16
-10
@@ -88,9 +88,9 @@ func GetCmdGenTx(cdc *codec.Codec) *cobra.Command {
|
||||
// GetCmdGenTx generates an ethereum transaction
|
||||
func GetCmdGenETHTx(cdc *codec.Codec) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "generate-eth-tx [nonce] [ethaddress] [amount] [gaslimit] [gasprice] [payload]",
|
||||
Short: "geberate and broadcast an Ethereum tx",
|
||||
Args: cobra.ExactArgs(6),
|
||||
Use: "generate-eth-tx [amount] [gaslimit] [gasprice] [payload] [<ethereum-address>]",
|
||||
Short: "generate and broadcast an Ethereum tx. If address is not specified, contract will be created",
|
||||
Args: cobra.RangeArgs(4, 5),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := emintUtils.NewETHCLIContext().WithCodec(cdc)
|
||||
|
||||
@@ -101,35 +101,41 @@ func GetCmdGenETHTx(cdc *codec.Codec) *cobra.Command {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
nonce, err := strconv.ParseUint(args[0], 0, 64)
|
||||
coins, err := sdk.ParseCoins(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
coins, err := sdk.ParseCoins(args[2])
|
||||
gasLimit, err := strconv.ParseUint(args[1], 0, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gasLimit, err := strconv.ParseUint(args[3], 0, 64)
|
||||
gasPrice, err := strconv.ParseUint(args[2], 0, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gasPrice, err := strconv.ParseUint(args[4], 0, 64)
|
||||
payload := args[3]
|
||||
|
||||
txBldr, err = emintUtils.PrepareTxBuilder(txBldr, cliCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
payload := args[5]
|
||||
var tx *types.EthereumTxMsg
|
||||
if len(args) == 5 {
|
||||
tx = types.NewEthereumTxMsg(txBldr.Sequence(), ethcmn.HexToAddress(args[4]), big.NewInt(coins.AmountOf(emintTypes.DenomDefault).Int64()), gasLimit, new(big.Int).SetUint64(gasPrice), []byte(payload))
|
||||
} else {
|
||||
tx = types.NewEthereumTxMsgContract(txBldr.Sequence(), big.NewInt(coins.AmountOf(emintTypes.DenomDefault).Int64()), gasLimit, new(big.Int).SetUint64(gasPrice), []byte(payload))
|
||||
}
|
||||
|
||||
tx := types.NewEthereumTxMsg(nonce, ethcmn.HexToAddress(args[1]), big.NewInt(coins.AmountOf(emintTypes.DenomDefault).Int64()), gasLimit, new(big.Int).SetUint64(gasPrice), []byte(payload))
|
||||
err = tx.ValidateBasic()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return emintUtils.BroadcastETHTx(cliCtx, txBldr.WithSequence(nonce).WithKeybase(kb), tx)
|
||||
return emintUtils.BroadcastETHTx(cliCtx, txBldr.WithKeybase(kb), tx)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,6 @@ func GenerateOrBroadcastETHMsgs(cliCtx context.CLIContext, txBldr authtypes.TxBu
|
||||
|
||||
// BroadcastETHTx Broadcasts an Ethereum Tx not wrapped in a Std Tx
|
||||
func BroadcastETHTx(cliCtx context.CLIContext, txBldr authtypes.TxBuilder, tx *evmtypes.EthereumTxMsg) error {
|
||||
txBldr, err := utils.PrepareTxBuilder(txBldr, cliCtx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fromName := cliCtx.GetFromName()
|
||||
|
||||
@@ -346,3 +342,34 @@ func getFromFields(from string, genOnly bool) (sdk.AccAddress, string, error) {
|
||||
|
||||
return info.GetAddress(), info.GetName(), nil
|
||||
}
|
||||
|
||||
// * Overriden function from cosmos-sdk/auth/client/utils/tx.go
|
||||
// PrepareTxBuilder populates a TxBuilder in preparation for the build of a Tx.
|
||||
func PrepareTxBuilder(txBldr authtypes.TxBuilder, cliCtx context.CLIContext) (authtypes.TxBuilder, error) {
|
||||
from := cliCtx.GetFromAddress()
|
||||
|
||||
// * Function is needed to override to use different account getter (to not use static codec)
|
||||
accGetter := emint.NewAccountRetriever(cliCtx, cliCtx.Codec)
|
||||
if err := accGetter.EnsureExists(from); err != nil {
|
||||
return txBldr, err
|
||||
}
|
||||
|
||||
txbldrAccNum, txbldrAccSeq := txBldr.AccountNumber(), txBldr.Sequence()
|
||||
// TODO: (ref #1903) Allow for user supplied account number without
|
||||
// automatically doing a manual lookup.
|
||||
if txbldrAccNum == 0 || txbldrAccSeq == 0 {
|
||||
num, seq, err := accGetter.GetAccountNumberSequence(from)
|
||||
if err != nil {
|
||||
return txBldr, err
|
||||
}
|
||||
|
||||
if txbldrAccNum == 0 {
|
||||
txBldr = txBldr.WithAccountNumber(num)
|
||||
}
|
||||
if txbldrAccSeq == 0 {
|
||||
txBldr = txBldr.WithSequence(seq)
|
||||
}
|
||||
}
|
||||
|
||||
return txBldr, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user