Blockchain Traits
This commit is contained in:
@@ -5,10 +5,7 @@ import {
|
||||
type WalletTransactions,
|
||||
} from './types.js';
|
||||
|
||||
import {
|
||||
type BlockchainTransactions,
|
||||
type BlockchainUTXOs,
|
||||
} from '../blockchain';
|
||||
import { type BlockchainUTXOs } from '../blockchain';
|
||||
import { type Activities } from '../storage';
|
||||
import { EventEmitter } from '../utils';
|
||||
|
||||
@@ -16,7 +13,7 @@ import { type TokenBalances, type Address } from '@xocash/primitives';
|
||||
|
||||
export type WalletEvents = {
|
||||
shouldMonitorUpdated: boolean;
|
||||
transactionsUpdated: BlockchainTransactions;
|
||||
transactionsUpdated: WalletTransactions;
|
||||
unspentsUpdated: BlockchainUTXOs;
|
||||
stateUpdated: string | null;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { type BaseBlockchain, type BlockchainTransaction } from '../blockchain';
|
||||
import {
|
||||
type BaseBlockchain,
|
||||
type AddressStatusPayload,
|
||||
type BlockHeightPayload,
|
||||
type BlockchainTransaction,
|
||||
} from '../blockchain';
|
||||
import { type Activities, type BaseStore } from '../storage';
|
||||
|
||||
import { type Address, type ExtMap } from '@xocash/primitives';
|
||||
@@ -12,9 +17,15 @@ import {
|
||||
type Output,
|
||||
} from '@bitauth/libauth';
|
||||
|
||||
// NOTE: For Wallets, the Blockchain Adapter must have Address and Transaction indexing.
|
||||
export type WalletBlockchain = BaseBlockchain<
|
||||
AddressStatusPayload,
|
||||
BlockHeightPayload
|
||||
>;
|
||||
|
||||
export type WalletDependencies = {
|
||||
activities?: Activities;
|
||||
blockchain: BaseBlockchain;
|
||||
blockchain: WalletBlockchain;
|
||||
cache?: BaseStore;
|
||||
};
|
||||
|
||||
@@ -24,7 +35,6 @@ export type InputTemplateBCH = InputTemplate<
|
||||
CompilationData
|
||||
>;
|
||||
|
||||
// TODO: Rename me to WalletUTXO
|
||||
export type WalletUTXO = {
|
||||
outpointIndex: number;
|
||||
outpointTransactionHash: Uint8Array;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { BaseWallet } from './base-wallet.js';
|
||||
import { type TransactionTemplate } from './types.js';
|
||||
import { TransactionBuilder } from './transaction-builder.js';
|
||||
import { type WalletDependencies } from './types.js';
|
||||
import { type WalletBlockchain, type WalletDependencies } from './types.js';
|
||||
import { WalletP2PKH } from './wallet-p2pkh.js';
|
||||
|
||||
import { type BaseBlockchain } from '../blockchain';
|
||||
import { type BaseStore, Activities, StoreInMemory } from '../storage';
|
||||
|
||||
import {
|
||||
@@ -80,7 +79,7 @@ export class WalletHD extends BaseWallet {
|
||||
|
||||
// Dependencies.
|
||||
public readonly activities: Activities;
|
||||
public readonly blockchain: BaseBlockchain;
|
||||
public readonly blockchain: WalletBlockchain;
|
||||
public readonly cache: BaseStore;
|
||||
|
||||
// Genesis Data.
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { BaseWallet } from './base-wallet.js';
|
||||
import { type TransactionTemplate, type WalletDependencies } from './types.js';
|
||||
import {
|
||||
type TransactionTemplate,
|
||||
type WalletBlockchain,
|
||||
type WalletDependencies,
|
||||
} from './types.js';
|
||||
import { TransactionBuilder } from './transaction-builder.js';
|
||||
|
||||
import { type BaseBlockchain, type BlockchainTransaction } from '../blockchain';
|
||||
import {
|
||||
type AddressStatusPayload,
|
||||
type BlockchainTransaction,
|
||||
} from '../blockchain';
|
||||
import { type BaseStore, Activities, StoreInMemory } from '../storage';
|
||||
|
||||
import {
|
||||
@@ -116,7 +123,7 @@ export class WalletP2PKH extends BaseWallet {
|
||||
|
||||
// Dependencies.
|
||||
public readonly activities: Activities;
|
||||
public readonly blockchain: BaseBlockchain;
|
||||
public readonly blockchain: WalletBlockchain;
|
||||
public readonly cache: BaseStore;
|
||||
|
||||
// Genesis Data.
|
||||
@@ -408,11 +415,14 @@ export class WalletP2PKH extends BaseWallet {
|
||||
await this.blockchain.broadcastTransaction(generatedTxBytes);
|
||||
}
|
||||
|
||||
private async onAddressNotification(status: string | null) {
|
||||
private async onAddressNotification(
|
||||
_address: string,
|
||||
payload?: AddressStatusPayload,
|
||||
) {
|
||||
// If wallet state has changed...
|
||||
if (status !== this.status) {
|
||||
if (payload && payload.status !== this.status) {
|
||||
// Set our new status.
|
||||
this.status = status;
|
||||
this.status = payload.status;
|
||||
|
||||
// Emit an event.
|
||||
this.emit('stateUpdated', this.status);
|
||||
|
||||
Reference in New Issue
Block a user