handle reject packet.
This commit is contained in:
parent
135208910d
commit
d109eaba6c
@ -318,7 +318,7 @@ Pool.prototype._addPeer = function _addPeer(backoff) {
|
||||
var result = peer.broadcast(entry.tx);
|
||||
if (!result) return;
|
||||
result[0].once('request', function() {
|
||||
entry.e.emit('ack');
|
||||
entry.e.emit('ack', peer);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -156,6 +156,22 @@ exports.script = {
|
||||
maxOps: 201
|
||||
};
|
||||
|
||||
exports.reject = {
|
||||
malformed: 0x01,
|
||||
invalid: 0x10,
|
||||
obsolete: 0x11,
|
||||
duplicate: 0x12,
|
||||
nonstandard: 0x40,
|
||||
dust: 0x41,
|
||||
insufficientfee: 0x42,
|
||||
checkpoint: 0x43
|
||||
};
|
||||
|
||||
exports.rejectByVal = Object.keys(exports.reject).reduce(function(out, name) {
|
||||
out[exports.reject[name]] = name;
|
||||
return out;
|
||||
}, {});
|
||||
|
||||
exports.locktimeThreshold = 500000000; // Tue Nov 5 00:53:20 1985 UTC
|
||||
|
||||
exports.oneHash = utils.toArray(
|
||||
|
||||
@ -409,10 +409,15 @@ Parser.prototype.parseReject = function parseReject(p) {
|
||||
|
||||
var reason = utils.stringify(p.slice(off, off + reasonLen));
|
||||
|
||||
off += reasonLen;
|
||||
|
||||
var data = p.slice(off, off + 32);
|
||||
|
||||
return {
|
||||
message: message,
|
||||
ccode: ccode,
|
||||
reason: reason
|
||||
ccode: constants.rejectByVal[ccode] || ccode,
|
||||
reason: reason,
|
||||
data: data
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -746,7 +746,6 @@ TX.prototype.utxos = function utxos(unspent) {
|
||||
if (this.funds('in').cmp(total) < 0) {
|
||||
this.inputs = inputs;
|
||||
this.outputs.pop();
|
||||
this.total = total;
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -770,6 +769,8 @@ 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.total;
|
||||
err.minBalance = tx.filled.total;
|
||||
cb(err);
|
||||
return null;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user