pass _network to tx. script debugging. tx filled total.
This commit is contained in:
parent
82983af52b
commit
5791672c07
@ -30,6 +30,7 @@ function Block(data, subtype) {
|
||||
var self = this;
|
||||
this.txs = data.txs || [];
|
||||
this.txs = this.txs.map(function(tx) {
|
||||
tx._network = self._network;
|
||||
tx = bcoin.tx(tx);
|
||||
tx.block = self.hash('hex');
|
||||
tx.ts = tx.ts || self.ts;
|
||||
@ -231,6 +232,8 @@ Block.fromJSON = function fromJSON(json) {
|
||||
parser.parseMerkleBlock(raw) :
|
||||
parser.parseBlock(raw);
|
||||
|
||||
data._network = json._network;
|
||||
|
||||
var block = new Block(data, json.subtype);
|
||||
|
||||
block._hash = json.hash;
|
||||
|
||||
@ -36,6 +36,12 @@ script.decode = function decode(s) {
|
||||
}
|
||||
|
||||
var opcode = constants.opcodesByVal[b];
|
||||
|
||||
if (i >= s.length) {
|
||||
opcodes.push(opcode || b);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (opcode === 'pushdata1') {
|
||||
var len = s[i];
|
||||
i += 1;
|
||||
@ -68,6 +74,8 @@ script.decode = function decode(s) {
|
||||
}
|
||||
}
|
||||
|
||||
utils.hidden(opcodes, '_raw', s);
|
||||
|
||||
return opcodes;
|
||||
};
|
||||
|
||||
@ -1124,8 +1132,7 @@ script.format = function(input, output) {
|
||||
var scripts = [];
|
||||
|
||||
if (input) {
|
||||
var script = input.script;
|
||||
scripts.push(script);
|
||||
scripts.push(input.script);
|
||||
if (input.out.tx && input.out.tx.outputs[input.out.index]) {
|
||||
var prev = input.out.tx.outputs[input.out.index].script;
|
||||
scripts.push(prev);
|
||||
@ -1135,7 +1142,7 @@ script.format = function(input, output) {
|
||||
}
|
||||
}
|
||||
} else if (output) {
|
||||
scripts.push(output);
|
||||
scripts.push(output.script);
|
||||
}
|
||||
|
||||
scripts = scripts.map(function(script) {
|
||||
|
||||
@ -98,6 +98,9 @@ TX.prototype._input = function _input(i, index) {
|
||||
seq: i.seq === undefined ? 0xffffffff : i.seq
|
||||
};
|
||||
|
||||
if (i.script && i.script._raw)
|
||||
utils.hidden(input.script, '_raw', i.script._raw);
|
||||
|
||||
if (input.out.tx) {
|
||||
var prev = input.out.tx.outputs[input.out.index].script;
|
||||
var lock = bcoin.script.lockTime(prev);
|
||||
@ -389,6 +392,9 @@ TX.prototype.output = function output(options, value) {
|
||||
script: options.script ? options.script.slice() : []
|
||||
};
|
||||
|
||||
if (options.script && options.script._raw)
|
||||
utils.hidden(output.script, '_raw', options.script._raw);
|
||||
|
||||
this.outputs.push(output);
|
||||
|
||||
this.scriptOutput(output, options);
|
||||
@ -404,6 +410,9 @@ TX.prototype.scriptOutput = function scriptOutput(output, options) {
|
||||
|
||||
var script = output.script ? output.script.slice() : [];
|
||||
|
||||
if (output.script && output.script._raw)
|
||||
utils.hidden(script, '_raw', output.script._raw);
|
||||
|
||||
if (Array.isArray(options.keys || options.address)) {
|
||||
// Raw multisig transaction
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0010.mediawiki
|
||||
@ -745,6 +754,7 @@ TX.prototype.utxos = function utxos(unspent) {
|
||||
// Still failing to get enough funds
|
||||
if (this.funds('in').cmp(total) < 0) {
|
||||
this.inputs = inputs;
|
||||
this.total = total;
|
||||
this.outputs.pop();
|
||||
return null;
|
||||
}
|
||||
@ -754,6 +764,7 @@ TX.prototype.utxos = function utxos(unspent) {
|
||||
|
||||
// Clear the tx of everything we added.
|
||||
this.inputs = inputs;
|
||||
this.total = total;
|
||||
this.outputs.pop();
|
||||
|
||||
// Return necessary utxos and change.
|
||||
@ -769,8 +780,6 @@ TX.prototype.utxos = function utxos(unspent) {
|
||||
TX.prototype.fillUnspent = function fillUnspent(unspent, changeAddress) {
|
||||
var result = unspent.utxos ? unspent : this.utxos(unspent);
|
||||
|
||||
this.filled = result;
|
||||
|
||||
this.changeAddress = changeAddress || this.changeAddress;
|
||||
|
||||
if (!result)
|
||||
|
||||
@ -535,7 +535,7 @@ Wallet.prototype.fill = function fill(tx, cb) {
|
||||
var result = tx.fillUnspent(this.unspent(), this.getAddress());
|
||||
if (!result) {
|
||||
var err = new Error('Not enough funds');
|
||||
err.minBalance = tx.filled.total;
|
||||
err.minBalance = tx.total;
|
||||
cb(err);
|
||||
return null;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user