Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: support ethermint ExtensionOptionDynamicFeeTx msg type #750

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions usecase/command/create_msg_extension_option_dynamic_fee_tx..go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package command
vincentysc marked this conversation as resolved.
Show resolved Hide resolved

import (
entity_event "github.com/crypto-com/chain-indexing/entity/event"
"github.com/crypto-com/chain-indexing/usecase/event"
"github.com/crypto-com/chain-indexing/usecase/model"
)

type CreateMsgExtensionOptionDynamicFeeTx struct {
msgCommonParams event.MsgCommonParams
params model.MsgDynamicFeeTxParams
}

func NewCreateMsgExtensionOptionDynamicFeeTxTx(
msgCommonParams event.MsgCommonParams,
params model.MsgDynamicFeeTxParams,
) *CreateMsgExtensionOptionDynamicFeeTx {
return &CreateMsgExtensionOptionDynamicFeeTx{
msgCommonParams,
params,
}
}

func (*CreateMsgExtensionOptionDynamicFeeTx) Name() string {
return "/ethermint.types.v1.DynamicFeeTx.Create"
}

func (*CreateMsgExtensionOptionDynamicFeeTx) Version() int {
return 1
}

func (cmd *CreateMsgExtensionOptionDynamicFeeTx) Exec() (entity_event.Event, error) {
event := event.NewMsgExtensionOptionDynamicFeeTx(cmd.msgCommonParams, cmd.params)
return event, nil
}
62 changes: 62 additions & 0 deletions usecase/event/msg_extension_option_dynamic_fee_tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package event

import (
"bytes"

"github.com/crypto-com/chain-indexing/usecase/model"

entity_event "github.com/crypto-com/chain-indexing/entity/event"
jsoniter "github.com/json-iterator/go"
"github.com/luci/go-render/render"
)

const MSG_EXTENSION_OPTION_DYNAMIC_FEE_TX = "/ethermint.types.v1.DynamicFeeTx"
const MSG_EXTENSION_OPTION_DYNAMIC_FEE_TX_CREATED = "/ethermint.types.v1.DynamicFeeTx.Created"
const MSG_EXTENSION_OPTION_DYNAMIC_FEE_TX_FAILED = "/ethermint.types.v1.DynamicFeeTx.Failed"

type MsgExtensionOptionDynamicFeeTx struct {
MsgBase

Params model.MsgDynamicFeeTxParams `json:"params"`
}

func NewMsgExtensionOptionDynamicFeeTx(
msgCommonParams MsgCommonParams,
params model.MsgDynamicFeeTxParams,
) *MsgExtensionOptionDynamicFeeTx {
return &MsgExtensionOptionDynamicFeeTx{
NewMsgBase(MsgBaseParams{
MsgName: MSG_ETHEREUM_TX,
Version: 1,
MsgCommonParams: msgCommonParams,
}),

params,
}
}

// ToJSON encodes the event into JSON string payload
func (event *MsgExtensionOptionDynamicFeeTx) ToJSON() (string, error) {
encoded, err := jsoniter.Marshal(event)
if err != nil {
return "", err
}

return string(encoded), nil
}

func (event *MsgExtensionOptionDynamicFeeTx) String() string {
return render.Render(event)
}

func DecodeMsgExtensionOptionDynamicFeeTx(encoded []byte) (entity_event.Event, error) {
jsonDecoder := jsoniter.NewDecoder(bytes.NewReader(encoded))
jsonDecoder.DisallowUnknownFields()

var event *MsgExtensionOptionDynamicFeeTx
if err := jsonDecoder.Decode(&event); err != nil {
return nil, err
}

return event, nil
}
26 changes: 26 additions & 0 deletions usecase/model/msg_ethereum_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,29 @@ type LegacyTx struct {
R string `mapstructure:"r" json:"r"`
S string `mapstructure:"s" json:"s"`
}

