Merge branch 'rename_fetch_transactions_to_fetch_address_history' into 'development'
Rename fetchTransactions to fetchAddressHistory See merge request GeneralProtocols/xo/stack!61
This commit is contained in:
@@ -1,11 +1,17 @@
|
|||||||
import { BlockchainElectrum, encodeExtendedJson, Transaction } from '@xocash/stack';
|
import {
|
||||||
|
BlockchainElectrum,
|
||||||
|
encodeExtendedJson,
|
||||||
|
Transaction,
|
||||||
|
} from '@xocash/stack';
|
||||||
|
|
||||||
export const electrumClient = {
|
export const electrumClient = {
|
||||||
from: [
|
from: [
|
||||||
{
|
{
|
||||||
label: 'From Servers',
|
label: 'From Servers',
|
||||||
inputs: ['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]) => {
|
callback: async (args: [string]) => {
|
||||||
const electrum = await BlockchainElectrum.from({
|
const electrum = await BlockchainElectrum.from({
|
||||||
opts: {
|
opts: {
|
||||||
@@ -39,11 +45,11 @@ export const electrumClient = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Fetch Transactions',
|
label: 'Fetch Address History',
|
||||||
inputs: ['Address'],
|
inputs: ['Address'],
|
||||||
models: ['Address'],
|
models: ['Address'],
|
||||||
callback: async (electrum: BlockchainElectrum, args: [string]) => {
|
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);
|
return encodeExtendedJson(transactions.toArray(), 2);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -83,7 +83,15 @@ export abstract class BaseBlockchain extends EventEmitter<BlockchainEvents> {
|
|||||||
* @returns {Promise<BlockchainTransactions>} A promise that resolves with the list of transactions
|
* @returns {Promise<BlockchainTransactions>} A promise that resolves with the list of transactions
|
||||||
* @throws {Error} If the address is invalid or the query fails
|
* @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.
|
* Broadcasts a raw transaction to the blockchain network.
|
||||||
|
|||||||
@@ -69,9 +69,7 @@ export class BlockchainElectrum extends BaseBlockchain {
|
|||||||
store: BaseStore;
|
store: BaseStore;
|
||||||
opts: BlockchainElectrumOpts;
|
opts: BlockchainElectrumOpts;
|
||||||
|
|
||||||
constructor(
|
constructor(public readonly params: BlockchainElectrumParams = {}) {
|
||||||
public readonly params: BlockchainElectrumParams = {},
|
|
||||||
) {
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Set the store, or use the memory store by default.
|
// Set the store, or use the memory store by default.
|
||||||
@@ -266,7 +264,7 @@ export class BlockchainElectrum extends BaseBlockchain {
|
|||||||
return transaction;
|
return transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchTransactions(address: string) {
|
async fetchAddressHistory(address: string) {
|
||||||
// Wait for connection to be established before attempting to subscribe.
|
// Wait for connection to be established before attempting to subscribe.
|
||||||
// TODO: Consider doing this at a higher level.
|
// TODO: Consider doing this at a higher level.
|
||||||
if (!this.isConnected) {
|
if (!this.isConnected) {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export class BlockchainLocal extends BaseBlockchain {
|
|||||||
return tx.transaction;
|
return tx.transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchTransactions(address: string) {
|
async fetchAddressHistory(address: string) {
|
||||||
return this.transactions.filter((tx) => {
|
return this.transactions.filter((tx) => {
|
||||||
// Check if any input or output involves the address
|
// 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
|
// This is a simplified check and might need to be more sophisticated in a real implementation
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ export class Blockchain extends BaseBlockchain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchTransactions(address: string) {
|
async fetchAddressHistory(address: string) {
|
||||||
if (this.blockchainElectrum.isConnected) {
|
if (this.blockchainElectrum.isConnected) {
|
||||||
return await this.blockchainElectrum.fetchTransactions(address);
|
return await this.blockchainElectrum.fetchAddressHistory(address);
|
||||||
} else {
|
} else {
|
||||||
return await this.blockchainLocal.fetchTransactions(address);
|
return await this.blockchainLocal.fetchAddressHistory(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ export class WalletP2PKH extends BaseWallet<WalletP2PKHEvents> {
|
|||||||
const address = await this.getReceivingAddress();
|
const address = await this.getReceivingAddress();
|
||||||
|
|
||||||
// Get transactions involving this address.
|
// Get transactions involving this address.
|
||||||
const transactions = await this.blockchain.fetchTransactions(
|
const transactions = await this.blockchain.fetchAddressHistory(
|
||||||
address.toCashAddr(),
|
address.toCashAddr(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user