consistent naming.
This commit is contained in:
parent
96a92ae29b
commit
af6ac736bf
@ -297,10 +297,10 @@ Address.prototype.scriptInputs = function scriptInputs(tx, index) {
|
|||||||
if (index != null && index !== i)
|
if (index != null && index !== i)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (!self.ownOutput(input.output))
|
if (!self.ownOutput(input.coin))
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (tx.scriptInput(i, self))
|
if (tx.scriptInput(i, self))
|
||||||
@ -323,10 +323,10 @@ Address.prototype.signInputs = function signInputs(tx, type, index) {
|
|||||||
if (index != null && index !== i)
|
if (index != null && index !== i)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (!self.ownOutput(input.output))
|
if (!self.ownOutput(input.coin))
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (tx.signInput(i, self, type))
|
if (tx.signInput(i, self, type))
|
||||||
@ -351,10 +351,10 @@ Address.prototype.sign = function sign(tx, type, index) {
|
|||||||
return total;
|
return total;
|
||||||
|
|
||||||
// Filter inputs that this wallet own
|
// Filter inputs that this wallet own
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (!self.ownOutput(input.output))
|
if (!self.ownOutput(input.coin))
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
if (tx.sign(i, self, type))
|
if (tx.sign(i, self, type))
|
||||||
|
|||||||
@ -645,7 +645,7 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, peer, c
|
|||||||
input = tx.inputs[j];
|
input = tx.inputs[j];
|
||||||
|
|
||||||
// Ensure tx is not double spending an output
|
// Ensure tx is not double spending an output
|
||||||
if (!input.output) {
|
if (!input.coin) {
|
||||||
utils.debug('Block is using spent inputs: %s (tx: %s, output: %s)',
|
utils.debug('Block is using spent inputs: %s (tx: %s, output: %s)',
|
||||||
block.rhash, tx.rhash,
|
block.rhash, tx.rhash,
|
||||||
utils.revHex(input.prevout.hash) + '/' + input.prevout.index);
|
utils.revHex(input.prevout.hash) + '/' + input.prevout.index);
|
||||||
@ -668,13 +668,13 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, peer, c
|
|||||||
block.rhash, tx.rhash, j);
|
block.rhash, tx.rhash, j);
|
||||||
utils.debug(input);
|
utils.debug(input);
|
||||||
utils.debug('Signature Hash v0: %s',
|
utils.debug('Signature Hash v0: %s',
|
||||||
utils.toHex(tx.signatureHash(j, input.output.script, 'all', 0)));
|
utils.toHex(tx.signatureHash(j, input.coin.script, 'all', 0)));
|
||||||
utils.debug('Signature Hash v1: %s',
|
utils.debug('Signature Hash v1: %s',
|
||||||
utils.toHex(tx.signatureHash(j, input.output.script, 'all', 1)));
|
utils.toHex(tx.signatureHash(j, input.coin.script, 'all', 1)));
|
||||||
utils.debug('Raw Script: %s',
|
utils.debug('Raw Script: %s',
|
||||||
utils.toHex(input.output.script.encode()));
|
utils.toHex(input.coin.script.encode()));
|
||||||
utils.debug('Reserialized Script: %s',
|
utils.debug('Reserialized Script: %s',
|
||||||
utils.toHex(input.output.script.clone().encode()));
|
utils.toHex(input.coin.script.clone().encode()));
|
||||||
if (height < network.checkpoints.lastHeight)
|
if (height < network.checkpoints.lastHeight)
|
||||||
throw new Error('BUG: Bad inputs in historical data!');
|
throw new Error('BUG: Bad inputs in historical data!');
|
||||||
return callback(null, false);
|
return callback(null, false);
|
||||||
|
|||||||
@ -587,7 +587,7 @@ ChainDB.prototype.connectBlock = function connectBlock(block, batch, callback) {
|
|||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
|
|
||||||
if (self.options.indexAddress) {
|
if (self.options.indexAddress) {
|
||||||
address = input.getAddress();
|
address = input.getAddress();
|
||||||
@ -659,7 +659,7 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(hash, batch, callba
|
|||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
|
|
||||||
if (self.options.indexAddress) {
|
if (self.options.indexAddress) {
|
||||||
address = input.getAddress();
|
address = input.getAddress();
|
||||||
@ -680,7 +680,7 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(hash, batch, callba
|
|||||||
batch.put('u/t/'
|
batch.put('u/t/'
|
||||||
+ input.prevout.hash
|
+ input.prevout.hash
|
||||||
+ '/' + input.prevout.index,
|
+ '/' + input.prevout.index,
|
||||||
input.output.toRaw());
|
input.coin.toRaw());
|
||||||
});
|
});
|
||||||
|
|
||||||
tx.outputs.forEach(function(output, i) {
|
tx.outputs.forEach(function(output, i) {
|
||||||
@ -708,14 +708,14 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(hash, batch, callba
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype.fillCoin = function fillCoin(tx, callback) {
|
ChainDB.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
callback = utils.asyncify(callback);
|
callback = utils.asyncify(callback);
|
||||||
|
|
||||||
if (Array.isArray(tx)) {
|
if (Array.isArray(tx)) {
|
||||||
return utils.forEachSerial(tx, function(tx, next) {
|
return utils.forEachSerial(tx, function(tx, next) {
|
||||||
self.fillCoin(tx, next);
|
self.fillCoins(tx, next);
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -727,7 +727,7 @@ ChainDB.prototype.fillCoin = function fillCoin(tx, callback) {
|
|||||||
return callback(null, tx);
|
return callback(null, tx);
|
||||||
|
|
||||||
utils.forEachSerial(tx.inputs, function(input, next) {
|
utils.forEachSerial(tx.inputs, function(input, next) {
|
||||||
if (input.output)
|
if (input.coin)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
self.getCoin(input.prevout.hash, input.prevout.index, function(err, coin) {
|
self.getCoin(input.prevout.hash, input.prevout.index, function(err, coin) {
|
||||||
@ -735,7 +735,7 @@ ChainDB.prototype.fillCoin = function fillCoin(tx, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (coin)
|
if (coin)
|
||||||
input.output = coin;
|
input.coin = coin;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -766,7 +766,7 @@ ChainDB.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
|
|
||||||
if (this.prune) {
|
if (this.prune) {
|
||||||
return utils.forEachSerial(tx.inputs, function(input, next) {
|
return utils.forEachSerial(tx.inputs, function(input, next) {
|
||||||
if (input.output)
|
if (input.coin)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
self._getPruneCoin(input.prevout.hash, input.prevout.index, function(err, coin) {
|
self._getPruneCoin(input.prevout.hash, input.prevout.index, function(err, coin) {
|
||||||
@ -774,7 +774,7 @@ ChainDB.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (coin)
|
if (coin)
|
||||||
input.output = coin;
|
input.coin = coin;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -786,7 +786,7 @@ ChainDB.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
utils.forEachSerial(tx.inputs, function(input, next) {
|
utils.forEachSerial(tx.inputs, function(input, next) {
|
||||||
if (input.output)
|
if (input.coin)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
self.getTX(input.prevout.hash, function(err, tx) {
|
self.getTX(input.prevout.hash, function(err, tx) {
|
||||||
@ -794,7 +794,7 @@ ChainDB.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
if (tx)
|
if (tx)
|
||||||
input.output = bcoin.coin(tx, input.prevout.index);
|
input.coin = bcoin.coin(tx, input.prevout.index);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -1076,7 +1076,7 @@ ChainDB.prototype._getTXBlock = function _getTXBlock(hash, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
|
ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
|
||||||
return this.fillCoin(block.txs, function(err) {
|
return this.fillCoins(block.txs, function(err) {
|
||||||
var coins, i, tx, hash, j, input, id;
|
var coins, i, tx, hash, j, input, id;
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
@ -1091,8 +1091,8 @@ ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
|
|||||||
for (j = 0; j < tx.inputs.length; j++) {
|
for (j = 0; j < tx.inputs.length; j++) {
|
||||||
input = tx.inputs[j];
|
input = tx.inputs[j];
|
||||||
id = input.prevout.hash + '/' + input.prevout.index;
|
id = input.prevout.hash + '/' + input.prevout.index;
|
||||||
if (!input.output && coins[id]) {
|
if (!input.coin && coins[id]) {
|
||||||
input.output = coins[id];
|
input.coin = coins[id];
|
||||||
delete coins[id];
|
delete coins[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1121,8 +1121,8 @@ ChainDB.prototype.fillTXBlock = function fillTXBlock(block, callback) {
|
|||||||
for (j = 0; j < tx.inputs.length; j++) {
|
for (j = 0; j < tx.inputs.length; j++) {
|
||||||
input = tx.inputs[j];
|
input = tx.inputs[j];
|
||||||
id = input.prevout.hash + '/' + input.prevout.index;
|
id = input.prevout.hash + '/' + input.prevout.index;
|
||||||
if (!input.output && coins[id]) {
|
if (!input.coin && coins[id]) {
|
||||||
input.output = coins[id];
|
input.coin = coins[id];
|
||||||
delete coins[id];
|
delete coins[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1258,12 +1258,12 @@ ChainDB.prototype._pruneBlock = function _pruneBlock(block, batch, callback) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
tx.inputs.forEach(function(input) {
|
tx.inputs.forEach(function(input) {
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
|
|
||||||
batch.put('u/x/'
|
batch.put('u/x/'
|
||||||
+ input.prevout.hash
|
+ input.prevout.hash
|
||||||
+ '/' + input.prevout.index,
|
+ '/' + input.prevout.index,
|
||||||
input.output.toRaw());
|
input.coin.toRaw());
|
||||||
|
|
||||||
batch.put('u/q/'
|
batch.put('u/q/'
|
||||||
+ futureHeight
|
+ futureHeight
|
||||||
|
|||||||
@ -101,13 +101,13 @@ Coins.prototype.fill = function fill(tx, spend) {
|
|||||||
if (input.prevout.hash !== this.hash)
|
if (input.prevout.hash !== this.hash)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!input.output) {
|
if (!input.coin) {
|
||||||
if (spend)
|
if (spend)
|
||||||
input.output = this.spend(input.prevout.index);
|
input.coin = this.spend(input.prevout.index);
|
||||||
else
|
else
|
||||||
input.output = this.get(input.prevout.index);
|
input.coin = this.get(input.prevout.index);
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -349,17 +349,17 @@ Fullnode.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Fullnode.prototype.fillCoin = function fillCoin(tx, callback) {
|
Fullnode.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.mempool.fillCoin(tx, function(err) {
|
this.mempool.fillCoins(tx, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (tx.hasPrevout())
|
if (tx.hasCoins())
|
||||||
return callback(null, tx);
|
return callback(null, tx);
|
||||||
|
|
||||||
self.chain.db.fillCoin(tx, callback);
|
self.chain.db.fillCoins(tx, callback);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ Fullnode.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (tx.hasPrevout())
|
if (tx.hasCoins())
|
||||||
return callback(null, tx);
|
return callback(null, tx);
|
||||||
|
|
||||||
self.chain.db.fillTX(tx, callback);
|
self.chain.db.fillTX(tx, callback);
|
||||||
|
|||||||
@ -103,7 +103,7 @@ Provider.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
assert(false);
|
assert(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
Provider.prototype.fillCoin = function fillCoin(tx, callback) {
|
Provider.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
assert(false);
|
assert(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -26,8 +26,8 @@ function Input(options, tx) {
|
|||||||
this.witness = options.witness || new bcoin.script.witness([]);
|
this.witness = options.witness || new bcoin.script.witness([]);
|
||||||
this._mutable = !tx || (tx instanceof bcoin.mtx);
|
this._mutable = !tx || (tx instanceof bcoin.mtx);
|
||||||
|
|
||||||
if (options.output)
|
if (options.coin)
|
||||||
this.output = bcoin.coin(options.output);
|
this.coin = bcoin.coin(options.coin);
|
||||||
|
|
||||||
if (Buffer.isBuffer(this.prevout.hash))
|
if (Buffer.isBuffer(this.prevout.hash))
|
||||||
this.prevout.hash = utils.toHex(this.prevout.hash);
|
this.prevout.hash = utils.toHex(this.prevout.hash);
|
||||||
@ -47,8 +47,8 @@ Input.prototype.getType = function getType() {
|
|||||||
if (this.isCoinbase())
|
if (this.isCoinbase())
|
||||||
return 'coinbase';
|
return 'coinbase';
|
||||||
|
|
||||||
if (this.output)
|
if (this.coin)
|
||||||
return this.output.getType();
|
return this.coin.getType();
|
||||||
|
|
||||||
if (this._type)
|
if (this._type)
|
||||||
return this._type;
|
return this._type;
|
||||||
@ -106,8 +106,8 @@ Input.prototype.getAddress = function getAddress() {
|
|||||||
if (this.isCoinbase())
|
if (this.isCoinbase())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.output)
|
if (this.coin)
|
||||||
return this.output.getAddress();
|
return this.coin.getAddress();
|
||||||
|
|
||||||
if (this._address)
|
if (this._address)
|
||||||
return this._address;
|
return this._address;
|
||||||
@ -132,23 +132,6 @@ Input.prototype.isFinal = function isFinal() {
|
|||||||
return this.sequence === 0xffffffff;
|
return this.sequence === 0xffffffff;
|
||||||
};
|
};
|
||||||
|
|
||||||
Input.prototype.getLocktime = function getLocktime() {
|
|
||||||
var output, redeem;
|
|
||||||
|
|
||||||
assert(this.output);
|
|
||||||
|
|
||||||
output = this.output;
|
|
||||||
redeem = output.script;
|
|
||||||
|
|
||||||
if (redeem.isScripthash())
|
|
||||||
redeem = this.script.getRedeem();
|
|
||||||
|
|
||||||
if (redeem[1] !== 'checklocktimeverify')
|
|
||||||
return;
|
|
||||||
|
|
||||||
return redeem.getLocktime();
|
|
||||||
};
|
|
||||||
|
|
||||||
Input.prototype.isCoinbase = function isCoinbase() {
|
Input.prototype.isCoinbase = function isCoinbase() {
|
||||||
return +this.prevout.hash === 0;
|
return +this.prevout.hash === 0;
|
||||||
};
|
};
|
||||||
@ -183,12 +166,12 @@ Input.prototype.getID = function getID() {
|
|||||||
|
|
||||||
Input.prototype.inspect = function inspect() {
|
Input.prototype.inspect = function inspect() {
|
||||||
var redeem = this.getRedeem();
|
var redeem = this.getRedeem();
|
||||||
var output;
|
var coin;
|
||||||
|
|
||||||
if (this.output) {
|
if (this.coin) {
|
||||||
output = this.output.inspect();
|
coin = this.coin.inspect();
|
||||||
} else {
|
} else {
|
||||||
output = {
|
coin = {
|
||||||
type: 'unknown',
|
type: 'unknown',
|
||||||
version: 1,
|
version: 1,
|
||||||
height: -1,
|
height: -1,
|
||||||
@ -205,12 +188,12 @@ Input.prototype.inspect = function inspect() {
|
|||||||
type: this.getType(),
|
type: this.getType(),
|
||||||
subtype: this.getSubtype(),
|
subtype: this.getSubtype(),
|
||||||
address: this.getAddress(),
|
address: this.getAddress(),
|
||||||
value: utils.btc(output.value),
|
value: utils.btc(coin.value),
|
||||||
script: bcoin.script.format(this.script),
|
script: bcoin.script.format(this.script),
|
||||||
witness: bcoin.script.format(this.witness),
|
witness: bcoin.script.format(this.witness),
|
||||||
redeem: redeem ? bcoin.script.format(redeem) : null,
|
redeem: redeem ? bcoin.script.format(redeem) : null,
|
||||||
sequence: this.sequence,
|
sequence: this.sequence,
|
||||||
output: output
|
coin: coin
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -220,7 +203,7 @@ Input.prototype.toJSON = function toJSON() {
|
|||||||
hash: utils.revHex(this.prevout.hash),
|
hash: utils.revHex(this.prevout.hash),
|
||||||
index: this.prevout.index
|
index: this.prevout.index
|
||||||
},
|
},
|
||||||
output: this.output ? this.output.toJSON() : null,
|
coin: this.coin ? this.coin.toJSON() : null,
|
||||||
script: utils.toHex(this.script.encode()),
|
script: utils.toHex(this.script.encode()),
|
||||||
witness: utils.toHex(this.witness.encode()),
|
witness: utils.toHex(this.witness.encode()),
|
||||||
sequence: this.sequence
|
sequence: this.sequence
|
||||||
@ -233,7 +216,7 @@ Input._fromJSON = function _fromJSON(json) {
|
|||||||
hash: utils.revHex(json.prevout.hash),
|
hash: utils.revHex(json.prevout.hash),
|
||||||
index: json.prevout.index
|
index: json.prevout.index
|
||||||
},
|
},
|
||||||
output: json.output ? bcoin.coin._fromJSON(json.output) : null,
|
coin: json.coin ? bcoin.coin._fromJSON(json.coin) : null,
|
||||||
script: new bcoin.script(new Buffer(json.script, 'hex')),
|
script: new bcoin.script(new Buffer(json.script, 'hex')),
|
||||||
witness: new bcoin.script.witness(new Buffer(json.witness, 'hex')),
|
witness: new bcoin.script.witness(new Buffer(json.witness, 'hex')),
|
||||||
sequence: json.sequence
|
sequence: json.sequence
|
||||||
|
|||||||
@ -260,8 +260,8 @@ Mempool.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
return this.tx.fillTX(tx, callback);
|
return this.tx.fillTX(tx, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Mempool.prototype.fillCoin = function fillCoin(tx, callback) {
|
Mempool.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
return this.tx.fillCoin(tx, callback);
|
return this.tx.fillCoins(tx, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Mempool.prototype.has =
|
Mempool.prototype.has =
|
||||||
@ -340,11 +340,11 @@ Mempool.prototype.addTX = function addTX(tx, peer, callback, force) {
|
|||||||
0));
|
0));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.node.fillCoin(tx, function(err) {
|
self.node.fillCoins(tx, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (!tx.hasPrevout()) {
|
if (!tx.hasCoins()) {
|
||||||
if (self.size > Mempool.MAX_MEMPOOL_SIZE) {
|
if (self.size > Mempool.MAX_MEMPOOL_SIZE) {
|
||||||
return callback(new VerifyError(
|
return callback(new VerifyError(
|
||||||
'insufficientfee',
|
'insufficientfee',
|
||||||
@ -458,7 +458,7 @@ Mempool.prototype.verify = function verify(tx, callback) {
|
|||||||
total = new bn(0);
|
total = new bn(0);
|
||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
coin = input.output;
|
coin = input.coin;
|
||||||
|
|
||||||
if (coin.coinbase) {
|
if (coin.coinbase) {
|
||||||
if (self.chain.height - coin.height < constants.tx.coinbaseMaturity) {
|
if (self.chain.height - coin.height < constants.tx.coinbaseMaturity) {
|
||||||
@ -642,7 +642,7 @@ Mempool.prototype.storeOrphan = function storeOrphan(tx, callback, force) {
|
|||||||
|
|
||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
outputs[input.prevout.hash] = true;
|
outputs[input.prevout.hash] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,11 +726,11 @@ Mempool.prototype.resolveOrphans = function resolveOrphans(tx, callback, force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
orphan.inputs.forEach(function(input) {
|
orphan.inputs.forEach(function(input) {
|
||||||
if (!input.output && input.prevout.hash === hash)
|
if (!input.coin && input.prevout.hash === hash)
|
||||||
input.output = bcoin.coin(tx, input.prevout.index);
|
input.coin = bcoin.coin(tx, input.prevout.index);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (orphan.hasPrevout()) {
|
if (orphan.hasCoins()) {
|
||||||
batch.del('m/D/' + orphanHash);
|
batch.del('m/D/' + orphanHash);
|
||||||
return self.verify(orphan, function(err) {
|
return self.verify(orphan, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@ -158,7 +158,7 @@ Miner.prototype.addTX = function addTX(tx) {
|
|||||||
// Cannot calculate fee if we don't have the prev_out.
|
// Cannot calculate fee if we don't have the prev_out.
|
||||||
// Could possibly just burn some coins.
|
// Could possibly just burn some coins.
|
||||||
if (this.options.burn === false) {
|
if (this.options.burn === false) {
|
||||||
if (!tx.hasPrevout())
|
if (!tx.hasCoins())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ Miner.prototype.addTX = function addTX(tx) {
|
|||||||
this.block.txs.push(tx);
|
this.block.txs.push(tx);
|
||||||
|
|
||||||
// Calculate our new reward fee
|
// Calculate our new reward fee
|
||||||
if (tx.hasPrevout())
|
if (tx.hasCoins())
|
||||||
this.fee.iadd(tx.getFee());
|
this.fee.iadd(tx.getFee());
|
||||||
|
|
||||||
// Update coinbase value
|
// Update coinbase value
|
||||||
|
|||||||
112
lib/bcoin/mtx.js
112
lib/bcoin/mtx.js
@ -129,7 +129,7 @@ MTX.prototype.addInput = function addInput(options, index) {
|
|||||||
if (options instanceof bcoin.coin) {
|
if (options instanceof bcoin.coin) {
|
||||||
options = {
|
options = {
|
||||||
prevout: { hash: options.hash, index: options.index },
|
prevout: { hash: options.hash, index: options.index },
|
||||||
output: options
|
coin: options
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ MTX.prototype.scriptInput = function scriptInput(index, addr) {
|
|||||||
assert(input);
|
assert(input);
|
||||||
|
|
||||||
// We should have previous outputs by now.
|
// We should have previous outputs by now.
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
|
|
||||||
// Optimization: Don't bother with any below
|
// Optimization: Don't bother with any below
|
||||||
// calculation if the output is already templated.
|
// calculation if the output is already templated.
|
||||||
@ -174,11 +174,11 @@ MTX.prototype.scriptInput = function scriptInput(index, addr) {
|
|||||||
// address map to avoid unnecessary calculation.
|
// address map to avoid unnecessary calculation.
|
||||||
// A hash table lookup may be faster than all
|
// A hash table lookup may be faster than all
|
||||||
// the nonsense below.
|
// the nonsense below.
|
||||||
if (!addr.ownOutput(input.output))
|
if (!addr.ownOutput(input.coin))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get the previous output's script
|
// Get the previous output's script
|
||||||
prev = input.output.script;
|
prev = input.coin.script;
|
||||||
|
|
||||||
// This is easily the hardest part about building a transaction
|
// This is easily the hardest part about building a transaction
|
||||||
// with segwit: figuring out where the redeem script and witness
|
// with segwit: figuring out where the redeem script and witness
|
||||||
@ -353,10 +353,10 @@ MTX.prototype.signInput = function signInput(index, addr, type) {
|
|||||||
assert(input);
|
assert(input);
|
||||||
|
|
||||||
// We should have previous outputs by now.
|
// We should have previous outputs by now.
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
|
|
||||||
// Get the previous output's subscript
|
// Get the previous output's subscript
|
||||||
prev = input.output.script;
|
prev = input.coin.script;
|
||||||
|
|
||||||
vector = input.script.code;
|
vector = input.script.code;
|
||||||
len = vector.length;
|
len = vector.length;
|
||||||
@ -543,11 +543,11 @@ MTX.prototype.isSigned = function isSigned(m) {
|
|||||||
|
|
||||||
// We can't check for signatures unless
|
// We can't check for signatures unless
|
||||||
// we have the previous output.
|
// we have the previous output.
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get the prevout's subscript
|
// Get the prevout's subscript
|
||||||
prev = input.output.script;
|
prev = input.coin.script;
|
||||||
|
|
||||||
// Script length, needed for multisig
|
// Script length, needed for multisig
|
||||||
vector = input.script.code;
|
vector = input.script.code;
|
||||||
@ -660,7 +660,7 @@ MTX.prototype.addOutput = function addOutput(obj, value) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MTX.prototype.scriptOutput = function scriptOutput(index, options) {
|
MTX.prototype.scriptOutput = function scriptOutput(index, options) {
|
||||||
var output, script, keys, m, n, hash, flags, address, redeem;
|
var output;
|
||||||
|
|
||||||
if (options instanceof bcoin.output)
|
if (options instanceof bcoin.output)
|
||||||
return;
|
return;
|
||||||
@ -696,10 +696,10 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) {
|
|||||||
size = 0;
|
size = 0;
|
||||||
witness = false;
|
witness = false;
|
||||||
|
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
|
|
||||||
// Get the previous output's subscript
|
// Get the previous output's subscript
|
||||||
prev = input.output.script;
|
prev = input.coin.script;
|
||||||
|
|
||||||
// If we have access to the redeem script,
|
// If we have access to the redeem script,
|
||||||
// we can use it to calculate size much easier.
|
// we can use it to calculate size much easier.
|
||||||
@ -793,7 +793,7 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) {
|
|||||||
return total;
|
return total;
|
||||||
};
|
};
|
||||||
|
|
||||||
MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
MTX.prototype.selectCoins = function selectCoins(coins, options) {
|
||||||
var tx = this.clone();
|
var tx = this.clone();
|
||||||
var outputValue = tx.getOutputValue();
|
var outputValue = tx.getOutputValue();
|
||||||
var totalkb = 1;
|
var totalkb = 1;
|
||||||
@ -815,12 +815,12 @@ MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
|||||||
|
|
||||||
if (!options.selection || options.selection === 'age') {
|
if (!options.selection || options.selection === 'age') {
|
||||||
// Oldest unspents first
|
// Oldest unspents first
|
||||||
unspent = unspent.slice().sort(function(a, b) {
|
coins = coins.slice().sort(function(a, b) {
|
||||||
return a.height - b.height;
|
return a.height - b.height;
|
||||||
});
|
});
|
||||||
} else if (options.selection === 'random' || options.selection === 'all') {
|
} else if (options.selection === 'random' || options.selection === 'all') {
|
||||||
// Random unspents
|
// Random unspents
|
||||||
unspent = unspent.slice().sort(function() {
|
coins = coins.slice().sort(function() {
|
||||||
return Math.random() > 0.5 ? 1 : -1;
|
return Math.random() > 0.5 ? 1 : -1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -838,12 +838,12 @@ MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
|||||||
function addCoins() {
|
function addCoins() {
|
||||||
var i, index;
|
var i, index;
|
||||||
|
|
||||||
for (i = lastAdded; i < unspent.length; i++) {
|
for (i = lastAdded; i < coins.length; i++) {
|
||||||
// Add new inputs until MTX will have enough
|
// Add new inputs until MTX will have enough
|
||||||
// funds to cover both minimum post cost
|
// funds to cover both minimum post cost
|
||||||
// and fee.
|
// and fee.
|
||||||
tx.addInput(unspent[i]);
|
tx.addInput(coins[i]);
|
||||||
chosen.push(unspent[i]);
|
chosen.push(coins[i]);
|
||||||
lastAdded++;
|
lastAdded++;
|
||||||
|
|
||||||
if (options.wallet)
|
if (options.wallet)
|
||||||
@ -887,14 +887,20 @@ MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
|||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
newkb = Math.ceil(size / 1024) - totalkb;
|
if (options.accurate) {
|
||||||
fee.iaddn(newkb * minFee);
|
newkb = size / 1024;
|
||||||
totalkb += newkb;
|
fee = new bn(newkb * minFee | 0);
|
||||||
|
totalkb = newkb;
|
||||||
|
} else {
|
||||||
|
newkb = Math.ceil(size / 1024) - totalkb;
|
||||||
|
fee.iaddn(newkb * minFee);
|
||||||
|
totalkb += newkb;
|
||||||
|
}
|
||||||
|
|
||||||
// Failed to get enough funds, add more inputs.
|
// Failed to get enough funds, add more inputs.
|
||||||
if (!isFull())
|
if (!isFull())
|
||||||
addCoins();
|
addCoins();
|
||||||
} while (!isFull() && lastAdded < unspent.length);
|
} while (!isFull() && lastAdded < coins.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFull()) {
|
if (!isFull()) {
|
||||||
@ -937,7 +943,8 @@ MTX.prototype.selectCoins = function selectCoins(unspent, options) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
MTX.prototype.fill = function fill(unspent, options) {
|
MTX.prototype.fill = function fill(coins, options) {
|
||||||
|
var self = this;
|
||||||
var result, err;
|
var result, err;
|
||||||
|
|
||||||
if (!options || typeof options !== 'object') {
|
if (!options || typeof options !== 'object') {
|
||||||
@ -947,10 +954,10 @@ MTX.prototype.fill = function fill(unspent, options) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(unspent);
|
assert(coins);
|
||||||
assert(options.changeAddress);
|
assert(options.changeAddress);
|
||||||
|
|
||||||
result = this.selectCoins(unspent, options);
|
result = this.selectCoins(coins, options);
|
||||||
|
|
||||||
if (!result.coins) {
|
if (!result.coins) {
|
||||||
err = new Error('Could not fill transaction');
|
err = new Error('Could not fill transaction');
|
||||||
@ -959,8 +966,8 @@ MTX.prototype.fill = function fill(unspent, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.coins.forEach(function(coin) {
|
result.coins.forEach(function(coin) {
|
||||||
this.addInput(coin);
|
self.addInput(coin);
|
||||||
}, this);
|
});
|
||||||
|
|
||||||
if (result.change.cmpn(constants.tx.dustThreshold) < 0) {
|
if (result.change.cmpn(constants.tx.dustThreshold) < 0) {
|
||||||
// Do nothing. Change is added to fee.
|
// Do nothing. Change is added to fee.
|
||||||
@ -1014,34 +1021,6 @@ MTX.prototype.sortMembers = function sortMembers() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MTX.prototype.getTargetLocktime = function getTargetLocktime() {
|
|
||||||
var bestValue = 0;
|
|
||||||
var i, locktime, bestType;
|
|
||||||
|
|
||||||
for (i = 0; i < this.inputs.length; i++) {
|
|
||||||
locktime = this.inputs[i].getLocktime();
|
|
||||||
|
|
||||||
if (!locktime)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Incompatible types
|
|
||||||
if (bestType && bestType !== locktime.type)
|
|
||||||
return;
|
|
||||||
|
|
||||||
bestType = locktime.type;
|
|
||||||
|
|
||||||
if (locktime.value < bestValue)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bestValue = locktime.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: bestType || 'height',
|
|
||||||
value: bestValue
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
MTX.prototype.avoidFeeSniping = function avoidFeeSniping(height) {
|
MTX.prototype.avoidFeeSniping = function avoidFeeSniping(height) {
|
||||||
if (height == null) {
|
if (height == null) {
|
||||||
if (!this.chain)
|
if (!this.chain)
|
||||||
@ -1062,34 +1041,13 @@ MTX.prototype.avoidFeeSniping = function avoidFeeSniping(height) {
|
|||||||
MTX.prototype.setLocktime = function setLocktime(locktime) {
|
MTX.prototype.setLocktime = function setLocktime(locktime) {
|
||||||
var i, input;
|
var i, input;
|
||||||
|
|
||||||
this.locktime = locktime;
|
|
||||||
|
|
||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
input = this.inputs[i];
|
input = this.inputs[i];
|
||||||
if (input.sequence === 0xffffffff)
|
if (input.sequence === 0xffffffff)
|
||||||
input.sequence = 0;
|
input.sequence = 0xffffffff - 1;
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
MTX.prototype.increaseFee = function increaseFee(unspent, address, fee) {
|
|
||||||
var i, input;
|
|
||||||
|
|
||||||
this.inputs.length = 0;
|
|
||||||
|
|
||||||
if (this.changeIndex !== -1) {
|
|
||||||
this.outputs.splice(this.changeIndex, 1);
|
|
||||||
this.changeIndex = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fee)
|
this.locktime = locktime;
|
||||||
fee = this.getFee().add(new bn(10000));
|
|
||||||
|
|
||||||
this.fill(unspent, address, fee);
|
|
||||||
|
|
||||||
for (i = 0; i < this.inputs.length; i++) {
|
|
||||||
input = this.inputs[i];
|
|
||||||
input.sequence = 0xffffffff - 1;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MTX._fromJSON = bcoin.tx._fromJSON;
|
MTX._fromJSON = bcoin.tx._fromJSON;
|
||||||
|
|||||||
@ -1233,8 +1233,8 @@ Pool.prototype.isWatched = function(tx, bloom) {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Test the prev_out script
|
// Test the prev_out script
|
||||||
if (input.output) {
|
if (input.coin) {
|
||||||
if (testScript(input.output.script.code))
|
if (testScript(input.coin.script.code))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1376,41 +1376,6 @@ Script.prototype.getSize = function getSize() {
|
|||||||
return this.encode().length;
|
return this.encode().length;
|
||||||
};
|
};
|
||||||
|
|
||||||
Script.prototype._locktime = function _locktime() {
|
|
||||||
if (this.code.length < 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!Buffer.isBuffer(this.code[0]))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.code[1] !== 'checklocktimeverify')
|
|
||||||
return;
|
|
||||||
|
|
||||||
return this.code[0];
|
|
||||||
};
|
|
||||||
|
|
||||||
Script.prototype.isLocktime = function isLocktime() {
|
|
||||||
return this._locktime() != null;
|
|
||||||
};
|
|
||||||
|
|
||||||
Script.prototype.getLocktime = function getLocktime() {
|
|
||||||
var locktime = this._locktime();
|
|
||||||
|
|
||||||
if (!locktime)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
locktime = Script.num(locktime, null, 4).toNumber();
|
|
||||||
} catch (e) {
|
|
||||||
locktime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (locktime < constants.locktimeThreshold)
|
|
||||||
return { type: 'height', value: locktime };
|
|
||||||
|
|
||||||
return { type: 'time', value: locktime };
|
|
||||||
};
|
|
||||||
|
|
||||||
Script.prototype.getInputAddress = function getInputAddress(prev) {
|
Script.prototype.getInputAddress = function getInputAddress(prev) {
|
||||||
return Script.getInputAddress(this.code, prev, false);
|
return Script.getInputAddress(this.code, prev, false);
|
||||||
};
|
};
|
||||||
@ -2238,10 +2203,10 @@ Script.format = function format(code) {
|
|||||||
scripts.push(code.script);
|
scripts.push(code.script);
|
||||||
if (code.witness.length > 0)
|
if (code.witness.length > 0)
|
||||||
scripts.push({ code: code.witness.items });
|
scripts.push({ code: code.witness.items });
|
||||||
if (code.output) {
|
if (code.coin) {
|
||||||
scripts.push(code.output.script);
|
scripts.push(code.coin.script);
|
||||||
if (code.output.script.isScripthash())
|
if (code.coin.script.isScripthash())
|
||||||
scripts.push(code.output.script.getRedeem());
|
scripts.push(code.coin.script.getRedeem());
|
||||||
}
|
}
|
||||||
} else if (code instanceof bcoin.output) {
|
} else if (code instanceof bcoin.output) {
|
||||||
scripts.push(code.script);
|
scripts.push(code.script);
|
||||||
|
|||||||
@ -22,7 +22,7 @@ function TXPool(wallet, txs) {
|
|||||||
|
|
||||||
this._wallet = wallet;
|
this._wallet = wallet;
|
||||||
this._all = {};
|
this._all = {};
|
||||||
this._unspent = {};
|
this._coins = {};
|
||||||
this._orphans = {};
|
this._orphans = {};
|
||||||
this._lastTs = 0;
|
this._lastTs = 0;
|
||||||
this._lastHeight = 0;
|
this._lastHeight = 0;
|
||||||
@ -57,10 +57,10 @@ TXPool.prototype.populate = function populate(txs) {
|
|||||||
TXPool.prototype.add = function add(tx, noWrite) {
|
TXPool.prototype.add = function add(tx, noWrite) {
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
var updated = false;
|
var updated = false;
|
||||||
var i, j, input, output, coin, unspent, orphan;
|
var i, j, input, output, coin, orphan;
|
||||||
var key, orphans, some;
|
var key, orphans, some;
|
||||||
|
|
||||||
this._wallet.fillPrevout(tx);
|
this._wallet.fillCoins(tx);
|
||||||
|
|
||||||
if (!this._wallet.ownInput(tx) && !this._wallet.ownOutput(tx))
|
if (!this._wallet.ownInput(tx) && !this._wallet.ownOutput(tx))
|
||||||
return false;
|
return false;
|
||||||
@ -84,8 +84,8 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
|||||||
this._all[hash].index = tx.index;
|
this._all[hash].index = tx.index;
|
||||||
this._all[hash].outputs.forEach(function(output, i) {
|
this._all[hash].outputs.forEach(function(output, i) {
|
||||||
var key = hash + '/' + i;
|
var key = hash + '/' + i;
|
||||||
if (this._unspent[key])
|
if (this._coins[key])
|
||||||
this._unspent[key].height = tx.height;
|
this._coins[key].height = tx.height;
|
||||||
}, this);
|
}, this);
|
||||||
this._storeTX(hash, tx, noWrite);
|
this._storeTX(hash, tx, noWrite);
|
||||||
this._lastTs = Math.max(tx.ts, this._lastTs);
|
this._lastTs = Math.max(tx.ts, this._lastTs);
|
||||||
@ -102,14 +102,14 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
|||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
key = input.prevout.hash + '/' + input.prevout.index;
|
key = input.prevout.hash + '/' + input.prevout.index;
|
||||||
unspent = this._unspent[key];
|
coin = this._coins[key];
|
||||||
|
|
||||||
if (unspent) {
|
if (coin) {
|
||||||
// Add TX to inputs and spend money
|
// Add TX to inputs and spend money
|
||||||
input.output = unspent;
|
input.coin = coin;
|
||||||
|
|
||||||
assert(input.prevout.hash === unspent.hash);
|
assert(input.prevout.hash === coin.hash);
|
||||||
assert(input.prevout.index === unspent.index);
|
assert(input.prevout.index === coin.index);
|
||||||
|
|
||||||
// Skip invalid transactions
|
// Skip invalid transactions
|
||||||
if (!tx.verify(i))
|
if (!tx.verify(i))
|
||||||
@ -117,7 +117,7 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
|||||||
|
|
||||||
this._addInput(tx, i);
|
this._addInput(tx, i);
|
||||||
|
|
||||||
delete this._unspent[key];
|
delete this._coins[key];
|
||||||
updated = true;
|
updated = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
|||||||
|
|
||||||
for (j = 0; j < orphans.length; j++) {
|
for (j = 0; j < orphans.length; j++) {
|
||||||
orphan = orphans[j];
|
orphan = orphans[j];
|
||||||
orphan.tx.inputs[orphan.index].output = coin;
|
orphan.tx.inputs[orphan.index].coin = coin;
|
||||||
|
|
||||||
assert(orphan.tx.inputs[orphan.index].prevout.hash === hash);
|
assert(orphan.tx.inputs[orphan.index].prevout.hash === hash);
|
||||||
assert(orphan.tx.inputs[orphan.index].prevout.index === i);
|
assert(orphan.tx.inputs[orphan.index].prevout.index === i);
|
||||||
@ -178,7 +178,7 @@ TXPool.prototype.add = function add(tx, noWrite) {
|
|||||||
delete this._orphans[key];
|
delete this._orphans[key];
|
||||||
|
|
||||||
if (!orphans) {
|
if (!orphans) {
|
||||||
this._unspent[key] = coin;
|
this._coins[key] = coin;
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +203,7 @@ TXPool.prototype.getTX = function getTX(hash) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype.getCoin = function getCoin(hash, index) {
|
TXPool.prototype.getCoin = function getCoin(hash, index) {
|
||||||
return this._unspent[hash + '/' + index];
|
return this._coins[hash + '/' + index];
|
||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype._storeTX = function _storeTX(hash, tx, noWrite) {
|
TXPool.prototype._storeTX = function _storeTX(hash, tx, noWrite) {
|
||||||
@ -225,8 +225,8 @@ TXPool.prototype._removeTX = function _removeTX(tx, noWrite) {
|
|||||||
|
|
||||||
for (i = 0; i < tx.outputs.length; i++) {
|
for (i = 0; i < tx.outputs.length; i++) {
|
||||||
key = hash + '/' + i;
|
key = hash + '/' + i;
|
||||||
if (this._unspent[key]) {
|
if (this._coins[key]) {
|
||||||
delete this._unspent[key];
|
delete this._coins[key];
|
||||||
this._removeOutput(tx, i);
|
this._removeOutput(tx, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,13 +259,13 @@ TXPool.prototype.removeTX = function removeTX(hash) {
|
|||||||
|
|
||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
if (!input.output || !this._wallet.ownOutput(input.output))
|
if (!input.coin || !this._wallet.ownOutput(input.coin))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
this._removeInput(input);
|
this._removeInput(input);
|
||||||
|
|
||||||
key = input.prevout.hash + '/' + input.prevout.index;
|
key = input.prevout.hash + '/' + input.prevout.index;
|
||||||
this._unspent[key] = input.output;
|
this._coins[key] = input.coin;
|
||||||
updated = true;
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,8 +297,8 @@ TXPool.prototype.unconfirm = function unconfirm(hash) {
|
|||||||
tx.index = -1;
|
tx.index = -1;
|
||||||
tx.outputs.forEach(function(output, i) {
|
tx.outputs.forEach(function(output, i) {
|
||||||
var key = hash + '/' + i;
|
var key = hash + '/' + i;
|
||||||
if (this._unspent[key])
|
if (this._coins[key])
|
||||||
this._unspent[key].height = -1;
|
this._coins[key].height = -1;
|
||||||
}, this);
|
}, this);
|
||||||
this._storeTX(hash, tx);
|
this._storeTX(hash, tx);
|
||||||
this._lastTs = Math.max(tx.ts, this._lastTs);
|
this._lastTs = Math.max(tx.ts, this._lastTs);
|
||||||
@ -357,12 +357,12 @@ TXPool.prototype._addInput = function _addInput(tx, i, remove) {
|
|||||||
else
|
else
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
|
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
|
|
||||||
if (!this._wallet.ownOutput(input.output))
|
if (!this._wallet.ownOutput(input.coin))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prev = input.output;
|
prev = input.coin;
|
||||||
address = prev.getAddress();
|
address = prev.getAddress();
|
||||||
|
|
||||||
if (!this._addresses[address]) {
|
if (!this._addresses[address]) {
|
||||||
@ -406,12 +406,12 @@ TXPool.prototype.getAll = function getAll(address) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype.getUnspent = function getUnspent(address) {
|
TXPool.prototype.getCoins = function getCoins(address) {
|
||||||
return Object.keys(this._unspent).map(function(key) {
|
return Object.keys(this._coins).map(function(key) {
|
||||||
return this._unspent[key];
|
return this._coins[key];
|
||||||
}, this).filter(function(unspent) {
|
}, this).filter(function(coin) {
|
||||||
if (address) {
|
if (address) {
|
||||||
if (!unspent.test(address))
|
if (!coin.test(address))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -457,23 +457,17 @@ TXPool.prototype.getBalance = function getBalance(address) {
|
|||||||
return this._balance.clone();
|
return this._balance.clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype.getBalanceUnspent = function getBalanceUnspent(address) {
|
TXPool.prototype.getBalanceCoins = function getBalanceCoins(address) {
|
||||||
var acc = new bn(0);
|
var acc = new bn(0);
|
||||||
var unspent = this.getUnspent(address);
|
var coin = this.getCoins(address);
|
||||||
if (unspent.length === 0)
|
if (coin.length === 0)
|
||||||
return acc;
|
return acc;
|
||||||
|
|
||||||
return unspent.reduce(function(acc, coin) {
|
return coin.reduce(function(acc, coin) {
|
||||||
return acc.iadd(coin.value);
|
return acc.iadd(coin.value);
|
||||||
}, acc);
|
}, acc);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Legacy
|
|
||||||
TXPool.prototype.all = TXPool.prototype.getAll;
|
|
||||||
TXPool.prototype.unspent = TXPool.prototype.getUnspent;
|
|
||||||
TXPool.prototype.pending = TXPool.prototype.getPending;
|
|
||||||
TXPool.prototype.balance = TXPool.prototype.getBalance;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
116
lib/bcoin/tx.js
116
lib/bcoin/tx.js
@ -332,7 +332,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, type) {
|
|||||||
p.writeHash(this.inputs[index].prevout.hash);
|
p.writeHash(this.inputs[index].prevout.hash);
|
||||||
p.writeU32(this.inputs[index].prevout.index);
|
p.writeU32(this.inputs[index].prevout.index);
|
||||||
p.writeVarBytes(prev.encode());
|
p.writeVarBytes(prev.encode());
|
||||||
p.write64(this.inputs[index].output.value);
|
p.write64(this.inputs[index].coin.value);
|
||||||
p.writeU32(this.inputs[index].sequence);
|
p.writeU32(this.inputs[index].sequence);
|
||||||
p.writeBytes(hashOutputs);
|
p.writeBytes(hashOutputs);
|
||||||
p.writeU32(this.locktime);
|
p.writeU32(this.locktime);
|
||||||
@ -362,7 +362,7 @@ TX.prototype.verify = function verify(index, force, flags) {
|
|||||||
if (index != null && i !== index)
|
if (index != null && i !== index)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!input.output) {
|
if (!input.coin) {
|
||||||
utils.debug('Warning: Not all outputs available for tx.verify().');
|
utils.debug('Warning: Not all outputs available for tx.verify().');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -370,7 +370,7 @@ TX.prototype.verify = function verify(index, force, flags) {
|
|||||||
return bcoin.script.verify(
|
return bcoin.script.verify(
|
||||||
input.script,
|
input.script,
|
||||||
input.witness,
|
input.witness,
|
||||||
input.output.script,
|
input.coin.script,
|
||||||
this,
|
this,
|
||||||
i,
|
i,
|
||||||
flags
|
flags
|
||||||
@ -396,7 +396,7 @@ TX.prototype.isCoinbase = function isCoinbase() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.getFee = function getFee() {
|
TX.prototype.getFee = function getFee() {
|
||||||
if (!this.hasPrevout())
|
if (!this.hasCoins())
|
||||||
return new bn(0);
|
return new bn(0);
|
||||||
|
|
||||||
return this.getInputValue().sub(this.getOutputValue());
|
return this.getInputValue().sub(this.getOutputValue());
|
||||||
@ -408,11 +408,11 @@ TX.prototype.getInputValue = function getInputValue() {
|
|||||||
if (this.inputs.length === 0)
|
if (this.inputs.length === 0)
|
||||||
return acc;
|
return acc;
|
||||||
|
|
||||||
if (!this.hasPrevout())
|
if (!this.hasCoins())
|
||||||
return acc;
|
return acc;
|
||||||
|
|
||||||
return this.inputs.reduce(function(acc, input) {
|
return this.inputs.reduce(function(acc, input) {
|
||||||
return acc.iadd(input.output.value);
|
return acc.iadd(input.coin.value);
|
||||||
}, acc);
|
}, acc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -549,61 +549,55 @@ TX.prototype.testOutputs = function testOutputs(addressTable, index) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.hasPrevout = function hasPrevout() {
|
TX.prototype.hasCoins = function hasCoins() {
|
||||||
if (this.inputs.length === 0)
|
if (this.inputs.length === 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// if (this.isCoinbase())
|
||||||
|
// return true;
|
||||||
|
|
||||||
return this.inputs.every(function(input) {
|
return this.inputs.every(function(input) {
|
||||||
return !!input.output;
|
return !!input.coin;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.fillPrevout = function fillPrevout(txs, unspent) {
|
TX.prototype.fillCoins = function fillCoins(coins) {
|
||||||
var inputs;
|
var total = 0;
|
||||||
|
var inputs, txs, key, i, input;
|
||||||
|
|
||||||
if (txs instanceof TX) {
|
if (!Array.isArray(coins))
|
||||||
txs = [txs];
|
coins = [coins];
|
||||||
unspent = null;
|
|
||||||
} else if (txs instanceof bcoin.coin) {
|
|
||||||
unspent = [txs];
|
|
||||||
txs = null;
|
|
||||||
} else if (txs instanceof bcoin.txpool) {
|
|
||||||
unspent = txs._unspent;
|
|
||||||
txs = txs._all;
|
|
||||||
} else if (txs instanceof bcoin.wallet && txs.tx) {
|
|
||||||
unspent = txs.tx._unspent;
|
|
||||||
txs = txs.tx._all;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(txs)) {
|
if (Array.isArray(coins)) {
|
||||||
txs = txs.reduce(function(out, tx) {
|
coins = coins.reduce(function(out, coin) {
|
||||||
out[tx.hash('hex')] = tx;
|
if (coin instanceof TX) {
|
||||||
|
out[coin.hash('hex')] = coin;
|
||||||
|
} else {
|
||||||
|
assert(typeof coin.hash === 'string');
|
||||||
|
out[coin.hash + '/' + coin.index] = coin;
|
||||||
|
}
|
||||||
return out;
|
return out;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(unspent)) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
unspent = unspent.reduce(function(out, coin) {
|
input = this.inputs[i];
|
||||||
out[coin.hash + '/' + coin.index] = coin;
|
|
||||||
return out;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
inputs = this.inputs.filter(function(input) {
|
if (!input.coin) {
|
||||||
var key;
|
if (coins[input.prevout.hash]) {
|
||||||
|
input.coin = bcoin.coin(coins[input.prevout.hash], input.prevout.index);
|
||||||
if (!input.output) {
|
} else {
|
||||||
key = input.prevout.hash + '/' + input.prevout.index;
|
key = input.prevout.hash + '/' + input.prevout.index;
|
||||||
if (unspent && unspent[key])
|
if (coins[key])
|
||||||
input.output = unspent[key];
|
input.coin = coins[key];
|
||||||
else if (txs && txs[input.prevout.hash])
|
}
|
||||||
input.output = bcoin.coin(txs[input.prevout.hash], input.prevout.index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return !!input.output;
|
if (input.coin)
|
||||||
}, this);
|
total++;
|
||||||
|
}
|
||||||
|
|
||||||
return inputs.length === this.inputs.length;
|
return total === this.inputs.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
TX.prototype.isFinal = function isFinal(height, ts) {
|
TX.prototype.isFinal = function isFinal(height, ts) {
|
||||||
@ -630,10 +624,10 @@ TX.prototype._getSigops = function _getSigops(scriptHash, accurate) {
|
|||||||
this.inputs.forEach(function(input) {
|
this.inputs.forEach(function(input) {
|
||||||
var prev;
|
var prev;
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prev = input.output.script;
|
prev = input.coin.script;
|
||||||
|
|
||||||
total += input.script.getSigops(accurate);
|
total += input.script.getSigops(accurate);
|
||||||
|
|
||||||
@ -666,10 +660,10 @@ TX.prototype.getSigops = function getSigops(scriptHash, accurate) {
|
|||||||
this.inputs.forEach(function(input) {
|
this.inputs.forEach(function(input) {
|
||||||
var prev;
|
var prev;
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prev = input.output.script;
|
prev = input.coin.script;
|
||||||
|
|
||||||
if (prev.isScripthash())
|
if (prev.isScripthash())
|
||||||
prev = input.script.getRedeem();
|
prev = input.script.getRedeem();
|
||||||
@ -791,10 +785,10 @@ TX.prototype.isStandardInputs = function isStandardInputs(flags) {
|
|||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
input = this.inputs[i];
|
input = this.inputs[i];
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
args = input.output.script.getArgs();
|
args = input.coin.script.getArgs();
|
||||||
|
|
||||||
if (args < 0)
|
if (args < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -813,7 +807,7 @@ TX.prototype.isStandardInputs = function isStandardInputs(flags) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((flags & constants.flags.VERIFY_WITNESS)
|
if ((flags & constants.flags.VERIFY_WITNESS)
|
||||||
&& input.output.isWitnessProgram()) {
|
&& input.coin.isWitnessProgram()) {
|
||||||
hadWitness = true;
|
hadWitness = true;
|
||||||
|
|
||||||
// Input script must be empty.
|
// Input script must be empty.
|
||||||
@ -821,12 +815,12 @@ TX.prototype.isStandardInputs = function isStandardInputs(flags) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Verify the program in the output script
|
// Verify the program in the output script
|
||||||
if (!this.isStandardProgram(input.witness, input.output.script, flags))
|
if (!this.isStandardProgram(input.witness, input.coin.script, flags))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & constants.flags.VERIFY_P2SH)
|
if ((flags & constants.flags.VERIFY_P2SH)
|
||||||
&& input.output.script.isScripthash()) {
|
&& input.coin.script.isScripthash()) {
|
||||||
if (stack.length === 0)
|
if (stack.length === 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -925,7 +919,7 @@ TX.prototype.getPriority = function getPriority(height, size) {
|
|||||||
if (height === -1)
|
if (height === -1)
|
||||||
height = null;
|
height = null;
|
||||||
|
|
||||||
if (!this.hasPrevout())
|
if (!this.hasCoins())
|
||||||
return new bn(0);
|
return new bn(0);
|
||||||
|
|
||||||
if (size == null)
|
if (size == null)
|
||||||
@ -936,10 +930,10 @@ TX.prototype.getPriority = function getPriority(height, size) {
|
|||||||
for (i = 0; i < this.inputs.length; i++) {
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
input = this.inputs[i];
|
input = this.inputs[i];
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return new bn(0);
|
return new bn(0);
|
||||||
|
|
||||||
age = input.output.getConfirmations(height);
|
age = input.coin.getConfirmations(height);
|
||||||
|
|
||||||
if (age === -1)
|
if (age === -1)
|
||||||
age = 0;
|
age = 0;
|
||||||
@ -947,7 +941,7 @@ TX.prototype.getPriority = function getPriority(height, size) {
|
|||||||
if (age !== 0)
|
if (age !== 0)
|
||||||
age += 1;
|
age += 1;
|
||||||
|
|
||||||
sum.iadd(input.output.value.muln(age));
|
sum.iadd(input.coin.value.muln(age));
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum.divn(size);
|
return sum.divn(size);
|
||||||
@ -956,7 +950,7 @@ TX.prototype.getPriority = function getPriority(height, size) {
|
|||||||
TX.prototype.isFree = function isFree(height, size) {
|
TX.prototype.isFree = function isFree(height, size) {
|
||||||
var priority;
|
var priority;
|
||||||
|
|
||||||
if (!this.hasPrevout())
|
if (!this.hasCoins())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (height == null)
|
if (height == null)
|
||||||
@ -1200,12 +1194,12 @@ TX.prototype.toExtended = function toExtended(saveCoins) {
|
|||||||
if (saveCoins) {
|
if (saveCoins) {
|
||||||
p.writeVarint(this.inputs.length);
|
p.writeVarint(this.inputs.length);
|
||||||
this.inputs.forEach(function(input) {
|
this.inputs.forEach(function(input) {
|
||||||
if (!input.output) {
|
if (!input.coin) {
|
||||||
p.writeVarint(0);
|
p.writeVarint(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.writeVarBytes(bcoin.protocol.framer.coin(input.output, false));
|
p.writeVarBytes(bcoin.protocol.framer.coin(input.coin, false));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1249,7 +1243,7 @@ TX._fromExtended = function _fromExtended(buf, saveCoins) {
|
|||||||
coin.hash = tx.inputs[i].prevout.hash;
|
coin.hash = tx.inputs[i].prevout.hash;
|
||||||
coin.index = tx.inputs[i].prevout.index;
|
coin.index = tx.inputs[i].prevout.index;
|
||||||
coin.coinbase = false;
|
coin.coinbase = false;
|
||||||
tx.inputs[i].output = new bcoin.coin(coin);
|
tx.inputs[i].coin = new bcoin.coin(coin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -314,7 +314,7 @@ TXPool.prototype._add = function add(tx, map, callback, force) {
|
|||||||
|
|
||||||
if (coin) {
|
if (coin) {
|
||||||
// Add TX to inputs and spend money
|
// Add TX to inputs and spend money
|
||||||
input.output = coin;
|
input.coin = coin;
|
||||||
|
|
||||||
// Skip invalid transactions
|
// Skip invalid transactions
|
||||||
if (self.options.verify) {
|
if (self.options.verify) {
|
||||||
@ -336,7 +336,7 @@ TXPool.prototype._add = function add(tx, map, callback, force) {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
input.output = null;
|
input.coin = null;
|
||||||
|
|
||||||
self.isSpent(input.prevout.hash, input.prevout.index, function(err, spentBy) {
|
self.isSpent(input.prevout.hash, input.prevout.index, function(err, spentBy) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -352,7 +352,7 @@ TXPool.prototype._add = function add(tx, map, callback, force) {
|
|||||||
if (!prev)
|
if (!prev)
|
||||||
return callback(new Error('Could not find double-spent coin.'));
|
return callback(new Error('Could not find double-spent coin.'));
|
||||||
|
|
||||||
input.output = bcoin.coin(prev, input.prevout.index);
|
input.coin = bcoin.coin(prev, input.prevout.index);
|
||||||
|
|
||||||
// Skip invalid transactions
|
// Skip invalid transactions
|
||||||
if (self.options.verify) {
|
if (self.options.verify) {
|
||||||
@ -422,7 +422,7 @@ TXPool.prototype._add = function add(tx, map, callback, force) {
|
|||||||
if (!orphan.tx)
|
if (!orphan.tx)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
orphan.tx.inputs[orphan.index].output = coin;
|
orphan.tx.inputs[orphan.index].coin = coin;
|
||||||
|
|
||||||
assert(orphan.tx.inputs[orphan.index].prevout.hash === hash);
|
assert(orphan.tx.inputs[orphan.index].prevout.hash === hash);
|
||||||
assert(orphan.tx.inputs[orphan.index].prevout.index === i);
|
assert(orphan.tx.inputs[orphan.index].prevout.index === i);
|
||||||
@ -766,7 +766,7 @@ TXPool.prototype._remove = function remove(tx, map, callback, force) {
|
|||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (self.options.mapAddress) {
|
if (self.options.mapAddress) {
|
||||||
@ -786,7 +786,7 @@ TXPool.prototype._remove = function remove(tx, map, callback, force) {
|
|||||||
batch.put(prefix + 'u/t/'
|
batch.put(prefix + 'u/t/'
|
||||||
+ input.prevout.hash
|
+ input.prevout.hash
|
||||||
+ '/' + input.prevout.index,
|
+ '/' + input.prevout.index,
|
||||||
input.output.toRaw());
|
input.coin.toRaw());
|
||||||
|
|
||||||
batch.del(prefix + 's/t/'
|
batch.del(prefix + 's/t/'
|
||||||
+ input.prevout.hash
|
+ input.prevout.hash
|
||||||
@ -1390,7 +1390,7 @@ TXPool.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
return callback(null, tx);
|
return callback(null, tx);
|
||||||
|
|
||||||
utils.forEach(tx.inputs, function(input, next) {
|
utils.forEach(tx.inputs, function(input, next) {
|
||||||
if (input.output)
|
if (input.coin)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
self.getTX(input.prevout.hash, function(err, tx) {
|
self.getTX(input.prevout.hash, function(err, tx) {
|
||||||
@ -1398,7 +1398,7 @@ TXPool.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
if (tx)
|
if (tx)
|
||||||
input.output = bcoin.coin(tx, input.prevout.index);
|
input.coin = bcoin.coin(tx, input.prevout.index);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -1409,12 +1409,12 @@ TXPool.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
TXPool.prototype.fillCoin = function fillCoin(tx, callback) {
|
TXPool.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (Array.isArray(tx)) {
|
if (Array.isArray(tx)) {
|
||||||
return utils.forEachSerial(tx, function(tx, next) {
|
return utils.forEachSerial(tx, function(tx, next) {
|
||||||
self.fillCoin(tx, function(err) {
|
self.fillCoins(tx, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
@ -1429,7 +1429,7 @@ TXPool.prototype.fillCoin = function fillCoin(tx, callback) {
|
|||||||
return callback(null, tx);
|
return callback(null, tx);
|
||||||
|
|
||||||
utils.forEach(tx.inputs, function(input, next) {
|
utils.forEach(tx.inputs, function(input, next) {
|
||||||
if (input.output)
|
if (input.coin)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
self.getCoin(input.prevout.hash, input.prevout.index, function(err, coin) {
|
self.getCoin(input.prevout.hash, input.prevout.index, function(err, coin) {
|
||||||
@ -1437,7 +1437,7 @@ TXPool.prototype.fillCoin = function fillCoin(tx, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
if (coin)
|
if (coin)
|
||||||
input.output = coin;
|
input.coin = coin;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
@ -1559,7 +1559,7 @@ TXPool.prototype.addUnchecked = function addUnchecked(tx, callback, force) {
|
|||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(input.output);
|
assert(input.coin);
|
||||||
address = input.getAddress();
|
address = input.getAddress();
|
||||||
|
|
||||||
batch.del(prefix + 'u/t/' + key);
|
batch.del(prefix + 'u/t/' + key);
|
||||||
@ -1625,7 +1625,7 @@ TXPool.prototype.removeUnchecked = function removeUnchecked(hash, callback, forc
|
|||||||
if (tx.isCoinbase())
|
if (tx.isCoinbase())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!input.output)
|
if (!input.coin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
address = input.getAddress();
|
address = input.getAddress();
|
||||||
|
|||||||
@ -524,7 +524,7 @@ Wallet.prototype.fill = function fill(tx, options, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.fillPrevout = function fillPrevout(tx, callback) {
|
Wallet.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
if (!this.provider)
|
if (!this.provider)
|
||||||
return callback(new Error('No wallet provider available.'));
|
return callback(new Error('No wallet provider available.'));
|
||||||
|
|
||||||
@ -615,7 +615,7 @@ Wallet.prototype.getInputPaths = function getInputPaths(tx) {
|
|||||||
var i, input, output, address, path;
|
var i, input, output, address, path;
|
||||||
|
|
||||||
if (tx instanceof bcoin.input) {
|
if (tx instanceof bcoin.input) {
|
||||||
path = this.getPath(tx.output.getAddress());
|
path = this.getPath(tx.coin.getAddress());
|
||||||
if (path)
|
if (path)
|
||||||
paths.push(path);
|
paths.push(path);
|
||||||
return paths;
|
return paths;
|
||||||
@ -623,7 +623,7 @@ Wallet.prototype.getInputPaths = function getInputPaths(tx) {
|
|||||||
|
|
||||||
for (i = 0; i < tx.inputs.length; i++) {
|
for (i = 0; i < tx.inputs.length; i++) {
|
||||||
input = tx.inputs[i];
|
input = tx.inputs[i];
|
||||||
output = input.output;
|
output = input.coin;
|
||||||
assert(output);
|
assert(output);
|
||||||
|
|
||||||
address = output.getAddress();
|
address = output.getAddress();
|
||||||
|
|||||||
@ -543,8 +543,8 @@ WalletDB.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
return this.tx.fillTX(tx, callback);
|
return this.tx.fillTX(tx, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.fillCoin = function fillCoin(tx, callback) {
|
WalletDB.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
return this.tx.fillCoin(tx, callback);
|
return this.tx.fillCoins(tx, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletDB.prototype.removeBlockSPV = function removeBlockSPV(block, callback) {
|
WalletDB.prototype.removeBlockSPV = function removeBlockSPV(block, callback) {
|
||||||
@ -708,8 +708,8 @@ Provider.prototype.fillTX = function fillTX(tx, callback) {
|
|||||||
return this.db.fillTX(tx, callback);
|
return this.db.fillTX(tx, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Provider.prototype.fillCoin = function fillCoin(tx, callback) {
|
Provider.prototype.fillCoins = function fillCoins(tx, callback) {
|
||||||
return this.db.fillCoin(tx, callback);
|
return this.db.fillCoins(tx, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Provider.prototype.addTX = function addTX(tx, callback) {
|
Provider.prototype.addTX = function addTX(tx, callback) {
|
||||||
|
|||||||
@ -36,7 +36,7 @@ describe('Wallet', function() {
|
|||||||
hash: constants.oneHash,
|
hash: constants.oneHash,
|
||||||
index: 0
|
index: 0
|
||||||
},
|
},
|
||||||
output: {
|
coin: {
|
||||||
version: 1,
|
version: 1,
|
||||||
height: 0,
|
height: 0,
|
||||||
value: new bn(70000),
|
value: new bn(70000),
|
||||||
@ -82,7 +82,7 @@ describe('Wallet', function() {
|
|||||||
// balance: 11000
|
// balance: 11000
|
||||||
[t2, t3, t4, f1, fake].forEach(function(tx) {
|
[t2, t3, t4, f1, fake].forEach(function(tx) {
|
||||||
tx.inputs.forEach(function(input) {
|
tx.inputs.forEach(function(input) {
|
||||||
delete input.output;
|
delete input.coin;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -49,7 +49,7 @@ describe('TX', function() {
|
|||||||
it('should be verifiable', function() {
|
it('should be verifiable', function() {
|
||||||
var tx = bcoin.tx(parser.parseTX(new Buffer(raw, 'hex')));
|
var tx = bcoin.tx(parser.parseTX(new Buffer(raw, 'hex')));
|
||||||
var p = bcoin.tx(parser.parseTX(new Buffer(inp, 'hex')));
|
var p = bcoin.tx(parser.parseTX(new Buffer(inp, 'hex')));
|
||||||
tx.fillPrevout(p);
|
tx.fillCoins(p);
|
||||||
|
|
||||||
assert(tx.verify());
|
assert(tx.verify());
|
||||||
});
|
});
|
||||||
|
|||||||
@ -9,7 +9,7 @@ var dummyInput = {
|
|||||||
hash: constants.zeroHash,
|
hash: constants.zeroHash,
|
||||||
index: 0
|
index: 0
|
||||||
},
|
},
|
||||||
output: {
|
coin: {
|
||||||
version: 1,
|
version: 1,
|
||||||
height: 0,
|
height: 0,
|
||||||
value: constants.maxMoney.clone(),
|
value: constants.maxMoney.clone(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user