type MsgDynamicFeeTxParams struct {
RawDynamicFeeTx
}
type RawDynamicFeeTx struct {
Type string `mapstructure:"@type" json:"@type"`
Size int `mapstructure:"size" json:"size"`
// FIXME: https://github.com/crypto-com/chain-indexing/issues/730
Data DynamicFeeTx `mapstructure:"data" json:"data"`
From string `mapstructure:"from" json:"from"`
Hash string `mapstructure:"hash" json:"hash"`
}
type DynamicFeeTx struct {
Type string `mapstructure:"@type" json:"@type"`
ChainId string `mapstructure:"chain_id" json:"chainId"`
Nonce string `mapstructure:"nonce" json:"nonce"`
GasTipCap string `mapstructure:"gas_tip_cap" json:"gasTipCap"`
GasFeeCap string `mapstructure:"Gas_fee_cap" json:"gasFeeCap"`
Gas string `mapstructure:"gas" json:"gas"`
To string `mapstructure:"to" json:"to"`
Value string `mapstructure:"value" json:"value"`
Data string `mapstructure:"data" json:"data"`
V string `mapstructure:"v" json:"v"`
R string `mapstructure:"r" json:"r"`
S string `mapstructure:"s" json:"s"`
}
67 changes: 66 additions & 1 deletion usecase/parser/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func ParseBlockTxsMsgToCommands(
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount",

// ethermint evm
"/ethermint.evm.v1.MsgEthereumTx":
"/ethermint.evm.v1.MsgEthereumTx",
"/ethermint.types.v1.DynamicFeeTx":
parser := parserManager.GetParser(utils.CosmosParserKey(msgType.(string)), utils.ParserBlockHeight(blockHeight))

msgCommands, possibleSignerAddresses = parser(utils.CosmosParserParams{
Expand Down Expand Up @@ -2133,6 +2134,9 @@ func ParseMsgEthereumTx(
panic(fmt.Errorf("error decoding RawMsgEthereumTx: %v", err))
}

data := parserParams.Msg["data"].(map[string]interface{})
fmt.Println("===> ", data["@type"])
vincentysc marked this conversation as resolved.
Show resolved Hide resolved

if !parserParams.MsgCommonParams.TxSuccess {
// FIXME: https://github.com/crypto-com/chain-indexing/issues/730
msgEthereumTxParams := model.MsgEthereumTxParams{
Expand Down Expand Up @@ -2167,3 +2171,64 @@ func ParseMsgEthereumTx(
msgEthereumTxParams,
)}, possibleSignerAddresses
}

func ParseExtensionOptionDynamicFeeTx(
parserParams utils.CosmosParserParams,
) ([]command.Command, []string) {
var rawMsg model.RawDynamicFeeTx
decoderConfig := &mapstructure.DecoderConfig{
WeaklyTypedInput: true,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToTimeHookFunc(time.RFC3339),
mapstructure_utils.StringToDurationHookFunc(),
mapstructure_utils.StringToByteSliceHookFunc(),
),
Result: &rawMsg,
}
decoder, decoderErr := mapstructure.NewDecoder(decoderConfig)

if decoderErr != nil {
panic(fmt.Errorf("error creating RawMsgEthereumTx decoder: %v", decoderErr))
vincentysc marked this conversation as resolved.
Show resolved Hide resolved
}
if err := decoder.Decode(parserParams.Msg); err != nil {
panic(fmt.Errorf("error decoding RawMsgEthereumTx: %v", err))
vincentysc marked this conversation as resolved.
Show resolved Hide resolved
}
// fmt.Println("===> ", parserParams.Msg["data"])
vincentysc marked this conversation as resolved.
Show resolved Hide resolved
data := parserParams.Msg["data"].(map[string]interface{})
fmt.Println("===> ", data["@type"])
vincentysc marked this conversation as resolved.
Show resolved Hide resolved

if !parserParams.MsgCommonParams.TxSuccess {
// FIXME: https://github.com/crypto-com/chain-indexing/issues/730
msgDynamicFeeTxParams := model.MsgDynamicFeeTxParams{
RawDynamicFeeTx: rawMsg,
}

// Getting possible signer address from Msg
var possibleSignerAddresses []string
// FIXME: https://github.com/crypto-com/chain-indexing/issues/729
// possibleSignerAddresses = append(possibleSignerAddresses, msgDynamicFeeTxParams.From)

return []command.Command{command_usecase.NewCreateMsgExtensionOptionDynamicFeeTxTx(
parserParams.MsgCommonParams,

msgDynamicFeeTxParams,
)}, possibleSignerAddresses
}

// FIXME: https://github.com/crypto-com/chain-indexing/issues/730
msgDynamicFeeTxParams := model.MsgDynamicFeeTxParams{
RawDynamicFeeTx: rawMsg,
}

// Getting possible signer address from Msg
var possibleSignerAddresses []string
// FIXME: https://github.com/crypto-com/chain-indexing/issues/729
// possibleSignerAddresses = append(possibleSignerAddresses, msgDynamicFeeTxParams.From)

return []command.Command{command_usecase.NewCreateMsgExtensionOptionDynamicFeeTxTx(
parserParams.MsgCommonParams,

msgDynamicFeeTxParams,
)}, possibleSignerAddresses
}
1 change: 0 additions & 1 deletion usecase/parser/msg_ethereum_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var _ = Describe("ParseMsgCommands", func() {
},
model.MsgEthereumTxParams{
RawMsgEthereumTx: model.RawMsgEthereumTx{

Type: "/ethermint.evm.v1.MsgEthereumTx",
Size: 208,
Data: model.LegacyTx{
Expand Down
75 changes: 75 additions & 0 deletions usecase/parser/msg_extension_option_dynamic_fee_tx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parser_test

import (
"github.com/crypto-com/chain-indexing/usecase/model"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/crypto-com/chain-indexing/entity/command"
command_usecase "github.com/crypto-com/chain-indexing/usecase/command"
"github.com/crypto-com/chain-indexing/usecase/event"
"github.com/crypto-com/chain-indexing/usecase/parser"
usecase_parser_test "github.com/crypto-com/chain-indexing/usecase/parser/test"
)

var _ = Describe("ParseMsgCommands", func() {
Describe("ExtensionOptionDynamicFeeTx", func() {
It("should parse Msg commands when there is ethermint.ExtensionOptionDynamicFeeTx in the transaction", func() {
block, _ := mustParseBlockResp(usecase_parser_test.TX_MSG_EXTENSION_OPTION_DYNAMIC_FEE_TX_BLOCK_RESP)
blockResults := mustParseBlockResultsResp(
usecase_parser_test.TX_MSG_EXTENSION_OPTION_DYNAMIC_FEE_TX_BLOCK_RESULTS_RESP,
)

tx := mustParseTxsResp(usecase_parser_test.TX_MSG_EXTENSION_OPTION_DYNAMIC_FEE_TXS_RESP)
txs := []model.Tx{*tx}

accountAddressPrefix := "tcro"
bondingDenom := "basetcro"

pm := usecase_parser_test.InitParserManager()

cmds, possibleSignerAddresses, err := parser.ParseBlockTxsMsgToCommands(
pm,
block.Height,
blockResults,
txs,
accountAddressPrefix,
bondingDenom,
)
Expect(err).To(BeNil())
Expect(cmds).To(HaveLen(1))
Expect(cmds).To(Equal([]command.Command{command_usecase.NewCreateMsgExtensionOptionDynamicFeeTxTx(
event.MsgCommonParams{
BlockHeight: int64(5168311),
TxHash: "3F1B98E6A43A3666699CA28DA2A0872E1478E092F7EC3FCF8A94202BB8B330D2",
TxSuccess: true,
MsgIndex: 0,
},
model.MsgDynamicFeeTxParams{
RawDynamicFeeTx: model.RawDynamicFeeTx{
Type: "/ethermint.evm.v1.MsgEthereumTx",
Size: 0,
Data: model.DynamicFeeTx{
Type: "/ethermint.evm.v1.DynamicFeeTx",
ChainId: "338",
Nonce: "115",
GasTipCap: "5000000000000",
GasFeeCap: "5000000000000",
Gas: "48834",
To: "0x904Bd5a5AAC0B9d88A0D47864724218986Ad4a3a",
Value: "0",
Data: "CV6nswAAAAAAAAAAAAAAAPVk7wA0u3182EQSJ14eUTZNTXc0//////////////////////////////////////////8=",
V: "",
R: "HHigR02IN48gvEM991C/MOCmbVfOw9Sj804IhtI5z2Q=",
S: "SspHmiOAoM4bQdvAig9I8PQzLv5GTzElhcROppO0WpU=",
},
From: "",
Hash: "0xd56db65672a48daaf14f743f53c316a3eba130d72beb7034296f4ea3f7e49b53",
},
},
)}))
var emptyAddress []string
Expect(possibleSignerAddresses).To(Equal(emptyAddress))
})
})
})
4 changes: 1 addition & 3 deletions usecase/parser/msg_fund_community_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ var _ = Describe("ParseMsgCommands", func() {
Describe("MsgFundCommunityPool", func() {
It("should parse Msg commands when there is distribution.MsgFundCommunityPool in the transaction", func() {
block, _ := mustParseBlockResp(usecase_parser_test.TX_MSG_FUND_COMMUNITY_POOL_BLOCK_RESP)
blockResults := mustParseBlockResultsResp(
usecase_parser_test.TX_MSG_FUND_COMMUNITY_POOL_BLOCK_RESULTS_RESP,
)
blockResults := mustParseBlockResultsResp(usecase_parser_test.TX_MSG_FUND_COMMUNITY_POOL_BLOCK_RESULTS_RESP)

tx := mustParseTxsResp(usecase_parser_test.TX_MSG_FUND_COMMUNITY_POOL_TXS_RESP)
txs := []model.Tx{*tx}
Expand Down
1 change: 1 addition & 0 deletions usecase/parser/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func InitParsers(manager *utils.CosmosParserManager) {

// ethermint evm
manager.RegisterParser("/ethermint.evm.v1.MsgEthereumTx", BEGIN_BLOCK_HEIGHT, ParseMsgEthereumTx)
manager.RegisterParser("/ethermint.types.v1.DynamicFeeTx", BEGIN_BLOCK_HEIGHT, ParseExtensionOptionDynamicFeeTx)
}

func RegisterBreakingVersionParsers(manager *utils.CosmosParserManager) {
Expand Down
Loading