more fixes. cleanup.
This commit is contained in:
parent
e3595906c9
commit
72e907f81e
@ -113,7 +113,7 @@ Block.prototype.getRaw = function getRaw() {
|
||||
};
|
||||
|
||||
Block.prototype._getSize = function _getSize() {
|
||||
var sizes = bcoin.protocol.framer.block._sizes(this);
|
||||
var sizes = bcoin.protocol.framer.block.sizes(this);
|
||||
this._size = sizes.size;
|
||||
this._witnessSize = sizes.witnessSize;
|
||||
};
|
||||
|
||||
@ -28,6 +28,7 @@ function Bloom(size, n, tweak) {
|
||||
this.size = size;
|
||||
this.n = n;
|
||||
this.tweak = tweak;
|
||||
this.update = null;
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
@ -2314,7 +2314,7 @@ Chain.prototype.checkFinal = function checkFinal(prev, tx, flags, callback, forc
|
||||
if (err)
|
||||
return callback(err);
|
||||
|
||||
return callback(null, tx.isFinal(ts, height));
|
||||
return callback(null, tx.isFinal(height, ts));
|
||||
}
|
||||
|
||||
if (flags & constants.flags.MEDIAN_TIME_PAST)
|
||||
|
||||
@ -225,28 +225,6 @@ Coin.fromRaw = function fromRaw(data, enc) {
|
||||
return new Coin(Coin._fromRaw(data, enc));
|
||||
};
|
||||
|
||||
Coin.prototype.toUTXO = function toUTXO(enc) {
|
||||
var data = bcoin.protocol.framer.utxo(this);
|
||||
|
||||
if (enc === 'hex')
|
||||
data = utils.toHex(data);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
Coin._fromUTXO = function _fromUTXO(data, enc) {
|
||||
if (enc === 'hex')
|
||||
data = new Buffer(data, 'hex');
|
||||
|
||||
data = bcoin.protocol.parser.parseUTXO(data);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
Coin.fromUTXO = function fromUTXO(data, enc) {
|
||||
return new Coin(Coin._fromUTXO(data, enc));
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize the coin to an "extended" format,
|
||||
* including both the hash and the index.
|
||||
|
||||
@ -115,9 +115,9 @@ Coins.prototype.remove = function remove(index) {
|
||||
* @returns {Coin}
|
||||
*/
|
||||
|
||||
Coins.prototype.spend = function spend(hash, index) {
|
||||
var coin = this.get(hash, index);
|
||||
this.remove(hash, index);
|
||||
Coins.prototype.spend = function spend(index) {
|
||||
var coin = this.get(index);
|
||||
this.remove(index);
|
||||
return coin;
|
||||
};
|
||||
|
||||
@ -169,7 +169,7 @@ Coins.prototype.fill = function fill(tx, spend) {
|
||||
* @returns {Number} Total.
|
||||
*/
|
||||
|
||||
Coins.prototype.count = function count(index) {
|
||||
Coins.prototype.count = function count() {
|
||||
return this.outputs.reduce(function(total, output) {
|
||||
if (!output)
|
||||
return total;
|
||||
@ -177,10 +177,13 @@ Coins.prototype.count = function count(index) {
|
||||
}, 0);
|
||||
};
|
||||
|
||||
Coins.prototype.forEach = function forEach(callback, context) {
|
||||
this.outputs.forEach(function(output, i) {
|
||||
callback.call(context || this, output, i);
|
||||
}, this);
|
||||
/**
|
||||
* Convert collection to an array.
|
||||
* @returns {Coin[]}
|
||||
*/
|
||||
|
||||
Coins.prototype.toArray = function toArray() {
|
||||
return this.outputs.filter(Boolean);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -91,7 +91,7 @@ CoinView.prototype.count = function count(hash) {
|
||||
|
||||
CoinView.prototype.has = function has(hash, index) {
|
||||
if (!this.coins[hash])
|
||||
return;
|
||||
return false;
|
||||
|
||||
return this.coins[hash].has(index);
|
||||
};
|
||||
|
||||
@ -196,7 +196,9 @@ function Environment(options) {
|
||||
this.coins = require('./coins')(this);
|
||||
this.coinview = require('./coinview')(this);
|
||||
this.tx = require('./tx')(this);
|
||||
this.transaction = this.tx;
|
||||
this.mtx = require('./mtx')(this);
|
||||
this.mutabletransaction = this.mtx;
|
||||
this.txdb = require('./txdb')(this);
|
||||
this.abstractblock = require('./abstractblock')(this);
|
||||
this.compactblock = require('./compactblock')(this);
|
||||
|
||||
@ -110,7 +110,7 @@ Fullnode.prototype._init = function _init() {
|
||||
key: this.options.sslKey,
|
||||
cert: this.options.sslCert,
|
||||
port: this.options.httpPort || 8080,
|
||||
host: '0.0.0.0'
|
||||
host: this.options.httpHost || '0.0.0.0'
|
||||
});
|
||||
|
||||
// Bind to errors
|
||||
|
||||
@ -855,7 +855,7 @@ HDPrivateKey.fromJSON = function fromJSON(json, passphrase) {
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
HDPublicKey.isHDPrivateKey = function isHDPrivateKey(obj) {
|
||||
HDPrivateKey.isHDPrivateKey = function isHDPrivateKey(obj) {
|
||||
return obj && obj.isPrivate && typeof obj.derive === 'function';
|
||||
};
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ Headers.prototype.getSize = function getSize() {
|
||||
|
||||
Headers.prototype.getRaw = function getRaw() {
|
||||
if (!this._raw) {
|
||||
this._raw = bcoin.protocol.framer.headers(this);
|
||||
this._raw = bcoin.protocol.framer.headers([this]);
|
||||
this._size = this._raw.length;
|
||||
}
|
||||
return this._raw;
|
||||
@ -95,7 +95,6 @@ Headers.prototype.inspect = function inspect() {
|
||||
var copy = bcoin.headers(this);
|
||||
copy.__proto__ = null;
|
||||
delete copy._raw;
|
||||
delete copy._chain;
|
||||
copy.hash = this.hash('hex');
|
||||
copy.rhash = this.rhash;
|
||||
copy.date = new Date((copy.ts || 0) * 1000).toISOString();
|
||||
@ -131,7 +130,7 @@ Headers._fromRaw = function _fromRaw(data, enc) {
|
||||
if (enc === 'hex')
|
||||
data = new Buffer(data, 'hex');
|
||||
|
||||
return bcoin.protocol.parser.parseHeaders(data);
|
||||
return bcoin.protocol.parser.parseHeaders(data)[0];
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -335,7 +335,7 @@ Client.prototype.getWallet = function getWallet(id, passphrase, callback) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
json.provider = new bcoin.http.provider(self.url);
|
||||
json.provider = new bcoin.http.provider(self.uri);
|
||||
|
||||
return callback(null, new bcoin.wallet(json));
|
||||
});
|
||||
@ -361,7 +361,7 @@ Client.prototype.createWallet = function createWallet(options, callback) {
|
||||
return callback(e);
|
||||
}
|
||||
|
||||
json.provider = new bcoin.http.provider(self.url);
|
||||
json.provider = new bcoin.http.provider(self.uri);
|
||||
|
||||
return callback(null, new bcoin.wallet(json));
|
||||
});
|
||||
@ -435,7 +435,7 @@ Client.prototype.getWalletPending = function getPending(id, callback) {
|
||||
|
||||
try {
|
||||
body = body.map(function(data) {
|
||||
return bcoin.coin.fromJSON(data);
|
||||
return bcoin.tx.fromJSON(data);
|
||||
});
|
||||
} catch (e) {
|
||||
return callback(e);
|
||||
@ -474,7 +474,7 @@ Client.prototype.getWalletBalance = function getBalance(id, callback) {
|
||||
* @param {Function} callback - Returns [Error, {@link TX}[]].
|
||||
*/
|
||||
|
||||
Client.prototype.getWalletLast = function getLast(id, limit, callback) {
|
||||
Client.prototype.getWalletLast = function getWalletLast(id, limit, callback) {
|
||||
var options = { limit: limit };
|
||||
return this._get('/wallet/' + id + '/tx/last', options, function(err, body) {
|
||||
if (err)
|
||||
|
||||
@ -20,14 +20,14 @@ var Client = bcoin.http.client;
|
||||
* @param {String} uri
|
||||
*/
|
||||
|
||||
function Provider(url) {
|
||||
function Provider(uri) {
|
||||
if (!(this instanceof Provider))
|
||||
return new Provider(url);
|
||||
return new Provider(uri);
|
||||
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.client = new Client(url);
|
||||
this.url = url;
|
||||
this.client = new Client(uri);
|
||||
this.uri = uri;
|
||||
this.id = null;
|
||||
this._init();
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ KeyPair._fromSecret = function _fromSecret(secret) {
|
||||
|
||||
privateKey = p.readBytes(32);
|
||||
|
||||
if (p.left() > 1) {
|
||||
if (p.left() > 4) {
|
||||
assert(p.readU8() === 1);
|
||||
compressed = true;
|
||||
}
|
||||
|
||||
@ -80,7 +80,6 @@ function Mempool(options) {
|
||||
this.relayPriority = this.options.relayPriority !== false;
|
||||
this.requireStandard = this.options.requireStandard !== false;
|
||||
this.rejectInsaneFees = this.options.rejectInsaneFees !== false;
|
||||
this.relay = this.options.relay || false;
|
||||
|
||||
// Use an in-memory binary search tree by default
|
||||
this.backend = this.options.memory === false ? 'leveldb' : 'memory';
|
||||
|
||||
@ -32,7 +32,7 @@ function Output(options, tx) {
|
||||
value = options.value;
|
||||
|
||||
if (typeof value === 'number') {
|
||||
assert(value % 1 === 0);
|
||||
assert(value % 1 === 0, 'Output value cannot be a float.');
|
||||
value = new bn(value);
|
||||
}
|
||||
|
||||
|
||||
@ -296,10 +296,6 @@ Framer.prototype.getBlocks = function getBlocks(data) {
|
||||
return this.packet('getblocks', Framer.getBlocks(data));
|
||||
};
|
||||
|
||||
Framer.prototype.utxo = function _coin(coin) {
|
||||
return this.packet('utxo', Framer.coin(coin, false));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a tx packet with a header.
|
||||
* @param {TX} tx - See {@link Framer.tx}.
|
||||
@ -356,8 +352,8 @@ Framer.prototype.merkleBlock = function merkleBlock(block) {
|
||||
* @returns {Buffer} headers packet.
|
||||
*/
|
||||
|
||||
Framer.prototype.headers = function headers(block) {
|
||||
return this.packet('headers', Framer.headers(block));
|
||||
Framer.prototype.headers = function _headers(headers) {
|
||||
return this.packet('headers', Framer.headers(headers));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -640,26 +636,6 @@ Framer._getBlocks = function _getBlocks(data, writer, headers) {
|
||||
return p;
|
||||
};
|
||||
|
||||
Framer.utxo = function _utxo(coin, writer) {
|
||||
var p = new BufferWriter(writer);
|
||||
var height = coin.height;
|
||||
|
||||
if (height === -1)
|
||||
height = 0x7fffffff;
|
||||
|
||||
assert(coin.value.byteLength() <= 8);
|
||||
|
||||
p.writeU32(coin.version);
|
||||
p.writeU32(height);
|
||||
p.write64(coin.value);
|
||||
Framer.script(coin.script, p);
|
||||
|
||||
if (!writer)
|
||||
p = p.render();
|
||||
|
||||
return p;
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize a coin.
|
||||
* @param {NakedCoin|Coin} coin
|
||||
@ -1361,7 +1337,7 @@ Framer.filterClear = function filterClear() {
|
||||
* @returns {Object} In the form of `{size: Number, witnessSize: Number}`.
|
||||
*/
|
||||
|
||||
Framer.block._sizes = function blockSizes(block) {
|
||||
Framer.block.sizes = function blockSizes(block) {
|
||||
var writer = new BufferWriter();
|
||||
Framer.witnessBlock(block, writer);
|
||||
return {
|
||||
@ -1377,7 +1353,7 @@ Framer.block._sizes = function blockSizes(block) {
|
||||
* @returns {Object} In the form of `{size: Number, witnessSize: Number}`.
|
||||
*/
|
||||
|
||||
Framer.tx._sizes = function txSizes(tx) {
|
||||
Framer.tx.sizes = function txSizes(tx) {
|
||||
var writer = new BufferWriter();
|
||||
Framer.renderTX(tx, true, writer);
|
||||
return {
|
||||
@ -1393,7 +1369,7 @@ Framer.tx._sizes = function txSizes(tx) {
|
||||
*/
|
||||
|
||||
Framer.block.witnessSize = function blockWitnessSize(block) {
|
||||
return Framer.block._sizes(block).size;
|
||||
return Framer.block.sizes(block).size;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1403,7 +1379,7 @@ Framer.block.witnessSize = function blockWitnessSize(block) {
|
||||
*/
|
||||
|
||||
Framer.tx.witnessSize = function txWitnessSize(tx) {
|
||||
return Framer.tx._sizes(tx).size;
|
||||
return Framer.tx.sizes(tx).size;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1437,7 +1413,7 @@ Framer.tx.size = function txSize(tx) {
|
||||
*/
|
||||
|
||||
Framer.block.virtualSize = function blockVirtualSize(block) {
|
||||
var sizes = Framer.block._sizes(block);
|
||||
var sizes = Framer.block.sizes(block);
|
||||
var base = sizes.size - sizes.witnessSize;
|
||||
return (base * 4 + sizes.witnessSize + 3) / 4 | 0;
|
||||
};
|
||||
@ -1449,7 +1425,7 @@ Framer.block.virtualSize = function blockVirtualSize(block) {
|
||||
*/
|
||||
|
||||
Framer.tx.virtualSize = function txVirtualSize(tx) {
|
||||
var sizes = Framer.tx._sizes(tx);
|
||||
var sizes = Framer.tx.sizes(tx);
|
||||
var base = sizes.size - sizes.witnessSize;
|
||||
return (base * 4 + sizes.witnessSize + 3) / 4 | 0;
|
||||
};
|
||||
|
||||
@ -33,7 +33,6 @@ function Parser() {
|
||||
this.pendingTotal = 0;
|
||||
this.waiting = 24;
|
||||
this.packet = null;
|
||||
this.version = constants.minVersion;
|
||||
}
|
||||
|
||||
utils.inherits(Parser, EventEmitter);
|
||||
@ -1032,29 +1031,6 @@ Parser.parseOutput = function parseOutput(p) {
|
||||
};
|
||||
};
|
||||
|
||||
Parser.parseUTXO = function parseUTXO(p) {
|
||||
var version, height, value, script;
|
||||
|
||||
p = new BufferReader(p);
|
||||
p.start();
|
||||
|
||||
version = p.readU32();
|
||||
height = p.readU32();
|
||||
value = p.read64();
|
||||
script = Parser.parseScript(p);
|
||||
|
||||
if (height === 0x7fffffff)
|
||||
height = -1;
|
||||
|
||||
return {
|
||||
version: version,
|
||||
height: height,
|
||||
value: value,
|
||||
script: script,
|
||||
_size: p.end()
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {Object} NakedCoin
|
||||
* @global
|
||||
|
||||
@ -825,7 +825,7 @@ Script.prototype.encode = function encode() {
|
||||
*/
|
||||
|
||||
Script.prototype.getSubscript = function getSubscript(lastSep) {
|
||||
var res = [];
|
||||
var code = [];
|
||||
var i;
|
||||
|
||||
if (lastSep == null)
|
||||
@ -835,18 +835,18 @@ Script.prototype.getSubscript = function getSubscript(lastSep) {
|
||||
|
||||
for (i = lastSep + 1; i < this.code.length; i++) {
|
||||
if (this.code[i] !== opcodes.OP_CODESEPARATOR)
|
||||
res.push(this.code[i]);
|
||||
code.push(this.code[i]);
|
||||
}
|
||||
|
||||
// Optimization: avoid re-rendering
|
||||
// of the script in 99.9% of cases.
|
||||
if (res.length === this.code.length) {
|
||||
res = this.clone();
|
||||
res.raw = this.raw;
|
||||
return res;
|
||||
if (code.length === this.code.length) {
|
||||
code = this.clone();
|
||||
code.raw = this.raw;
|
||||
return code;
|
||||
}
|
||||
|
||||
return new Script(res);
|
||||
return new Script(code);
|
||||
};
|
||||
|
||||
Script.prototype._next = function _next(to, code, ip) {
|
||||
@ -1657,6 +1657,8 @@ Script.array = function(value) {
|
||||
|
||||
Script.prototype.removeData = function removeData(data) {
|
||||
for (var i = this.code.length - 1; i >= 0; i--) {
|
||||
if (!Buffer.isBuffer(this.code[i]))
|
||||
continue;
|
||||
if (utils.isEqual(this.code[i], data))
|
||||
this.code.splice(i, 1);
|
||||
}
|
||||
@ -3452,9 +3454,7 @@ Script.sign = function sign(msg, key, type) {
|
||||
|
||||
// Add the sighash type as a single byte
|
||||
// to the signature.
|
||||
sig = Buffer.concat([sig, new Buffer([type])]);
|
||||
|
||||
return sig;
|
||||
return Buffer.concat([sig, new Buffer([type])]);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -277,7 +277,7 @@ TX.prototype.getRaw = function getRaw() {
|
||||
else
|
||||
raw = bcoin.protocol.framer.tx(this);
|
||||
|
||||
// this._raw = raw;
|
||||
this._raw = raw;
|
||||
this._size = raw.length;
|
||||
this._witnessSize = raw._witnessSize;
|
||||
|
||||
|
||||
@ -776,11 +776,11 @@ Wallet.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||
* @param {Function} callback - Returns [Error, {@link Coin}].
|
||||
*/
|
||||
|
||||
Wallet.prototype.getCoin = function getCoin(id, callback) {
|
||||
Wallet.prototype.getCoin = function getCoin(hash, index, callback) {
|
||||
if (!this.provider)
|
||||
return callback(new Error('No wallet provider available.'));
|
||||
|
||||
return this.provider.getCoin(id, callback);
|
||||
return this.provider.getCoin(hash, index, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -1162,8 +1162,8 @@ Provider.prototype.update = function update(wallet, address) {
|
||||
* @param {Function} callback
|
||||
*/
|
||||
|
||||
Provider.prototype.zap = function zap(wallet, address) {
|
||||
return this.db.zapWallet(wallet, address);
|
||||
Provider.prototype.zap = function zap(now, age, callback) {
|
||||
return this.db.zapWallet(this.id, now, age, callback);
|
||||
};
|
||||
|
||||
WalletDB.Provider = Provider;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user