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 Blockchain Query #320

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

Implement Stacks Blockchain Query #320

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

Comments

@CyrusVorwald
Copy link

This issue covers the parts of the Stacks blockchain provider associated with blockchain data retrieval. This includes fetching the latest block height, checking message statuses, querying account balances, extracting cross-chain messages from blocks, and obtaining transaction receipts.

Implement QueryLatestHeight()

This method should query and return the latest block height from the Stacks blockchain.

func (p *Provider) QueryLatestHeight(ctx context.Context) (uint64, error)

Implement ShouldReceiveMessage() and ShouldSendMessage()

These methods always return true, nil, consistent with the ICON and EVM implementations.

func (p *Provider) ShouldReceiveMessage(ctx context.Context, messagekey *types.Message) (bool, error) {
	return true, nil
}

func (p *Provider) ShouldSendMessage(ctx context.Context, messageKey *types.Message) (bool, error) {
	return true, nil
}

Implement QueryBalance()

This method should query and return the balance of a given Stacks address.

func (p *Provider) QueryBalance(ctx context.Context, addr string) (*types.Coin, error)

Implement GenerateMessages()

This method should:

  • Retrieve the Stacks block at the height specified in the key parameter.
  • Iterate through the transactions in the block.
  • Identify and extract relevant cross-chain events from the transaction logs.

For each relevant event:

  • Parse the event data according to Stacks-specific formats.
  • Create a types.Message object with the parsed data.
  • Return an array of all extracted and parsed types.Message objects.

func (p *Provider) GenerateMessages(ctx context.Context, key *types.MessageKeyWithMessageHeight) ([]*types.Message, error)

Implement QueryTransactionReceipt

This method should query and return the receipt for a given transaction hash on the Stacks blockchain.

func (p *Provider) QueryTransactionReceipt(ctx context.Context, txHash string) (*types.Receipt, error)

Acceptance Criteria

  • QueryLatestHeight successfully retrieves the latest block height from the Stacks blockchain or returns an error if the Stacks node is unreachable or returns invalid data.
  • ShouldReceiveMessage and ShouldSendMessage both return true, nil
  • QueryBalance correctly retrieves the balance for a given Stacks address or returns an error if the Stacks node is unreachable or returns invalid data, or the address is invalid.
  • GenerateMessages successfully retrieves the block for the given height from the Stacks blockchain, correctly identifies and extracts all relevant cross-chain events from the block's transactions, and accurately parses event data into types.Message objects, including all required fields (MessageHeight, EventType, Src, Dst, Sn, Data) for both EmitMessage and CallMessage. It returns an empty slice and no error if no relevant events are found in the block and returns an error if the block retrieval fails or if there are issues parsing the event data
  • QueryTransactionReceipt successfully retrieves the transaction receipt for a given transaction hash and correctly populates the types.Receipt struct. It returns an error for non-existent or invalid transaction hashes.
  • 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