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 all 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_access_list_tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package command

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 CreateMsgAccessListTx struct {
msgCommonParams event.MsgCommonParams
params model.EthermintAccessListTxParams
}

func NewCreateMsgAccessListTx(
msgCommonParams event.MsgCommonParams,
params model.EthermintAccessListTxParams,
) *CreateMsgAccessListTx {
return &CreateMsgAccessListTx{
msgCommonParams,
params,
}
}

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

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

func (cmd *CreateMsgAccessListTx) Exec() (entity_event.Event, error) {
event := event.NewEthermintAccessListTx(cmd.msgCommonParams, cmd.params)
return event, nil
}
22 changes: 11 additions & 11 deletions usecase/command/create_msg_ethereum_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import (
"github.com/crypto-com/chain-indexing/usecase/model"
)

type CreateMsgEthereumTx struct {
type CreateLegacyTx struct {
msgCommonParams event.MsgCommonParams
params model.MsgEthereumTxParams
params model.EthermintLegacyTxParams
}

func NewCreateMsgEthereumTx(
func NewCreateLegacyTx(
msgCommonParams event.MsgCommonParams,
params model.MsgEthereumTxParams,
) *CreateMsgEthereumTx {
return &CreateMsgEthereumTx{
params model.EthermintLegacyTxParams,
) *CreateLegacyTx {
return &CreateLegacyTx{
msgCommonParams,
params,
}
}

func (*CreateMsgEthereumTx) Name() string {
return "/ethermint.evm.v1.MsgEthereumTx.Create"
func (*CreateLegacyTx) Name() string {
return "/ethermint.evm.v1.LegacyTx.Create"
}

func (*CreateMsgEthereumTx) Version() int {
func (*CreateLegacyTx) Version() int {
return 1
}

func (cmd *CreateMsgEthereumTx) Exec() (entity_event.Event, error) {
event := event.NewMsgEthereumTx(cmd.msgCommonParams, cmd.params)
func (cmd *CreateLegacyTx) Exec() (entity_event.Event, error) {
event := event.NewEthermintLegacyTx(cmd.msgCommonParams, cmd.params)
return event, nil
}
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

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.EthermintDynamicFeeTxParams
}

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

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

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

func (cmd *CreateMsgExtensionOptionDynamicFeeTx) Exec() (entity_event.Event, error) {
event := event.NewEthermintExtensionOptionDynamicFeeTx(cmd.msgCommonParams, cmd.params)
return event, nil
}
62 changes: 62 additions & 0 deletions usecase/event/ethermint_access_list_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 ACCESS_LIST_TX = "/ethermint.evm.v1.AccessListTx"
const ACCESS_LIST_TX_CREATED = "/ethermint.evm.v1.AccessListTx.Created"
const ACCESS_LIST_TX_FAILED = "/ethermint.evm.v1.AccessListTx.Failed"

type EthermintAccessListTx struct {
MsgBase

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

func NewEthermintAccessListTx(
msgCommonParams MsgCommonParams,
params model.EthermintAccessListTxParams,
) *EthermintAccessListTx {
return &EthermintAccessListTx{
NewMsgBase(MsgBaseParams{
MsgName: ACCESS_LIST_TX,
Version: 1,
MsgCommonParams: msgCommonParams,
}),

params,
}
}

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

return string(encoded), nil
}

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

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

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

return event, nil
}
62 changes: 62 additions & 0 deletions usecase/event/ethermint_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 DYNAMIC_FEE_TX = "/ethermint.evm.v1.DynamicFeeTx"
const DYNAMIC_FEE_TX_CREATED = "/ethermint.evm.v1.DynamicFeeTx.Created"
const DYNAMIC_FEE_TX_FAILED = "/ethermint.evm.v1.DynamicFeeTx.Failed"

type EthermintExtensionOptionDynamicFeeTx struct {
MsgBase

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

func NewEthermintExtensionOptionDynamicFeeTx(
msgCommonParams MsgCommonParams,
params model.EthermintDynamicFeeTxParams,
) *EthermintExtensionOptionDynamicFeeTx {
return &EthermintExtensionOptionDynamicFeeTx{
NewMsgBase(MsgBaseParams{
MsgName: DYNAMIC_FEE_TX,
Version: 1,
MsgCommonParams: msgCommonParams,
}),

params,
}
}

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

return string(encoded), nil
}

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

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

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

return event, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import (
"github.com/luci/go-render/render"
)

const MSG_ETHEREUM_TX = "/ethermint.evm.v1.MsgEthereumTx"
const MSG_ETHEREUM_TX_CREATED = "/ethermint.evm.v1.MsgEthereumTx.Created"
const MSG_ETHEREUM_TX_FAILED = "/ethermint.evm.v1.MsgEthereumTx.Failed"
const LEGACY_TX = "/ethermint.evm.v1.LegacyTx"
const LEGACY_TX_CREATED = "/ethermint.evm.v1.LegacyTx.Created"
const LEGACY_TX_FAILED = "/ethermint.evm.v1.LegacyTx.Failed"

type MsgEthereumTx struct {
type EthermintLegacyTx struct {
MsgBase

Params model.MsgEthereumTxParams `json:"params"`
Params model.EthermintLegacyTxParams `json:"params"`
}

func NewMsgEthereumTx(
func NewEthermintLegacyTx(
msgCommonParams MsgCommonParams,
params model.MsgEthereumTxParams,
) *MsgEthereumTx {
return &MsgEthereumTx{
params model.EthermintLegacyTxParams,
) *EthermintLegacyTx {
return &EthermintLegacyTx{
NewMsgBase(MsgBaseParams{
MsgName: MSG_ETHEREUM_TX,
MsgName: LEGACY_TX,
Version: 1,
MsgCommonParams: msgCommonParams,
}),
Expand All @@ -36,7 +36,7 @@ func NewMsgEthereumTx(
}

// ToJSON encodes the event into JSON string payload
func (event *MsgEthereumTx) ToJSON() (string, error) {
func (event *EthermintLegacyTx) ToJSON() (string, error) {
encoded, err := jsoniter.Marshal(event)
if err != nil {
return "", err
Expand All @@ -45,15 +45,15 @@ func (event *MsgEthereumTx) ToJSON() (string, error) {
return string(encoded), nil
}

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

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

var event *MsgEthereumTx
var event *EthermintLegacyTx
if err := jsonDecoder.Decode(&event); err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions usecase/event/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ func RegisterEvents(registry *event.Registry) {
registry.Register(CRONOS_SEND_TO_IBC_CREATED, 1, DecodeCronosSendToIBCCreated)

// Ethermint tx
registry.Register(MSG_ETHEREUM_TX_CREATED, 1, DecodeMsgEthereumTx)
registry.Register(MSG_ETHEREUM_TX_FAILED, 1, DecodeMsgEthereumTx)
registry.Register(LEGACY_TX_CREATED, 1, DecodeEthermintLegacyTx)
registry.Register(LEGACY_TX_FAILED, 1, DecodeEthermintLegacyTx)
}
20 changes: 10 additions & 10 deletions usecase/event/msg_ethereum_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var _ = Describe("Event", func() {
anyTxHash := "2678437368AFC7E0E6D891D858F17B9C05CFEE850A786592A11992813D6A89FD"
anyMsgIndex := 2

anyParams := model.MsgEthereumTxParams{}
anyParams := model.EthermintLegacyTxParams{}

event := event_usecase.NewMsgEthereumTx(event_usecase.MsgCommonParams{
event := event_usecase.NewEthermintLegacyTx(event_usecase.MsgCommonParams{
BlockHeight: anyHeight,
TxHash: anyTxHash,
TxSuccess: true,
Expand All @@ -32,12 +32,12 @@ var _ = Describe("Event", func() {
Expect(err).To(BeNil())

decodedEvent, err := registry.DecodeByType(
event_usecase.MSG_ETHEREUM_TX_CREATED, 1, []byte(encoded),
event_usecase.LEGACY_TX_CREATED, 1, []byte(encoded),
)
Expect(err).To(BeNil())
Expect(decodedEvent).To(Equal(event))
typedEvent, _ := decodedEvent.(*event_usecase.MsgEthereumTx)
Expect(typedEvent.Name()).To(Equal(event_usecase.MSG_ETHEREUM_TX_CREATED))
typedEvent, _ := decodedEvent.(*event_usecase.EthermintLegacyTx)
Expect(typedEvent.Name()).To(Equal(event_usecase.LEGACY_TX_CREATED))
Expect(typedEvent.Version()).To(Equal(1))
Expect(typedEvent.TxSuccess()).To(BeTrue())
Expect(typedEvent.TxHash()).To(Equal(anyTxHash))
Expand All @@ -51,9 +51,9 @@ var _ = Describe("Event", func() {
anyTxHash := "2678437368AFC7E0E6D891D858F17B9C05CFEE850A786592A11992813D6A89FD"
anyMsgIndex := 2

anyParams := model.MsgEthereumTxParams{}
anyParams := model.EthermintLegacyTxParams{}

event := event_usecase.NewMsgEthereumTx(event_usecase.MsgCommonParams{
event := event_usecase.NewEthermintLegacyTx(event_usecase.MsgCommonParams{
BlockHeight: anyHeight,
TxHash: anyTxHash,
TxSuccess: false,
Expand All @@ -64,12 +64,12 @@ var _ = Describe("Event", func() {
Expect(err).To(BeNil())

decodedEvent, err := registry.DecodeByType(
event_usecase.MSG_ETHEREUM_TX_FAILED, 1, []byte(encoded),
event_usecase.LEGACY_TX_FAILED, 1, []byte(encoded),
)
Expect(err).To(BeNil())
Expect(decodedEvent).To(Equal(event))
typedEvent, _ := decodedEvent.(*event_usecase.MsgEthereumTx)
Expect(typedEvent.Name()).To(Equal(event_usecase.MSG_ETHEREUM_TX_FAILED))
typedEvent, _ := decodedEvent.(*event_usecase.EthermintLegacyTx)
Expect(typedEvent.Name()).To(Equal(event_usecase.LEGACY_TX_FAILED))
Expect(typedEvent.Version()).To(Equal(1))
Expect(typedEvent.TxSuccess()).To(BeFalse())
Expect(typedEvent.TxHash()).To(Equal(anyTxHash))
Expand Down
6 changes: 4 additions & 2 deletions usecase/event/msgevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ var MSG_EVENTS = []string{
MSG_REVOKE_ALLOWANCE_FAILED,
MSG_CREATE_VESTING_ACCOUNT_CREATED,
MSG_CREATE_VESTING_ACCOUNT_FAILED,
MSG_ETHEREUM_TX_CREATED,
MSG_ETHEREUM_TX_FAILED,
LEGACY_TX_CREATED,
LEGACY_TX_FAILED,
DYNAMIC_FEE_TX_CREATED,
DYNAMIC_FEE_TX_FAILED,
}
Loading