Conversation
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Reviewer's GuideThis PR replaces the external merkletreejs dependency with a custom BitcoinMerkleTree implementation for constructing and verifying Bitcoin Merkle proofs, refactors the Indexer’s proof generation and validation logic to use the new tree, and updates the test suite accordingly. Sequence diagram for Merkle proof generation with custom BitcoinMerkleTreesequenceDiagram
participant Indexer
participant BitcoinMerkleTree
participant Block
participant Transaction
Indexer->>Block: Get transactions
Indexer->>BitcoinMerkleTree: constructMerkleTree(block)
BitcoinMerkleTree->>Transaction: Get hashes
BitcoinMerkleTree-->>Indexer: Return tree
Indexer->>BitcoinMerkleTree: getTxProof(tree, targetTx)
BitcoinMerkleTree-->>Indexer: Return proofPath
Indexer->>Block: Compare calculated root with block.merkleRoot
Class diagram for the new BitcoinMerkleTree and Indexer changesclassDiagram
class BitcoinMerkleTree {
-tree: MerkleNode[][]
-root: Buffer
+constructor(transactions: Transaction[])
+getRoot(bigEndian: boolean): Buffer
+getProof(targetTx: Transaction): Buffer[]
}
class MerkleNode {
+hash: Buffer
+preimage: Buffer
}
class Indexer {
+constructMerkleTree(block: Block): BitcoinMerkleTree | null
+getTxProof(tree: BitcoinMerkleTree, targetTx: Transaction): Buffer[] | null
}
BitcoinMerkleTree o-- MerkleNode
Indexer --> BitcoinMerkleTree
Class diagram for ProofResult structure updateclassDiagram
class ProofResult {
+proofPath: Buffer[]
+merkleRoot: string
}
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the merkletreejs library with a custom BitcoinMerkleTree implementation to generate Bitcoin-style Merkle proofs and handle proof validation.
Key Changes:
- Implements custom BitcoinMerkleTree class for constructing Merkle trees and generating proofs
- Updates proof data structure to include merkle root alongside proof path
- Simplifies SuiClient proof encoding by removing unnecessary byte reversal operations
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
packages/btcindexer/src/bitcoin-merkle-tree.ts |
New custom implementation of Bitcoin Merkle tree with proof generation |
packages/btcindexer/src/bitcoin-merkle-tree.test.ts |
Unit tests for the new BitcoinMerkleTree implementation |
packages/btcindexer/src/btcindexer.ts |
Refactored to use BitcoinMerkleTree and updated proof validation logic |
packages/btcindexer/src/btcindexer.test.ts |
Updated test assertions to work with new proof structure |
packages/btcindexer/src/sui_client.ts |
Simplified proof encoding by removing buffer reversal |
packages/btcindexer/src/sui_client.test.ts |
Updated test to use new proof structure with merkle root |
Comments suppressed due to low confidence (1)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
There are a few linter issues - see github comments in the PR (in files, not above) |
Signed-off-by: sczembor <43810037+sczembor@users.noreply.github.com>
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Description
Closes: #46
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!to the type prefix if API or client breaking changeCHANGELOG.mdSummary by Sourcery
Replace merkletreejs with a custom BitcoinMerkleTree implementation and update the indexer and SuiClient to use it for Merkle proof generation and validation
New Features:
Enhancements:
Tests: