Skip to content

Commit

Permalink
parse txs result events to log
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentysc committed Dec 3, 2024
1 parent f01e2f2 commit f53deea
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 2 deletions.
8 changes: 7 additions & 1 deletion usecase/parser/icaauth/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ func ParseMsgRegisterAccount(
msgRegisterAccountParams := make([]icaauth_model.MsgRegisterAccountParams, 0)

for _, event := range events {

var counterpartyChannelId string
if event.HasAttribute("counterparty_channel_id") {
counterpartyChannelId = event.MustGetAttributeByKey("counterparty_channel_id")
}

param := icaauth_model.MsgRegisterAccountParams{
MsgRegisterAccount: icaauth_model.MsgRegisterAccount{
Owner: msgRegisterAccount.Owner,
Expand All @@ -341,7 +347,7 @@ func ParseMsgRegisterAccount(
PortID: event.MustGetAttributeByKey("port_id"),
ChannelID: event.MustGetAttributeByKey("channel_id"),
CounterpartyPortID: event.MustGetAttributeByKey("counterparty_port_id"),
CounterpartyChannelID: event.MustGetAttributeByKey("counterparty_channel_id"),
CounterpartyChannelID: counterpartyChannelId,
}

isExisted := false
Expand Down
77 changes: 76 additions & 1 deletion usecase/parser/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,82 @@ func RegisterBreakingVersionParsers(manager *utils.CosmosParserManager) {
// cosmos sdk v0.42.7
manager.RegisterParser("/ibc.core.channel.v1.MsgRecvPacket", manager.GetCosmosV0_42_7BlockHeight(), V0_42_7_ibcmsg.ParseMsgRecvPacket)

// cronos v1.4.0
/*
Cronos v1.4.0
*/
manager.RegisterParser("/ethermint.evm.v1.MsgEthereumTx", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEthereumTx)

// cosmos bank
manager.RegisterParser("/cosmos.bank.v1beta1.MsgSend", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgSend))
manager.RegisterParser("/cosmos.bank.v1beta1.MsgMultiSend", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgMultiSend))
manager.RegisterParser("/cosmos.bank.v1beta1.MsgSetSendEnabled", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgSetSendEnabled))

// cosmos distribution
manager.RegisterParser("/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgSetWithdrawAddress))
manager.RegisterParser("/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgWithdrawDelegatorReward))
manager.RegisterParser("/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgWithdrawValidatorCommission))
manager.RegisterParser("/cosmos.distribution.v1beta1.MsgFundCommunityPool", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgFundCommunityPool))

// cosmos gov
manager.RegisterParser("/cosmos.gov.v1beta1.MsgSubmitProposal", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgSubmitProposal))
manager.RegisterParser("/cosmos.gov.v1beta1.MsgVote", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgVote))
manager.RegisterParser("/cosmos.gov.v1beta1.MsgDeposit", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgDeposit))

// cosmos gov v1
manager.RegisterParser("/cosmos.gov.v1.MsgDeposit", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(cosmos_gov_v1.ParseMsgDeposit))
manager.RegisterParser("/cosmos.gov.v1.MsgSubmitProposal", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(cosmos_gov_v1.ParseMsgSubmitProposal))
manager.RegisterParser("/cosmos.gov.v1.MsgVote", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(cosmos_gov_v1.ParseMsgVote))
manager.RegisterParser("/cosmos.gov.v1.MsgVoteWeighted", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(cosmos_gov_v1.ParseMsgVoteWeighted))

// cosmos staking
manager.RegisterParser("/cosmos.staking.v1beta1.MsgDelegate", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgDelegate))
manager.RegisterParser("/cosmos.staking.v1beta1.MsgUndelegate", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgUndelegate))
manager.RegisterParser("/cosmos.staking.v1beta1.MsgBeginRedelegate", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgBeginRedelegate))
manager.RegisterParser("/cosmos.staking.v1beta1.MsgCreateValidator", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgCreateValidator))
manager.RegisterParser("/cosmos.staking.v1beta1.MsgEditValidator", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgEditValidator))

// cosmos slashing
manager.RegisterParser("/cosmos.slashing.v1beta1.MsgUnjail", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgUnjail))

// cronos icaauth
manager.RegisterParser("/icaauth.v1.MsgRegisterAccount", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(icaauth.ParseMsgRegisterAccount))
manager.RegisterParser("/icaauth.v1.MsgSubmitTx", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(icaauth.ParseMsgSubmitTx))

// ibc core client
manager.RegisterParser("/ibc.core.client.v1.MsgCreateClient", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgCreateClient))
manager.RegisterParser("/ibc.core.client.v1.MsgUpdateClient", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgUpdateClient))

// ibc core connection
manager.RegisterParser("/ibc.core.connection.v1.MsgConnectionOpenInit", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgConnectionOpenInit))
manager.RegisterParser("/ibc.core.connection.v1.MsgConnectionOpenTry", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgConnectionOpenTry))
manager.RegisterParser("/ibc.core.connection.v1.MsgConnectionOpenAck", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgConnectionOpenAck))
manager.RegisterParser("/ibc.core.connection.v1.MsgConnectionOpenConfirm", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgConnectionOpenConfirm))

