Rename fetchTransactions to fetchAddressHistory

This commit is contained in:
Jim Hamill
2025-04-09 02:03:27 +00:00
parent a662d5cc7e
commit 05f858549b
6 changed files with 27 additions and 15 deletions
@@ -1,11 +1,17 @@
import { BlockchainElectrum, encodeExtendedJson, Transaction } from '@xocash/stack';
import {
BlockchainElectrum,
encodeExtendedJson,
Transaction,
} from '@xocash/stack';
export const electrumClient = {
from: [
{
label: 'From Servers',
inputs: ['Servers'],
models: ['bch.imaginary.cash, cashnode.bch.ninja, electrum.imaginary.cash'],
models: [
'bch.imaginary.cash, cashnode.bch.ninja, electrum.imaginary.cash',
],
callback: async (args: [string]) => {
const electrum = await BlockchainElectrum.from({
opts: {
@@ -39,11 +45,11 @@ export const electrumClient = {
},
},
{
label: 'Fetch Transactions',
label: 'Fetch Address History',
inputs: ['Address'],
models: ['Address'],
callback: async (electrum: BlockchainElectrum, args: [string]) => {
const transactions = await electrum.fetchTransactions(args[0]);
const transactions = await electrum.fetchAddressHistory(args[0]);
return encodeExtendedJson(transactions.toArray(), 2);
},
},
@@ -57,4 +63,4 @@ export const electrumClient = {
},
},
],
};
};
@@ -83,7 +83,15 @@ export abstract class BaseBlockchain extends EventEmitter<BlockchainEvents> {
* @returns {Promise<BlockchainTransactions>} A promise that resolves with the list of transactions
* @throws {Error} If the address is invalid or the query fails
*/
abstract fetchTransactions(address: string): Promise<BlockchainTransactions>;
abstract fetchAddressHistory(
address: string,
): Promise<BlockchainTransactions>;
// TODO: We may have a fetchTokenHistory in future, but Fulcrum does not currently support indexing tokens.
// There are actually a few functional discrepancies with the adapters: different adapters grant different capabilities.
// For example, Chaingraph can fetch token and address history. But BCHN P2P network cannot even fetch address history.
// We might want to handle this by having multiple BlockchainInterfaces (e.g. IBlockchainAddressSubscriptions) that describe capabilities.
// But we should return to that later.
/**
* Broadcasts a raw transaction to the blockchain network.
@@ -69,9 +69,7 @@ export class BlockchainElectrum extends BaseBlockchain {
store: BaseStore;
opts: BlockchainElectrumOpts;
constructor(
public readonly params: BlockchainElectrumParams = {},
) {
constructor(public readonly params: BlockchainElectrumParams = {}) {
super();
// Set the store, or use the memory store by default.
@@ -266,7 +264,7 @@ export class BlockchainElectrum extends BaseBlockchain {
return transaction;
}
async fetchTransactions(address: string) {
async fetchAddressHistory(address: string) {
// Wait for connection to be established before attempting to subscribe.
// TODO: Consider doing this at a higher level.
if (!this.isConnected) {
@@ -71,7 +71,7 @@ export class BlockchainLocal extends BaseBlockchain {
return tx.transaction;
}
async fetchTransactions(address: string) {
async fetchAddressHistory(address: string) {
return this.transactions.filter((tx) => {
// Check if any input or output involves the address
// This is a simplified check and might need to be more sophisticated in a real implementation
+3 -3
View File
@@ -60,11 +60,11 @@ export class Blockchain extends BaseBlockchain {
}
}
async fetchTransactions(address: string) {
async fetchAddressHistory(address: string) {
if (this.blockchainElectrum.isConnected) {
return await this.blockchainElectrum.fetchTransactions(address);
return await this.blockchainElectrum.fetchAddressHistory(address);
} else {
return await this.blockchainLocal.fetchTransactions(address);
return await this.blockchainLocal.fetchAddressHistory(address);
}
}
+1 -1
View File
@@ -241,7 +241,7 @@ export class WalletP2PKH extends BaseWallet<WalletP2PKHEvents> {
const address = await this.getReceivingAddress();
// Get transactions involving this address.
const transactions = await this.blockchain.fetchTransactions(
const transactions = await this.blockchain.fetchAddressHistory(
address.toCashAddr(),
);