Skip to content

Commit

Permalink
rename decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentysc committed Nov 22, 2024
1 parent 81256e9 commit 8a62ffc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 59 deletions.
6 changes: 3 additions & 3 deletions bootstrap/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/crypto-com/chain-indexing/appinterface/rdb"
config "github.com/crypto-com/chain-indexing/bootstrap/config"
projection_entity "github.com/crypto-com/chain-indexing/entity/projection"
"github.com/crypto-com/chain-indexing/external/evminnermsgdecoder"
"github.com/crypto-com/chain-indexing/external/ethereumtxinnermsgdecoder"
applogger "github.com/crypto-com/chain-indexing/external/logger"
"github.com/crypto-com/chain-indexing/external/txdecoder"
"github.com/crypto-com/chain-indexing/infrastructure/metric/prometheus"
Expand Down Expand Up @@ -81,9 +81,9 @@ func (a *app) InitHTTPAPIServer(registry RouteRegistry) {
}
}

func (a *app) InitIndexService(projections []projection_entity.Projection, cronJobs []projection_entity.CronJob, txDecoder txdecoder.TxDecoder, evmInnerMsgDecoder evminnermsgdecoder.EvmInnerMsgDecoder) {
func (a *app) InitIndexService(projections []projection_entity.Projection, cronJobs []projection_entity.CronJob, txDecoder txdecoder.TxDecoder, ethereumTxInnerMsgDecoder ethereumtxinnermsgdecoder.EthereumTxInnerMsgDecoder) {
if a.config.IndexService.Enable {
a.indexService = NewIndexService(a.logger, a.rdbConn, a.config, projections, cronJobs, txDecoder, evmInnerMsgDecoder)
a.indexService = NewIndexService(a.logger, a.rdbConn, a.config, projections, cronJobs, txDecoder, ethereumTxInnerMsgDecoder)
}
}

Expand Down
20 changes: 10 additions & 10 deletions bootstrap/indexservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/crypto-com/chain-indexing/bootstrap/config"
"github.com/crypto-com/chain-indexing/entity/event"
projection_entity "github.com/crypto-com/chain-indexing/entity/projection"
"github.com/crypto-com/chain-indexing/external/evminnermsgdecoder"
"github.com/crypto-com/chain-indexing/external/ethereumtxinnermsgdecoder"
applogger "github.com/crypto-com/chain-indexing/external/logger"
"github.com/crypto-com/chain-indexing/external/txdecoder"
event_usecase "github.com/crypto-com/chain-indexing/usecase/event"
Expand Down Expand Up @@ -42,8 +42,8 @@ type IndexService struct {
GithubAPIUser string
GithubAPIToken string

txDecoder txdecoder.TxDecoder
evmInnerMsgDecoder evminnermsgdecoder.EvmInnerMsgDecoder
txDecoder txdecoder.TxDecoder
ethereumTxInnerMsgDecoder ethereumtxinnermsgdecoder.EthereumTxInnerMsgDecoder
}

// NewIndexService creates a new server instance for polling and indexing
Expand All @@ -54,7 +54,7 @@ func NewIndexService(
projections []projection_entity.Projection,
cronJobs []projection_entity.CronJob,
txDecoder txdecoder.TxDecoder,
evmInnerMsgDecoder evminnermsgdecoder.EvmInnerMsgDecoder,
ethereumTxInnerMsgDecoder ethereumtxinnermsgdecoder.EthereumTxInnerMsgDecoder,
) *IndexService {
return &IndexService{
logger: logger,
Expand Down Expand Up @@ -83,8 +83,8 @@ func NewIndexService(
GithubAPIUser: config.IndexService.GithubAPI.Username,
GithubAPIToken: config.IndexService.GithubAPI.Token,

txDecoder: txDecoder,
evmInnerMsgDecoder: evmInnerMsgDecoder,
txDecoder: txDecoder,
ethereumTxInnerMsgDecoder: ethereumTxInnerMsgDecoder,
}
}

Expand Down Expand Up @@ -165,8 +165,8 @@ func (service *IndexService) RunEventStoreMode() error {
StartingBlockHeight: service.startingBlockHeight,
BlockResultEventAttributeDecodeMethod: service.BlockResultEventAttributeDecodeMethod,
},
TxDecoder: service.txDecoder,
EvmInnerMsgDecoder: service.evmInnerMsgDecoder,
TxDecoder: service.txDecoder,
EthereumTxInnerMsgDecoder: service.ethereumTxInnerMsgDecoder,
},
utils.NewCosmosParserManager(
utils.CosmosParserManagerParams{
Expand Down Expand Up @@ -207,8 +207,8 @@ func (service *IndexService) RunTendermintDirectMode() error {
StartingBlockHeight: service.startingBlockHeight,
BlockResultEventAttributeDecodeMethod: service.BlockResultEventAttributeDecodeMethod,
},
TxDecoder: service.txDecoder,
EvmInnerMsgDecoder: service.evmInnerMsgDecoder,
TxDecoder: service.txDecoder,
EthereumTxInnerMsgDecoder: service.ethereumTxInnerMsgDecoder,
},
utils.NewCosmosParserManager(
utils.CosmosParserManagerParams{
Expand Down
20 changes: 10 additions & 10 deletions bootstrap/syncmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
cosmosapp_interface "github.com/crypto-com/chain-indexing/appinterface/cosmosapp"
eventhandler_interface "github.com/crypto-com/chain-indexing/appinterface/eventhandler"
tendermint_interface "github.com/crypto-com/chain-indexing/appinterface/tendermint"
"github.com/crypto-com/chain-indexing/external/evminnermsgdecoder"
"github.com/crypto-com/chain-indexing/external/ethereumtxinnermsgdecoder"
"github.com/crypto-com/chain-indexing/external/txdecoder"
cosmosapp_infrastructure "github.com/crypto-com/chain-indexing/infrastructure/cosmosapp"
"github.com/crypto-com/chain-indexing/usecase/model"
Expand Down Expand Up @@ -55,17 +55,17 @@ type SyncManager struct {

startingBlockHeight int64

txDecoder txdecoder.TxDecoder
evmInnerMsgDecoder evminnermsgdecoder.EvmInnerMsgDecoder
txDecoder txdecoder.TxDecoder
ethereumTxInnerMsgDecoder ethereumtxinnermsgdecoder.EthereumTxInnerMsgDecoder

eventAttributeDecoder tendermint_interface.BlockResultEventAttributeDecoder
}

type SyncManagerParams struct {
Logger applogger.Logger
RDbConn rdb.Conn
TxDecoder txdecoder.TxDecoder
EvmInnerMsgDecoder evminnermsgdecoder.EvmInnerMsgDecoder
Logger applogger.Logger
RDbConn rdb.Conn
TxDecoder txdecoder.TxDecoder
EthereumTxInnerMsgDecoder ethereumtxinnermsgdecoder.EthereumTxInnerMsgDecoder

Config SyncManagerConfig
}
Expand Down Expand Up @@ -147,8 +147,8 @@ func NewSyncManager(

startingBlockHeight: params.Config.StartingBlockHeight,

txDecoder: params.TxDecoder,
evmInnerMsgDecoder: params.EvmInnerMsgDecoder,
txDecoder: params.TxDecoder,
ethereumTxInnerMsgDecoder: params.EthereumTxInnerMsgDecoder,

eventAttributeDecoder: eventAttributeDecoder,
}
Expand Down Expand Up @@ -298,7 +298,7 @@ func (manager *SyncManager) syncBlockWorker(blockHeight int64) ([]command_entity
})

manager.parserManager.TxDecoder = manager.txDecoder
manager.parserManager.EvmInnerMsgDecoder = manager.evmInnerMsgDecoder
manager.parserManager.EthereumTxInnerMsgDecoder = manager.ethereumTxInnerMsgDecoder
commands, err := parser.ParseBlockToCommands(
parseBlockToCommandsLogger,
manager.parserManager,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package evminnermsgdecoder
package ethereumtxinnermsgdecoder

type EvmInnerMsgDecoder interface {
type EthereumTxInnerMsgDecoder interface {
DecodeCosmosMsgFromTxInput([]byte, string) (map[string]interface{}, error)
}
28 changes: 14 additions & 14 deletions usecase/parser/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ func ParseBlockTxsMsgToCommands(
parser := parserManager.GetParser(utils.CosmosParserKey(msgType.(string)), utils.ParserBlockHeight(blockHeight))

msgCommands, possibleSignerAddresses = parser(utils.CosmosParserParams{
AddressPrefix: accountAddressPrefix,
StakingDenom: stakingDenom,
TxsResult: txsResult,
MsgCommonParams: msgCommonParams,
Msg: msg,
MsgIndex: msgIndex,
ParserManager: parserManager,
Logger: parserManager.GetLogger(),
TxDecoder: parserManager.TxDecoder,
EvmInnerMsgDecoder: parserManager.EvmInnerMsgDecoder,
IsProposalInnerMsg: false,
IsEthereumTxInnerMsg: false,
AddressPrefix: accountAddressPrefix,
StakingDenom: stakingDenom,
TxsResult: txsResult,
MsgCommonParams: msgCommonParams,
Msg: msg,
MsgIndex: msgIndex,
ParserManager: parserManager,
Logger: parserManager.GetLogger(),
TxDecoder: parserManager.TxDecoder,
EthereumTxInnerMsgDecoder: parserManager.EthereumTxInnerMsgDecoder,
IsProposalInnerMsg: false,
IsEthereumTxInnerMsg: false,
})
}
addresses = append(addresses, possibleSignerAddresses...)
Expand Down Expand Up @@ -2509,7 +2509,7 @@ func ParseMsgEthereumTx(
// parse msgCreateClient
sendEvents := log.GetEventsByType("create_client")
if len(sendEvents) > 0 {
msg, err := parserParams.EvmInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, MSG_CREATE_CLIENT_TYPE_URL)
msg, err := parserParams.EthereumTxInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, MSG_CREATE_CLIENT_TYPE_URL)
if err != nil {
panic(fmt.Errorf("error deserializing MsgCreateClient: %v", err))
}
Expand All @@ -2524,7 +2524,7 @@ func ParseMsgEthereumTx(
// parse MsgUpdateClient
sendEvents := log.GetEventsByType("update_client")
if len(sendEvents) > 0 {
msg, err := parserParams.EvmInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, MSG_UPDATE_CLIENT_TYPE_URL)
msg, err := parserParams.EthereumTxInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, MSG_UPDATE_CLIENT_TYPE_URL)
if err != nil {
panic(fmt.Errorf("error deserializing MsgUpdateClient: %v", err))
}
Expand Down
36 changes: 18 additions & 18 deletions usecase/parser/utils/parsermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"fmt"

"github.com/crypto-com/chain-indexing/entity/command"
"github.com/crypto-com/chain-indexing/external/evminnermsgdecoder"
"github.com/crypto-com/chain-indexing/external/ethereumtxinnermsgdecoder"
applogger "github.com/crypto-com/chain-indexing/external/logger"
"github.com/crypto-com/chain-indexing/external/txdecoder"
"github.com/crypto-com/chain-indexing/usecase/event"
"github.com/crypto-com/chain-indexing/usecase/model"
)

type CosmosParserManager struct {
store map[CosmosParserKey]BlockHeightToCosmosParserMap
logger applogger.Logger
config CosmosParserManagerConfig
TxDecoder txdecoder.TxDecoder
EvmInnerMsgDecoder evminnermsgdecoder.EvmInnerMsgDecoder
store map[CosmosParserKey]BlockHeightToCosmosParserMap
logger applogger.Logger
config CosmosParserManagerConfig
TxDecoder txdecoder.TxDecoder
EthereumTxInnerMsgDecoder ethereumtxinnermsgdecoder.EthereumTxInnerMsgDecoder
}

type CosmosParserKey string
Expand Down Expand Up @@ -48,18 +48,18 @@ type CosmosParser func(
) ([]command.Command, []string)

type CosmosParserParams struct {
AddressPrefix string
StakingDenom string
TxsResult model.BlockResultsTxsResult
MsgCommonParams event.MsgCommonParams
MsgIndex int
Msg map[string]interface{}
ParserManager *CosmosParserManager
Logger applogger.Logger
TxDecoder txdecoder.TxDecoder
EvmInnerMsgDecoder evminnermsgdecoder.EvmInnerMsgDecoder
IsProposalInnerMsg bool
IsEthereumTxInnerMsg bool
AddressPrefix string
StakingDenom string
TxsResult model.BlockResultsTxsResult
MsgCommonParams event.MsgCommonParams
MsgIndex int
Msg map[string]interface{}
ParserManager *CosmosParserManager
Logger applogger.Logger
TxDecoder txdecoder.TxDecoder
EthereumTxInnerMsgDecoder ethereumtxinnermsgdecoder.EthereumTxInnerMsgDecoder
IsProposalInnerMsg bool
IsEthereumTxInnerMsg bool
}

func NewCosmosParserManager(params CosmosParserManagerParams) *CosmosParserManager {
Expand Down
4 changes: 2 additions & 2 deletions usecase/parser/v1_4_0_cronos/msg/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func ParseMsgEthereumTx(
// parse msgCreateClient
sendEvents := events.GetEventsByType("create_client")
if len(sendEvents) > 0 {
msg, err := parserParams.EvmInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, "MsgCreateClient")
msg, err := parserParams.EthereumTxInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, "MsgCreateClient")
if err != nil {
panic(fmt.Errorf("error deserializing MsgCreateClient: %v", err))
}
Expand All @@ -268,7 +268,7 @@ func ParseMsgEthereumTx(
// parse MsgUpdateClient
sendEvents := events.GetEventsByType("update_client")
if len(sendEvents) > 0 {
msg, err := parserParams.EvmInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, "MsgUpdateClient")
msg, err := parserParams.EthereumTxInnerMsgDecoder.DecodeCosmosMsgFromTxInput(inputData, "MsgUpdateClient")
if err != nil {
panic(fmt.Errorf("error deserializing MsgUpdateClient: %v", err))
}
Expand Down

0 comments on commit 8a62ffc

Please sign in to comment.