forked from cerc-io/laconicd-deprecated
rpc: implement eth_getPendingTransactions (#259)
* Implement `eth_getPendingTransactions` Closes #244 * refactor repeatitive code * Update ethereum/rpc/namespaces/eth/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/namespaces/eth/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/namespaces/eth/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/rpc/namespaces/eth/api.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * test UnwrapEthereumMsg Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
Federico Kunze Küllmer
parent
8d51a70d6d
commit
1a48e09e78
@@ -37,6 +37,7 @@ func NewTx(
|
||||
gasLimit uint64, gasPrice *big.Int, input []byte, accesses *ethtypes.AccessList,
|
||||
) *MsgEthereumTx {
|
||||
return newMsgEthereumTx(chainID, nonce, to, amount, gasLimit, gasPrice, input, accesses)
|
||||
|
||||
}
|
||||
|
||||
// NewTxContract returns a reference to a new Ethereum transaction
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
log "github.com/xlab/suplog"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
@@ -50,3 +52,20 @@ func DecodeTransactionLogs(data []byte) (TransactionLogs, error) {
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// UnwrapEthereumMsg extract MsgEthereumTx from wrapping sdk.Tx
|
||||
func UnwrapEthereumMsg(tx *sdk.Tx) (*MsgEthereumTx, error) {
|
||||
if tx == nil {
|
||||
return nil, fmt.Errorf("invalid tx: nil")
|
||||
}
|
||||
|
||||
if len((*tx).GetMsgs()) != 1 {
|
||||
return nil, fmt.Errorf("invalid tx type: %T", tx)
|
||||
}
|
||||
msg, ok := (*tx).GetMsgs()[0].(*MsgEthereumTx)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid tx type: %T", tx)
|
||||
}
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package types
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
"github.com/tharsis/ethermint/app"
|
||||
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
|
||||
"github.com/tharsis/ethermint/encoding"
|
||||
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -27,9 +33,9 @@ func GenerateEthAddress() ethcmn.Address {
|
||||
func TestEvmDataEncoding(t *testing.T) {
|
||||
ret := []byte{0x5, 0x8}
|
||||
|
||||
data := &MsgEthereumTxResponse{
|
||||
data := &evmtypes.MsgEthereumTxResponse{
|
||||
Hash: common.BytesToHash([]byte("hash")).String(),
|
||||
Logs: []*Log{{
|
||||
Logs: []*evmtypes.Log{{
|
||||
Data: []byte{1, 2, 3, 4},
|
||||
BlockNumber: 17,
|
||||
}},
|
||||
@@ -40,15 +46,36 @@ func TestEvmDataEncoding(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
txData := &sdk.TxMsgData{
|
||||
Data: []*sdk.MsgData{{MsgType: TypeMsgEthereumTx, Data: enc}},
|
||||
Data: []*sdk.MsgData{{MsgType: evmtypes.TypeMsgEthereumTx, Data: enc}},
|
||||
}
|
||||
|
||||
txDataBz, err := proto.Marshal(txData)
|
||||
require.NoError(t, err)
|
||||
|
||||
res, err := DecodeTxResponse(txDataBz)
|
||||
res, err := evmtypes.DecodeTxResponse(txDataBz)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, res)
|
||||
require.Equal(t, data.Logs, res.Logs)
|
||||
require.Equal(t, ret, res.Ret)
|
||||
}
|
||||
|
||||
func TestUnwrapEthererumMsg(t *testing.T) {
|
||||
_, err := evmtypes.UnwrapEthereumMsg(nil)
|
||||
require.NotNil(t, err)
|
||||
|
||||
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
|
||||
clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
||||
builder, _ := clientCtx.TxConfig.NewTxBuilder().(authtx.ExtensionOptionsTxBuilder)
|
||||
|
||||
tx := builder.GetTx().(sdk.Tx)
|
||||
_, err = evmtypes.UnwrapEthereumMsg(&tx)
|
||||
require.NotNil(t, err)
|
||||
|
||||
msg := evmtypes.NewTx(big.NewInt(1), 0, &common.Address{}, big.NewInt(0), 0, big.NewInt(0), []byte{}, nil)
|
||||
err = builder.SetMsgs(msg)
|
||||
|
||||
tx = builder.GetTx().(sdk.Tx)
|
||||
msg_, err := evmtypes.UnwrapEthereumMsg(&tx)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, msg_, msg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user