Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Stacks Events and Event Parsing #318

Open
CyrusVorwald opened this issue Jul 28, 2024 · 0 comments
Open

Implement Stacks Events and Event Parsing #318

CyrusVorwald opened this issue Jul 28, 2024 · 0 comments
Assignees

Comments

@CyrusVorwald
Copy link

CyrusVorwald commented Jul 28, 2024

ProcessStacksEvent is the main interface for processing Stacks events within the Stacks Provider. It should use the ParseStacksEvent() function below and handle any additional provider-specific logic or error handling.

Stacks events

Define constants for the xCall event names we'll be monitoring on the Stacks blockchain:

const (
    EmitMessage = "EmitMessage"
    CallMessage = "CallMessage"
)

Implement eventMap()

This function should create a mapping between Stacks contract addresses and their associated events. It will be used to determine which events to monitor for each contract. The returned map should use contract addresses as keys and providerTypes.EventMap as values, where EventMap contains the contract name and a mapping of event signatures to event types.

func (p *Config) eventMap() map[string]providerTypes.EventMap

Implement GetMonitorEventFilters()

This function should return a list of event filters based on the eventMap(). These filters will be used by the Stacks Blockchain Listener to determine which events to monitor. Each EventFilter should specify the contract address and event signature to watch for.

func (p *Provider) GetMonitorEventFilters() []*types.EventFilter

Implement GetEventName() and GetAddressByEventType()

GetEventName() should return the human-readable event name (e.g., "EmitMessage") given an event signature.

func (p *Provider) GetEventName(sig string) string

GetAddressByEventType() should return the contract address associated with a given event type.

func (p *Provider) GetAddressByEventType(eventType string) types.Address

These functions will be used for event processing and routing.

Implement ParseStacksEvent()

This is the main entry point for parsing Stacks events. It should determine the event type and call the appropriate parsing function (parseEmitMessage or parseCallMessage). The function should return a types.Message that can be processed by the relay system.

func (p *Provider) ParseStacksEvent(event StacksEvent) (*types.Message, error)

Implement parseEmitMessage and parseCallMessage that handle the specific parsing logic for each event type. They should extract relevant data from the Stacks event and construct a types.Message. Use the ClarityValue types to parse the event data correctly.

func (p *Provider) parseEmitMessage(event StacksEvent) (*types.Message, error)
func (p *Provider) parseCallMessage(event StacksEvent) (*types.Message, error)

Acceptance Criteria

  • Event parsing logic correctly interprets EmitMessage and CallMessage events from Stacks xCall contract
  • Parsed events are correctly converted into the common types.Message format
  • Unit tests cover all methods and edge cases with >80% code coverage
  • Integration tests confirm functionality against Stacks testnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant