Created
May 2, 2019 16:35
-
-
Save pinheadmz/99a4dad597427171a5e44043b84e9eae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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