Skip to content

Commit 3ff1606

Browse files
authored
Merge pull request #902 from crypto-com/fix/v1-proposal
Fix: proposal id not found
2 parents 74fb66f + d7028dd commit 3ff1606

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

usecase/parser/gov/v1/msg.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -170,30 +170,24 @@ func ParseMsgSubmitProposal(
170170
events := log.GetEventsByType("submit_proposal")
171171

172172
var proposalId *string
173-
if parserParams.Msg["msg_index"] != nil {
174-
msgIndex, err := strconv.Atoi(parserParams.Msg["msg_index"].(string))
175-
if err != nil {
176-
panic("error on parsing `msg_index` to int")
177-
}
178173

179-
proposalId = events[msgIndex].GetAttributeByKey("proposal_id")
180-
if proposalId == nil {
181-
panic("missing `proposal_id` in `submit_proposal` event of TxsResult log")
174+
for _, event := range events {
175+
if proposalId != nil {
176+
break
182177
}
183178

184-
if events[msgIndex].HasAttribute("voting_period_start") {
185-
cmds = append(cmds, command_usecase.NewStartProposalVotingPeriod(
186-
parserParams.MsgCommonParams.BlockHeight, events[msgIndex].MustGetAttributeByKey("voting_period_start"),
187-
))
179+
if event.HasAttribute("msg_index") {
180+
msgIndex, err := strconv.Atoi(event.MustGetAttributeByKey("msg_index"))
181+
if err != nil {
182+
panic("error on parsing `msg_index` to int")
183+
}
184+
if msgIndex != parserParams.MsgIndex {
185+
continue
186+
}
188187
}
189-
} else {
190-
event := log.GetEventByType("submit_proposal")
191-
if event == nil {
192-
panic("missing `submit_proposal` event in TxsResult log")
193-
}
194-
proposalId = event.GetAttributeByKey("proposal_id")
195-
if proposalId == nil {
196-
panic("missing `proposal_id` in `submit_proposal` event of TxsResult log")
188+
189+
if event.HasAttribute("proposal_id") {
190+
proposalId = event.GetAttributeByKey("proposal_id")
197191
}
198192

199193
if event.HasAttribute("voting_period_start") {
@@ -203,6 +197,10 @@ func ParseMsgSubmitProposal(
203197
}
204198
}
205199

200+
if proposalId == nil {
201+
panic("missing `proposal_id` in `submit_proposal` event of TxsResult log")
202+
}
203+
206204
return append([]command.Command{
207205
command_usecase.NewCreateMsgSubmitProposal(
208206
parserParams.MsgCommonParams,

0 commit comments

Comments
 (0)