chaingate
Version:
Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO
54 lines (53 loc) • 2.22 kB
TypeScript
import type { Amount } from './Amount';
/**
* A UTXO that is tracked locally (either as spent or as a new unspent change output).
*/
export interface CachedUtxo {
txid: string;
n: number;
amount: Amount;
script: Uint8Array;
}
/**
* Local cache that tracks spent and unspent UTXOs between broadcast and API indexing.
*
* When a transaction is broadcast, the API may still return the spent inputs
* (stale) and may not yet know about the new change outputs. This cache bridges
* that gap so that successive transactions can be built immediately.
*
* - **Spent**: UTXOs consumed by a local broadcast. Filtered out even if the
* API still returns them.
* - **Unspent**: Change outputs created by a local broadcast. Included even if
* the API does not know about them yet.
*
* When a broadcasted transaction is confirmed, {@link confirmTransaction} should
* be called to clean up the cache entries (the API has caught up).
*/
export declare class UtxoLocalCache {
/** "txid:n" → broadcastTxId that consumed the UTXO. */
private spent;
/** address → locally created unspent UTXOs. */
private unspent;
/**
* Marks a UTXO as spent by a broadcast transaction.
*
* If the UTXO was a locally cached unspent (e.g. a change output from a
* previous broadcast), it is also removed from the unspent set.
*/
markSpent(txid: string, n: number, broadcastTxId: string): void;
/** Returns `true` if the UTXO has been marked as spent by a local broadcast. */
isSpent(txid: string, n: number): boolean;
/** Adds a new unspent UTXO (typically a change output from a local broadcast). */
addUnspent(address: string, utxo: CachedUtxo): void;
/** Returns a copy of locally cached unspent UTXOs for the given address. */
getUnspent(address: string): CachedUtxo[];
/**
* Cleans up cache entries for a confirmed broadcast transaction.
*
* Once the API has indexed the transaction, the local overrides are no longer
* needed:
* - Spent entries consumed by this broadcast are removed.
* - Unspent entries created by this broadcast are removed.
*/
confirmTransaction(broadcastTxId: string): void;
}