minor.
This commit is contained in:
parent
61ea825ffe
commit
7c725c40aa
@ -34,7 +34,7 @@ Docs need to be rewritten. They're coming soon. I promise.
|
|||||||
### High-level usage for Node object
|
### High-level usage for Node object
|
||||||
|
|
||||||
``` js
|
``` js
|
||||||
var bcoin = require('bcoin');
|
var bcoin = require('bcoin')('main');
|
||||||
|
|
||||||
var node = bcoin.fullnode({
|
var node = bcoin.fullnode({
|
||||||
prune: false,
|
prune: false,
|
||||||
@ -136,8 +136,7 @@ $ node bin/bcoin-cli mempool
|
|||||||
### Creating a blockchain and mempool
|
### Creating a blockchain and mempool
|
||||||
|
|
||||||
``` js
|
``` js
|
||||||
var bcoin = require('bcoin');
|
var bcoin = require('bcoin')('regtest');
|
||||||
bcoin.protocol.network.set('regtest');
|
|
||||||
var chain = new bcoin.chain({ db: 'memory' });
|
var chain = new bcoin.chain({ db: 'memory' });
|
||||||
var mempool = new bcoin.mempool({ chain: chain, db: 'memory' });
|
var mempool = new bcoin.mempool({ chain: chain, db: 'memory' });
|
||||||
var miner = new bcoin.miner({ chain: chain, mempool: mempool });
|
var miner = new bcoin.miner({ chain: chain, mempool: mempool });
|
||||||
|
|||||||
@ -36,6 +36,7 @@ function ldb(options) {
|
|||||||
maxOpenFiles: options.maxOpenFiles || 8192,
|
maxOpenFiles: options.maxOpenFiles || 8192,
|
||||||
filterBits: 0,
|
filterBits: 0,
|
||||||
paranoidChecks: false,
|
paranoidChecks: false,
|
||||||
|
memory: false,
|
||||||
|
|
||||||
// For LMDB if we decide to use it:
|
// For LMDB if we decide to use it:
|
||||||
sync: options.sync || false,
|
sync: options.sync || false,
|
||||||
|
|||||||
@ -110,25 +110,22 @@ Miner.prototype._init = function _init() {
|
|||||||
stat.best);
|
stat.best);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.chain.open(function(err) {
|
function done(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return self.emit('error', err);
|
return self.emit('error', err);
|
||||||
self.loaded = true;
|
self.loaded = true;
|
||||||
self.emit('open');
|
self.emit('open');
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (this.mempool)
|
||||||
|
this.mempool.open(done);
|
||||||
|
else
|
||||||
|
this.chain.open(done);
|
||||||
};
|
};
|
||||||
|
|
||||||
Miner.prototype.start = function start() {
|
Miner.prototype.start = function start() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Wait for `tip`.
|
|
||||||
if (!this.chain.tip) {
|
|
||||||
this.chain.on('tip', function(tip) {
|
|
||||||
self.start();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.stop();
|
this.stop();
|
||||||
|
|
||||||
this.running = true;
|
this.running = true;
|
||||||
@ -189,6 +186,17 @@ Miner.prototype.createBlock = function createBlock(callback) {
|
|||||||
var ts = Math.max(utils.now(), this.chain.tip.ts + 1);
|
var ts = Math.max(utils.now(), this.chain.tip.ts + 1);
|
||||||
var attempt;
|
var attempt;
|
||||||
|
|
||||||
|
if (!this.loaded) {
|
||||||
|
this.open(function(err) {
|
||||||
|
if (err)
|
||||||
|
return callback(err);
|
||||||
|
self.createBlock(callback);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(this.chain.tip);
|
||||||
|
|
||||||
// Find target
|
// Find target
|
||||||
this.chain.getTargetAsync(this.chain.tip, ts, function(err, target) {
|
this.chain.getTargetAsync(this.chain.tip, ts, function(err, target) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -520,7 +528,6 @@ function rcmp(a, b) {
|
|||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var exports = Miner;
|
Miner.minerblock = MinerBlock;
|
||||||
exports.minerblock = MinerBlock;
|
return Miner;
|
||||||
return exports;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -37,7 +37,7 @@ function MTX(options) {
|
|||||||
this.ts = 0;
|
this.ts = 0;
|
||||||
this.block = null;
|
this.block = null;
|
||||||
this.index = -1;
|
this.index = -1;
|
||||||
this.ps = this.ts === 0 ? utils.now() : 0;
|
this.ps = options.ps != null ? options.ps : utils.now();
|
||||||
this.changeIndex = options.changeIndex != null ? options.changeIndex : -1;
|
this.changeIndex = options.changeIndex != null ? options.changeIndex : -1;
|
||||||
this.height = -1;
|
this.height = -1;
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,13 @@ function Pool(options) {
|
|||||||
options.relay = true;
|
options.relay = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.headers == null) {
|
||||||
|
if (options.spv)
|
||||||
|
options.headers = true;
|
||||||
|
else
|
||||||
|
options.headers = false;
|
||||||
|
}
|
||||||
|
|
||||||
seeds = (options.seeds || network.seeds).slice();
|
seeds = (options.seeds || network.seeds).slice();
|
||||||
|
|
||||||
if (process.env.BCOIN_SEED)
|
if (process.env.BCOIN_SEED)
|
||||||
@ -59,14 +66,6 @@ function Pool(options) {
|
|||||||
this.size = options.size || 8;
|
this.size = options.size || 8;
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
|
|
||||||
if (options.spv) {
|
|
||||||
if (options.headers == null)
|
|
||||||
options.headers = true;
|
|
||||||
} else {
|
|
||||||
if (options.headers == null)
|
|
||||||
options.headers = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.syncing = false;
|
this.syncing = false;
|
||||||
this.synced = false;
|
this.synced = false;
|
||||||
this._scheduled = false;
|
this._scheduled = false;
|
||||||
@ -140,7 +139,7 @@ function Pool(options) {
|
|||||||
timeout: options.invTimeout || 60000
|
timeout: options.invTimeout || 60000
|
||||||
};
|
};
|
||||||
|
|
||||||
this.chain.open(function(err) {
|
function done(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return self.emit('error', err);
|
return self.emit('error', err);
|
||||||
|
|
||||||
@ -148,7 +147,12 @@ function Pool(options) {
|
|||||||
self.emit('open');
|
self.emit('open');
|
||||||
|
|
||||||
self._init();
|
self._init();
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (this.mempool)
|
||||||
|
this.mempool.open(done);
|
||||||
|
else
|
||||||
|
this.chain.open(done);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.inherits(Pool, EventEmitter);
|
utils.inherits(Pool, EventEmitter);
|
||||||
|
|||||||
@ -40,7 +40,7 @@ function TX(data, block, index) {
|
|||||||
this.ts = data.ts || 0;
|
this.ts = data.ts || 0;
|
||||||
this.block = data.block || null;
|
this.block = data.block || null;
|
||||||
this.index = data.index != null ? data.index : -1;
|
this.index = data.index != null ? data.index : -1;
|
||||||
this.ps = this.ts === 0 ? utils.now() : 0;
|
this.ps = this.ts === 0 ? (data.ps != null ? data.ps : utils.now()) : 0;
|
||||||
this.height = data.height != null ? data.height : -1;
|
this.height = data.height != null ? data.height : -1;
|
||||||
|
|
||||||
this._hash = null;
|
this._hash = null;
|
||||||
@ -1223,7 +1223,9 @@ TX.prototype.inspect = function inspect() {
|
|||||||
date: new Date(this.ts * 1000).toISOString(),
|
date: new Date(this.ts * 1000).toISOString(),
|
||||||
block: this.block ? utils.revHex(this.block) : null,
|
block: this.block ? utils.revHex(this.block) : null,
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
|
ps: this.ps,
|
||||||
index: this.index,
|
index: this.index,
|
||||||
|
changeIndex: this.changeIndex || -1,
|
||||||
version: this.version,
|
version: this.version,
|
||||||
inputs: this.inputs,
|
inputs: this.inputs,
|
||||||
outputs: this.outputs,
|
outputs: this.outputs,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user