Skip to content

Look into creating a generic helper function for parsing event attributes #6651

@gjermundgaraba

Description

@gjermundgaraba

At the moment we have multiple methods to parse out specific event attributes (examples below).

As per the discussion here #6648 (comment)
Maybe we can find a clean way to more generically pick out values that we need.

// ParseProposalIDFromEvents parses events emitted from MsgSubmitProposal and returns proposalID
func ParseProposalIDFromEvents(events []abci.Event) (uint64, error) {
	for _, event := range events {
		for _, attribute := range event.Attributes {
			if attribute.Key == "proposal_id" {
				return strconv.ParseUint(attribute.Value, 10, 64)
			}
		}
	}

	return 0, fmt.Errorf("proposalID event attribute not found")
}

// ParsePacketSequenceFromEvents parses events emitted from MsgRecvPacket and returns the packet sequence
func ParsePacketSequenceFromEvents(events []abci.Event) (uint64, error) {
	for _, event := range events {
		for _, attribute := range event.Attributes {
			if attribute.Key == "packet_sequence" {
				return strconv.ParseUint(attribute.Value, 10, 64)
			}
		}
	}

	return 0, fmt.Errorf("packet sequence event attribute not found")
}

Metadata

Metadata

Assignees

Labels

testingTesting package and unit/integration teststype: code hygieneClean up code but without changing functionality or interfaces

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions