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
+54
View File
@@ -0,0 +1,54 @@
import { Transaction } from '@xo/primitives';
import { BlockchainLocal, WalletP2PKH } from '@xo/wallet';
const blockchainLocal = new BlockchainLocal();
await blockchainLocal.start();
const walletP2PKH = WalletP2PKH.generateRandom(blockchainLocal);
const walletP2PKHReceive = WalletP2PKH.generateRandom(blockchainLocal);
const coinbaseTransaction = new Transaction({
version: 2,
locktime: 0,
inputs: [
{
outpointIndex: 0,
outpointTransactionHash: new Uint8Array(),
unlockingBytecode: new Uint8Array(),
sequenceNumber: 0,
},
],
outputs: [
{
lockingBytecode: walletP2PKH.getAddress().toLockscriptBytes(),
valueSatoshis: 100_000n,
},
{
lockingBytecode: walletP2PKH.getAddress().toLockscriptBytes(),
valueSatoshis: 150_000n,
},
],
});
await blockchainLocal.broadcastTransaction(coinbaseTransaction, {
skipValidation: true,
});
console.log('walletP2PKH unspents', await walletP2PKH.fetchUnspentDirectives());
console.log(
'walletP2PKHReceive unspents',
await walletP2PKHReceive.fetchUnspentDirectives()
);
const sweepTx = await walletP2PKH.sweep(
walletP2PKHReceive.getAddress().toLockscriptBytes()
);
await blockchainLocal.broadcastTransaction(sweepTx);
console.log('walletP2PKH unspents', await walletP2PKH.fetchUnspentDirectives());
console.log(
'walletP2PKHReceive unspents',
await walletP2PKHReceive.fetchUnspentDirectives()
);
console.log(blockchainLocal.deriveUtxoSet());
+1 -1
View File
@@ -19,7 +19,7 @@ await wallet.scan();
const transactions = wallet.getTransactions();
transactions.forEach((tx) => {
blockchain.broadcastTransaction(tx);
blockchain.commitTransaction(tx);
});
console.log(blockchain.pendingTransactions.deriveUtxoState());