UNPKG

@bsv/overlay

Version:
105 lines (76 loc) 3.52 kB
### Introduction to BSV Overlay Services Engine The BSV Overlay Services Engine is designed to process transactions and manage data within a blockchain-based system, specifically targeting the Bitcoin SV (BSV) blockchain. It integrates various components such as Topic Managers, Lookup Services, Storage, and Chain Tracker to provide a robust environment for managing transaction data and overlay services. ### Components of the System 1. **Topic Managers**: Responsible for managing the admittance of transactions related to specific topics. 2. **Lookup Services**: Handle the lookup of UTXO (Unspent Transaction Output) data for transactions. 3. **Storage**: Manages persistent data storage, tracking UTXOs and their states within the system. 4. **Chain Tracker**: Verifies SPV (Simplified Payment Verification) data associated with transactions to ensure their validity. ### Setting Up the Engine Before you can use the engine, you must initialize it with the required components: ```ts import { Engine, KnexStorage } from "@bsv/overlay"; import { HelloTopicManager, HelloLookupService } from 'hello-services'; import { WoChain } from "@bsv/sdk"; // Initialize components const managers = { "exampleTopic": new HelloTopicManager() }; const lookupServices = { "exampleLookup": new HelloLookupService() }; const storage = new KnexStorage(); const chainTracker = new WoChain(); // Create the engine instance const engine = new Engine(managers, lookupServices, storage, chainTracker); ``` ### Submitting a Transaction To submit a transaction for processing by the Overlay Services: ```ts import { Transaction } from '@bsv/sdk' const tx = new Transaction(/* ... */); const transaction = { beef: tx.toBEEF(), topics: ['exampleTopic'] } // Submit transaction engine.submit(transaction).then(steak => { console.log("Transaction processed:", steak); }).catch(error => { console.error("Error processing transaction:", error); }); ``` ### Lookup Queries To perform a lookup query using the engine: ```ts const question = { service: 'exampleLookup', query: { name: 'Bob' } } // Perform a lookup engine.lookup(question).then(answer => { console.log("Lookup result:", answer); }).catch(error => { console.error("Error performing lookup:", error); }); ``` ### Managing UTXOs The system's core functionality involves managing UTXOs: 1. **Inserting a New UTXO**: Store new UTXO data when transactions are processed. 2. **Deleting a UTXO**: Remove UTXOs that are no longer needed or have been consumed by newer transactions. 3. **Tracking UTXO Consumption**: Monitor which transactions consume which UTXOs. ### Retrieving Documentation To retrieve documentation for specific managers or services: ```ts // For a topic manager engine.getDocumentationForTopicManger("exampleTopic").then(doc => { console.log("Documentation for Topic Manager:", doc); }); // For a lookup service engine.getDocumentationForLookupServiceProvider("exampleLookup").then(doc => { console.log("Documentation for Lookup Service:", doc); }); ``` ### Conclusion The BSV Overlay Services Engine provides a powerful toolset for managing transactions and data on the Bitcoin SV blockchain. It's designed to handle complex data structures and ensure the integrity and security of transactions through rigorous validation and management processes. By following this tutorial, developers can effectively integrate and utilize these capabilities within their blockchain applications.