forked from bcoin-org/bcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
/
miner-configs.js
49 lines (37 loc) · 918 Bytes
/
miner-configs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const bcoin = require('../..');
const KeyRing = bcoin.keyring;
const WorkerPool = bcoin.workerpool;
const Chain = bcoin.chain;
const Miner = bcoin.miner;
const key = KeyRing.generate('regtest');
const workers = new WorkerPool({
enabled: true
});
const chain = new Chain({
network: 'regtest',
workers: workers
});
const miner = new Miner({
chain: chain,
addresses: [key.getAddress()],
coinbaseFlags: 'my-miner',
workers: workers
});
(async () => {
await miner.open();
const tmpl = await miner.createBlock();
console.log('Block template:');
console.log(tmpl);
const job = await miner.createJob();
const block = await job.mineAsync();
console.log('Mined block:');
console.log(block);
console.log(block.txs[0]);
await chain.add(block);
console.log('New tip:');
console.log(chain.tip);
})().catch((err) => {
console.error(err.stack);
process.exit(1);
});