This commit is contained in:
Christopher Jeffrey 2016-04-08 14:37:51 -07:00
parent 61ea825ffe
commit 7c725c40aa
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
6 changed files with 41 additions and 28 deletions

View File

@ -34,7 +34,7 @@ Docs need to be rewritten. They're coming soon. I promise.
### High-level usage for Node object
``` js
var bcoin = require('bcoin');
var bcoin = require('bcoin')('main');
var node = bcoin.fullnode({
prune: false,
@ -136,8 +136,7 @@ $ node bin/bcoin-cli mempool
### Creating a blockchain and mempool
``` js
var bcoin = require('bcoin');
bcoin.protocol.network.set('regtest');
var bcoin = require('bcoin')('regtest');
var chain = new bcoin.chain({ db: 'memory' });
var mempool = new bcoin.mempool({ chain: chain, db: 'memory' });
var miner = new bcoin.miner({ chain: chain, mempool: mempool });

View File

@ -36,6 +36,7 @@ function ldb(options) {
maxOpenFiles: options.maxOpenFiles || 8192,
filterBits: 0,
paranoidChecks: false,
memory: false,
// For LMDB if we decide to use it:
sync: options.sync || false,

View File

@ -110,25 +110,22 @@ Miner.prototype._init = function _init() {
stat.best);
});
this.chain.open(function(err) {
function done(err) {
if (err)
return self.emit('error', err);
self.loaded = true;
self.emit('open');
});
}
if (this.mempool)
this.mempool.open(done);
else
this.chain.open(done);
};
Miner.prototype.start = function start() {
var self = this;
// Wait for `tip`.
if (!this.chain.tip) {
this.chain.on('tip', function(tip) {
self.start();
});
return;
}
this.stop();
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 attempt;
if (!this.loaded) {
this.open(function(err) {
if (err)
return callback(err);
self.createBlock(callback);
});
return;
}
assert(this.chain.tip);
// Find target
this.chain.getTargetAsync(this.chain.tip, ts, function(err, target) {
if (err)
@ -520,7 +528,6 @@ function rcmp(a, b) {
* Expose
*/
var exports = Miner;
exports.minerblock = MinerBlock;
return exports;
Miner.minerblock = MinerBlock;
return Miner;
};

View File

@ -37,7 +37,7 @@ function MTX(options) {
this.ts = 0;
this.block = null;
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.height = -1;

View File

@ -43,6 +43,13 @@ function Pool(options) {
options.relay = true;
}
if (options.headers == null) {
if (options.spv)
options.headers = true;
else
options.headers = false;
}
seeds = (options.seeds || network.seeds).slice();
if (process.env.BCOIN_SEED)
@ -59,14 +66,6 @@ function Pool(options) {
this.size = options.size || 8;
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.synced = false;
this._scheduled = false;
@ -140,7 +139,7 @@ function Pool(options) {
timeout: options.invTimeout || 60000
};
this.chain.open(function(err) {
function done(err) {
if (err)
return self.emit('error', err);
@ -148,7 +147,12 @@ function Pool(options) {
self.emit('open');
self._init();
});
}
if (this.mempool)
this.mempool.open(done);
else
this.chain.open(done);
}
utils.inherits(Pool, EventEmitter);

View File

@ -40,7 +40,7 @@ function TX(data, block, index) {
this.ts = data.ts || 0;
this.block = data.block || null;
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._hash = null;
@ -1223,7 +1223,9 @@ TX.prototype.inspect = function inspect() {
date: new Date(this.ts * 1000).toISOString(),
block: this.block ? utils.revHex(this.block) : null,
ts: this.ts,
ps: this.ps,
index: this.index,
changeIndex: this.changeIndex || -1,
version: this.version,
inputs: this.inputs,
outputs: this.outputs,