// ibc core channel
manager.RegisterParser("/ibc.core.channel.v1.MsgChannelOpenInit", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgChannelOpenInit))
manager.RegisterParser("/ibc.core.channel.v1.MsgChannelOpenTry", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgChannelOpenTry))
manager.RegisterParser("/ibc.core.channel.v1.MsgChannelOpenAck", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgChannelOpenAck))
manager.RegisterParser("/ibc.core.channel.v1.MsgChannelOpenConfirm", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgChannelOpenConfirm))
manager.RegisterParser("/ibc.core.channel.v1.MsgRecvPacket", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(V0_42_7_ibcmsg.ParseMsgRecvPacket))
manager.RegisterParser("/ibc.core.channel.v1.MsgAcknowledgement", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgAcknowledgement))
manager.RegisterParser("/ibc.core.channel.v1.MsgTimeout", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgTimeout))
manager.RegisterParser("/ibc.core.channel.v1.MsgTimeoutOnClose", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgTimeoutOnClose))
manager.RegisterParser("/ibc.core.channel.v1.MsgChannelCloseInit", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgChannelCloseInit))
manager.RegisterParser("/ibc.core.channel.v1.MsgChannelCloseConfirm", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgChannelCloseConfirm))

// ibc applications transfer
manager.RegisterParser("/ibc.applications.transfer.v1.MsgTransfer", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ibc.ParseMsgTransfer))

// cosmos authz
manager.RegisterParser("/cosmos.authz.v1beta1.MsgGrant", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgGrant))
manager.RegisterParser("/cosmos.authz.v1beta1.MsgRevoke", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgRevoke))
// FIXME: https://github.com/crypto-com/chain-indexing/issues/673
//manager.RegisterParser("/cosmos.authz.v1beta1.MsgExec", manager.GetCronosV1_4_0BlockHeight(), ParseMsgExec))

// cosmos feegrant
manager.RegisterParser("/cosmos.feegrant.v1beta1.MsgGrantAllowance", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgGrantAllowance))
manager.RegisterParser("/cosmos.feegrant.v1beta1.MsgRevokeAllowance", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgRevokeAllowance))

// cosmos vesting
manager.RegisterParser("/cosmos.vesting.v1beta1.MsgCreateVestingAccount", manager.GetCronosV1_4_0BlockHeight(), V1_4_0_cronos_msg.ParseMsgEventsToLog(ParseMsgCreateVestingAccount))
}
31 changes: 31 additions & 0 deletions usecase/parser/utils/txs_results_event.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package utils

import (
"fmt"
"strconv"

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

Expand Down Expand Up @@ -61,3 +64,31 @@ func (log *ParsedTxsResultsEvents) GetEventsByType(t string) []*ParsedTxsResultL

return logEvents
}

func (log *ParsedTxsResultsEvents) ParsedEventToTxsResultLog() []model.BlockResultsTxsResultLog {
logs := make([]model.BlockResultsTxsResultLog, 0)

for _, logEvent := range log.rawEvents {
logEvent := NewParsedTxsResultLogEvent(&logEvent)
msgIndex := logEvent.GetAttributeByKey("msg_index")
if msgIndex != nil {
i, err := strconv.Atoi(*msgIndex)
if err != nil || i < 0 {
panic(fmt.Sprintf("msg_index should be a number, got %s", *msgIndex))
}

if len(logs)-1 >= i {
logs[i].Events = append(logs[i].Events, logEvent.rawEvent)
} else {
logs = append(logs, model.BlockResultsTxsResultLog{
MsgIndex: i,
Events: []model.BlockResultsEvent{
logEvent.rawEvent,
},
})
}
}
}

return logs
}
24 changes: 24 additions & 0 deletions usecase/parser/v1_4_0_cronos/msg/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func ParseMsgEthereumTx(
var possibleSignerAddresses []string

events := utils.NewParsedTxsResultsEvents(parserParams.TxsResult.Events)
log := events.ParsedEventToTxsResultLog()
parserParams.TxsResult.Log = log

rawTxData, err := hex.DecodeString(rawMsg.Raw[2:]) // Remove hex prefix "0x..."
if err != nil {
Expand Down Expand Up @@ -295,3 +297,25 @@ func ParseMsgEthereumTx(
msgEthereumTxParams,
)), possibleSignerAddresses
}

func ParseMsgEventsToLog(
parser utils.CosmosParser,
) utils.CosmosParser {
return func(
parserParams utils.CosmosParserParams,
) ([]command.Command, []string) {
events := utils.NewParsedTxsResultsEvents(parserParams.TxsResult.Events)
log := events.ParsedEventToTxsResultLog()
parserParams.TxsResult.Log = log

return parser(utils.CosmosParserParams{
AddressPrefix: parserParams.AddressPrefix,
StakingDenom: parserParams.StakingDenom,
TxsResult: parserParams.TxsResult,
MsgCommonParams: parserParams.MsgCommonParams,
Msg: parserParams.Msg,
MsgIndex: parserParams.MsgIndex,
ParserManager: parserParams.ParserManager,
})
}
}

0 comments on commit f53deea

Please sign in to comment.