WIP (BlockchainLocal working)

Signed-off-by: James Zuccon <zuccon@gmail.com>
This commit is contained in:
James Zuccon
2024-09-12 21:33:11 +10:00
parent 52da32ad4d
commit e308206d9f
33 changed files with 1274 additions and 397 deletions
+5 -6
View File
@@ -1,10 +1,9 @@
import { Blockchain, WalletHD } from '@xo/wallet';
import { HDPrivateNode } from '@xo/primitives';
import { IBlockchain, WalletHD } from '@xo/wallet';
import { WalletP2PKHVue, useWalletP2PKHVue } from './wallet-p2pkh-vue.js';
import { computed, ref, shallowRef } from 'vue';
import { HdPrivateNodeValid } from '@bitauth/libauth';
export class WalletHDVue extends WalletHD<WalletP2PKHVue> {
// Reactive State.
public rShouldMonitor = ref(false);
@@ -14,13 +13,13 @@ export class WalletHDVue extends WalletHD<WalletP2PKHVue> {
public rBalance = computed(() => {
return this.rWallets.value.reduce(
(total, node) => total + node.rBalance.value,
0
0n
);
});
constructor(
node: HdPrivateNodeValid,
electrum: Blockchain,
node: HDPrivateNode,
electrum: IBlockchain,
walletFactory = useWalletP2PKHVue
) {
super(node, electrum, walletFactory);
+10 -10
View File
@@ -1,5 +1,5 @@
import { Transaction } from '@xo/primitives';
import { type AddressListUnspent, Blockchain, WalletP2PKH } from '@xo/wallet';
import { PrivateKey, Transaction } from '@xo/primitives';
import { type IBlockchain, type UTXO, WalletP2PKH } from '@xo/wallet';
import { computed, shallowRef } from 'vue';
/**
@@ -15,19 +15,19 @@ import { computed, shallowRef } from 'vue';
*/
export class WalletP2PKHVue extends WalletP2PKH {
// Reactive State.
public rUnspents = shallowRef<AddressListUnspent['response']>([]);
public rUnspents = shallowRef<Array<UTXO>>([]);
public rTransactions = shallowRef<Array<Transaction>>([]);
// Computeds.
public rBalance = computed(() => {
return this.rUnspents.value.reduce(
(total, unspent) => total + unspent.value,
0
(total, unspent) => total + unspent.valueSatoshis,
0n
);
});
constructor(privateKeyBytes: Uint8Array, electrum: Blockchain) {
super(privateKeyBytes, electrum);
constructor(privateKey: PrivateKey, electrum: IBlockchain) {
super(privateKey, electrum);
this.events.on('unspentsUpdated', (unspents) => {
this.rUnspents.value = unspents;
@@ -40,8 +40,8 @@ export class WalletP2PKHVue extends WalletP2PKH {
}
export function useWalletP2PKHVue(
privateKeyBytes: Uint8Array,
electrum: Blockchain
privateKey: PrivateKey,
electrum: IBlockchain
): WalletP2PKHVue {
return new WalletP2PKHVue(privateKeyBytes, electrum);
return new WalletP2PKHVue(privateKey, electrum);
}