From 854a51f58962af766fe4a3941e12ae1c6308f5ae Mon Sep 17 00:00:00 2001 From: vincentysc Date: Fri, 3 Nov 2023 14:00:41 +0800 Subject: [PATCH] fix lint --- usecase/model/icaauth/msg_register_account.go | 2 +- usecase/parser/icaauth/msg.go | 98 ++++++++++--------- 2 files changed, 55 insertions(+), 45 deletions(-) diff --git a/usecase/model/icaauth/msg_register_account.go b/usecase/model/icaauth/msg_register_account.go index f2ee229b..59be2b59 100644 --- a/usecase/model/icaauth/msg_register_account.go +++ b/usecase/model/icaauth/msg_register_account.go @@ -17,6 +17,6 @@ type MsgRegisterAccount struct { type RawMsgRegisterAccount struct { Owner string `mapstructure:"owner" json:"owner"` - ConnectionID string `mapstructure:"connection_id" json:"connection_id"` + ConnectionID string `mapstructure:"connection_id" json:"connectionId"` Version string `mapstructure:"version" json:"version"` } diff --git a/usecase/parser/icaauth/msg.go b/usecase/parser/icaauth/msg.go index 73968d7b..f6a56e95 100644 --- a/usecase/parser/icaauth/msg.go +++ b/usecase/parser/icaauth/msg.go @@ -1,6 +1,7 @@ package icaauth import ( + "encoding/json" "fmt" "github.com/crypto-com/chain-indexing/entity/command" @@ -20,14 +21,20 @@ func ParseChainmainMsgSubmitTx( panic(fmt.Errorf("error decoding RawMsgSubmitTx: %v", err)) } + var msgSubmitTx icaauth_model.MsgSubmitTx + msg, err := json.Marshal(rawMsg) + if err != nil { + panic(fmt.Errorf("error json marshalling RawMsgSubmitTx: %v", err)) + } + + err = json.Unmarshal(msg, &msgSubmitTx) + if err != nil { + panic(fmt.Errorf("error json unmarshlling MsgSubmitTx: %v", err)) + } + if !parserParams.MsgCommonParams.TxSuccess { msgSubmitTxParams := icaauth_model.MsgSubmitTxParams{ - MsgSubmitTx: icaauth_model.MsgSubmitTx{ - Owner: rawMsg.Owner, - ConnectionId: rawMsg.ConnectionId, - Msgs: rawMsg.Msgs, - TimeoutDuration: rawMsg.TimeoutDuration, - }, + MsgSubmitTx: msgSubmitTx, } // Getting possible signer address from Msg @@ -83,12 +90,7 @@ func ParseChainmainMsgSubmitTx( } msgSubmitTxParams := icaauth_model.MsgSubmitTxParams{ - MsgSubmitTx: icaauth_model.MsgSubmitTx{ - Owner: rawMsg.Owner, - ConnectionId: rawMsg.ConnectionId, - Msgs: rawMsg.Msgs, - TimeoutDuration: rawMsg.TimeoutDuration, - }, + MsgSubmitTx: msgSubmitTx, Packet: ibc_model.Packet{ Sequence: packetSequence, @@ -121,6 +123,17 @@ func ParseChainmainMsgRegisterAccount( panic(fmt.Errorf("error decoding RawMsgRegisterAccount: %v", err)) } + var msgRegisterAccount icaauth_model.MsgRegisterAccount + msg, err := json.Marshal(rawMsg) + if err != nil { + panic(fmt.Errorf("error json marshalling RawMsgRegisterAccount: %v", err)) + } + + err = json.Unmarshal(msg, &msgRegisterAccount) + if err != nil { + panic(fmt.Errorf("error json unmarshlling MsgRegisterAccount: %v", err)) + } + if !parserParams.MsgCommonParams.TxSuccess { // Getting possible signer address from Msg var possibleSignerAddresses []string @@ -130,11 +143,7 @@ func ParseChainmainMsgRegisterAccount( parserParams.MsgCommonParams, icaauth_model.MsgRegisterAccountParams{ - MsgRegisterAccount: icaauth_model.MsgRegisterAccount{ - Owner: rawMsg.Owner, - ConnectionID: rawMsg.ConnectionID, - Version: rawMsg.Version, - }, + MsgRegisterAccount: msgRegisterAccount, }, )}, possibleSignerAddresses } @@ -146,11 +155,7 @@ func ParseChainmainMsgRegisterAccount( } msgRegisterAccountParams := icaauth_model.MsgRegisterAccountParams{ - MsgRegisterAccount: icaauth_model.MsgRegisterAccount{ - Owner: rawMsg.Owner, - ConnectionID: rawMsg.ConnectionID, - Version: rawMsg.Version, - }, + MsgRegisterAccount: msgRegisterAccount, PortID: event.MustGetAttributeByKey("port_id"), ChannelID: event.MustGetAttributeByKey("channel_id"), @@ -177,14 +182,20 @@ func ParseMsgSubmitTx( panic(fmt.Errorf("error decoding RawMsgSubmitTx: %v", err)) } + var msgSubmitTx icaauth_model.MsgSubmitTx + msg, err := json.Marshal(rawMsg) + if err != nil { + panic(fmt.Errorf("error json marshalling RawMsgSubmitTx: %v", err)) + } + + err = json.Unmarshal(msg, &msgSubmitTx) + if err != nil { + panic(fmt.Errorf("error json unmarshlling MsgSubmitTx: %v", err)) + } + if !parserParams.MsgCommonParams.TxSuccess { msgSubmitTxParams := icaauth_model.MsgSubmitTxParams{ - MsgSubmitTx: icaauth_model.MsgSubmitTx{ - Owner: rawMsg.Owner, - ConnectionId: rawMsg.ConnectionId, - Msgs: rawMsg.Msgs, - TimeoutDuration: rawMsg.TimeoutDuration, - }, + MsgSubmitTx: msgSubmitTx, } // Getting possible signer address from Msg @@ -240,12 +251,7 @@ func ParseMsgSubmitTx( } msgSubmitTxParams := icaauth_model.MsgSubmitTxParams{ - MsgSubmitTx: icaauth_model.MsgSubmitTx{ - Owner: rawMsg.Owner, - ConnectionId: rawMsg.ConnectionId, - Msgs: rawMsg.Msgs, - TimeoutDuration: rawMsg.TimeoutDuration, - }, + MsgSubmitTx: msgSubmitTx, Packet: ibc_model.Packet{ Sequence: packetSequence, @@ -278,6 +284,17 @@ func ParseMsgRegisterAccount( panic(fmt.Errorf("error decoding RawMsgRegisterAccount: %v", err)) } + var msgRegisterAccount icaauth_model.MsgRegisterAccount + msg, err := json.Marshal(rawMsg) + if err != nil { + panic(fmt.Errorf("error json marshalling RawMsgRegisterAccount: %v", err)) + } + + err = json.Unmarshal(msg, &msgRegisterAccount) + if err != nil { + panic(fmt.Errorf("error json unmarshlling MsgRegisterAccount: %v", err)) + } + if !parserParams.MsgCommonParams.TxSuccess { // Getting possible signer address from Msg var possibleSignerAddresses []string @@ -287,11 +304,7 @@ func ParseMsgRegisterAccount( parserParams.MsgCommonParams, icaauth_model.MsgRegisterAccountParams{ - MsgRegisterAccount: icaauth_model.MsgRegisterAccount{ - Owner: rawMsg.Owner, - ConnectionID: rawMsg.ConnectionID, - Version: rawMsg.Version, - }, + MsgRegisterAccount: msgRegisterAccount, }, )}, possibleSignerAddresses } @@ -303,11 +316,8 @@ func ParseMsgRegisterAccount( } msgRegisterAccountParams := icaauth_model.MsgRegisterAccountParams{ - MsgRegisterAccount: icaauth_model.MsgRegisterAccount{ - Owner: rawMsg.Owner, - ConnectionID: rawMsg.ConnectionID, - Version: rawMsg.Version, - }, + MsgRegisterAccount: msgRegisterAccount, + PortID: event.MustGetAttributeByKey("port_id"), ChannelID: event.MustGetAttributeByKey("channel_id"), CounterpartyPortID: event.MustGetAttributeByKey("counterparty_port_id"),