76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
import { Transaction } from '@xo/primitives';
|
|
import {
|
|
BlockchainLocal,
|
|
StorageMemory,
|
|
WalletP2PKH,
|
|
StorageLocal,
|
|
} 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());
|
|
|
|
const storageMemory = new StorageMemory();
|
|
await storageMemory.start();
|
|
|
|
await storageMemory.set('test', {
|
|
isItWorking: true,
|
|
});
|
|
|
|
console.log(storageMemory.storage);
|
|
|
|
const storageLocal = new StorageLocal();
|
|
await storageLocal.start();
|
|
|
|
await storageLocal.set('test', {
|
|
thisShouldNotWork: true,
|
|
});
|