Resolve "WIP: UTXO Selection and Storage"
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { Transaction } from '@xo/primitives';
|
||||
import { BlockchainLocal, WalletP2PKH } from '@xo/wallet';
|
||||
|
||||
const blockchainLocal = new BlockchainLocal();
|
||||
await blockchainLocal.start();
|
||||
|
||||
const services = {
|
||||
blockchain: blockchainLocal,
|
||||
};
|
||||
|
||||
const walletP2PKH = WalletP2PKH.generateRandom(services);
|
||||
const walletP2PKHReceive = WalletP2PKH.generateRandom(services);
|
||||
|
||||
const coinbaseTransaction = new Transaction({
|
||||
version: 2,
|
||||
locktime: 0,
|
||||
inputs: [
|
||||
{
|
||||
outpointIndex: 0,
|
||||
outpointTransactionHash: new Uint8Array(),
|
||||
unlockingBytecode: new Uint8Array(),
|
||||
sequenceNumber: 0,
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{
|
||||
lockingBytecode: (
|
||||
await walletP2PKH.getReceivingAddress()
|
||||
).toLockscriptBytes(),
|
||||
valueSatoshis: 100_000n,
|
||||
},
|
||||
{
|
||||
lockingBytecode: (
|
||||
await walletP2PKH.getReceivingAddress()
|
||||
).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 sendTx = await walletP2PKH.send({
|
||||
outputs: [
|
||||
{
|
||||
lockingBytecode: (
|
||||
await walletP2PKHReceive.getReceivingAddress()
|
||||
).toLockscriptBytes(),
|
||||
valueSatoshis: 150_000n,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.log(sendTx);
|
||||
|
||||
// await blockchainLocal.broadcastTransaction(new Transaction(sendTx));
|
||||
|
||||
console.log('walletP2PKH unspents', await walletP2PKH.fetchUnspentDirectives());
|
||||
console.log(
|
||||
'walletP2PKHReceive unspents',
|
||||
await walletP2PKHReceive.fetchUnspentDirectives(),
|
||||
);
|
||||
|
||||
console.log(blockchainLocal.deriveUtxoSet());
|
||||
Reference in New Issue
Block a user