Skip to content

Instantly share code, notes, and snippets.

@pinheadmz
Created May 2, 2019 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinheadmz/99a4dad597427171a5e44043b84e9eae to your computer and use it in GitHub Desktop.
Save pinheadmz/99a4dad597427171a5e44043b84e9eae to your computer and use it in GitHub Desktop.
'use strict';
const bcoin = require('bcoin');
const plugin = bcoin.wallet.plugin;
const network = bcoin.Network.get('regtest');
const client = require('bclient');
const {MTX, Input, Outpoint} = bcoin;
const random = require('bcrypto/lib/random');
const walletClient = new client.WalletClient({
port: network.walletPort
});
const primary = walletClient.wallet('primary');
const node = new bcoin.FullNode({
network: 'regtest',
db: 'memory',
logLevel: 'spam'
});
node.use(plugin);
const walletdb = node.plugins.walletdb.wdb;
function dummyInput() {
const hash = random.randomBytes(32);
return Input.fromOutpoint(new Outpoint(hash, 0));
}
(async () => {
await node.open();
const addr = await primary.createAddress('default');
const amt1 = 6000;
const amt2 = 10000;
const amt3 = 500000;
for (let i = 0; i < 150; i++) {
const fund = new MTX();
fund.addInput(dummyInput());
fund.addOutput(addr.address, amt1);
const tx = fund.toTX();
await walletdb.addTX(tx);
}
for (let i = 0; i < 150; i++) {
const fund = new MTX();
fund.addInput(dummyInput());
fund.addOutput(addr.address, amt2);
const tx = fund.toTX();
await walletdb.addTX(tx);
}
for (let i = 0; i < 150; i++) {
const fund = new MTX();
fund.addInput(dummyInput());
fund.addOutput(addr.address, amt3);
const tx = fund.toTX();
await walletdb.addTX(tx);
}
const total = (amt1 * 150) + (amt2 * 150) + (amt3 * 150);
primary.send({
outputs:[{
value: total,
address: 'moodgfQhGTnZTuZYMaeSu6r2f6fLkBgFVb'
}],
rate: 10000,
subtractFee: true
}).then(console.log);
})().catch((err) => {
console.error(err.stack);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment