WIP (BlockchainLocal working)
Signed-off-by: James Zuccon <zuccon@gmail.com>
This commit is contained in:
@@ -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());
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user