Resolve "feat(Docs): Add BlockchainElectrum Tool"

This commit is contained in:
2025-04-07 06:40:02 +00:00
committed by Jim Hamill
parent 5623b9b27c
commit a392462f12
5 changed files with 132 additions and 25 deletions
@@ -48,6 +48,11 @@ export type BlockchainElectrumOpts = {
application: string;
};
export type BlockchainElectrumParams = {
store?: BaseStore;
opts?: Partial<BlockchainElectrumOpts>;
};
export class BlockchainElectrum extends BaseBlockchain {
// Composables.
electrumClient!: ElectrumClient<ElectrumProtocolEvents>;
@@ -60,18 +65,43 @@ export class BlockchainElectrum extends BaseBlockchain {
addressSubscriptions: Map<string, Set<AddressCallback>> = new Map();
transactionSubscriptions: Map<string, Set<TransactionCallback>> = new Map();
// Options
store: BaseStore;
opts: BlockchainElectrumOpts;
constructor(
public readonly store: BaseStore = new StoreInMemory(),
public readonly opts: BlockchainElectrumOpts = {
public readonly params: BlockchainElectrumParams = {},
) {
super();
// Set the store, or use the memory store by default.
this.store = params.store ?? new StoreInMemory();
// Combine provided options with default options.
this.opts = {
servers: [
'bch.imaginary.cash',
'cashnode.bch.ninja',
'electrum.imaginary.cash',
],
application: 'XOApp',
},
) {
super();
...params.opts,
};
}
/**
* Creates a new BlockchainElectrum instance.
* @param {BlockchainElectrumParams} params - The parameters for the BlockchainElectrum instance.
* @returns {BlockchainElectrum} A new BlockchainElectrum instance.
*/
static async from(
params: BlockchainElectrumParams = {},
): Promise<BlockchainElectrum> {
const blockchain = new BlockchainElectrum(params);
await blockchain.start();
return blockchain;
}
async start() {