script fixes.

This commit is contained in:
Christopher Jeffrey 2016-01-15 19:28:17 -08:00
parent e5a82c7195
commit b1d46206a8
4 changed files with 27 additions and 25 deletions

View File

@ -145,12 +145,6 @@ Peer.prototype._init = function init() {
})); }));
}, this._ping.interval); }, this._ping.interval);
// Send hello
this._write(this.framer.version({
height: this.pool.chain.getStartHeight(),
relay: this.options.relay
}));
this._req('verack', function(err, payload) { this._req('verack', function(err, payload) {
if (err) { if (err) {
self._error(err); self._error(err);
@ -162,6 +156,12 @@ Peer.prototype._init = function init() {
self.ts = utils.now(); self.ts = utils.now();
self._write(self.framer.packet('getaddr', [])); self._write(self.framer.packet('getaddr', []));
}); });
// Send hello
this._write(this.framer.version({
height: this.pool.chain.getStartHeight(),
relay: this.options.relay
}));
}; };
Peer.prototype.broadcast = function broadcast(items) { Peer.prototype.broadcast = function broadcast(items) {

View File

@ -1463,11 +1463,10 @@ Pool.prototype.usableSeed = function usableSeed(addrs, force) {
assert(addrs.length); assert(addrs.length);
addrs = addrs.slice().sort(function() {
return Math.random() > 0.50 ? 1 : -1;
});
if (this.peers.load) { if (this.peers.load) {
addrs = addrs.slice().sort(function() {
return Math.random() > 0.50 ? 1 : -1;
});
for (i = 0; i < addrs.length; i++) { for (i = 0; i < addrs.length; i++) {
if (!this.getPeer(addrs[i])) if (!this.getPeer(addrs[i]))
return addrs[i]; return addrs[i];

View File

@ -285,8 +285,8 @@ script._next = function _next(to, s, pc) {
return -1; return -1;
}; };
script.execute = function execute(s, stack, tx, index, flags, recurse) { script.execute = function execute(data, stack, tx, index, flags, recurse) {
s = s.slice(); var s = data.slice();
if (!flags) if (!flags)
flags = {}; flags = {};
@ -338,7 +338,6 @@ script.execute = function execute(s, stack, tx, index, flags, recurse) {
} }
case 'if_': case 'if_':
case 'notif': { case 'notif': {
val = false;
if (stack.length < 1) if (stack.length < 1)
return false; return false;
v = stack.pop(); v = stack.pop();
@ -468,10 +467,10 @@ script.execute = function execute(s, stack, tx, index, flags, recurse) {
case 'swap': { case 'swap': {
if (stack.length < 2) if (stack.length < 2)
return false; return false;
v2 = stack[stack.length - 2]; v1 = stack[stack.length - 2];
v1 = stack[stack.length - 1]; v2 = stack[stack.length - 1];
stack[stack.length - 2] = v1; stack[stack.length - 2] = v2;
stack[stack.length - 1] = v2; stack[stack.length - 1] = v1;
break; break;
} }
case 'tuck': { case 'tuck': {
@ -490,8 +489,8 @@ script.execute = function execute(s, stack, tx, index, flags, recurse) {
case 'dup2': { case 'dup2': {
if (stack.length < 2) if (stack.length < 2)
return false; return false;
v1 = stack[stack.length - 1]; v1 = stack[stack.length - 2];
v2 = stack[stack.length - 2]; v2 = stack[stack.length - 1];
stack.push(v1); stack.push(v1);
stack.push(v2); stack.push(v2);
break; break;
@ -499,9 +498,9 @@ script.execute = function execute(s, stack, tx, index, flags, recurse) {
case 'dup3': { case 'dup3': {
if (stack.length < 3) if (stack.length < 3)
return false; return false;
v1 = stack[stack.length - 1]; v1 = stack[stack.length - 3];
v2 = stack[stack.length - 2]; v2 = stack[stack.length - 2];
v3 = stack[stack.length - 3]; v3 = stack[stack.length - 1];
stack.push(v1); stack.push(v1);
stack.push(v2); stack.push(v2);
stack.push(v3); stack.push(v3);
@ -751,7 +750,7 @@ script.execute = function execute(s, stack, tx, index, flags, recurse) {
if (!constants.hashTypeByVal[type & 0x1f]) if (!constants.hashTypeByVal[type & 0x1f])
return false; return false;
subscript = script.subscript(s, lastSep); subscript = script.subscript(data, lastSep);
script.removeData(subscript, sig); script.removeData(subscript, sig);
hash = tx.signatureHash(index, subscript, type); hash = tx.signatureHash(index, subscript, type);
@ -796,7 +795,7 @@ script.execute = function execute(s, stack, tx, index, flags, recurse) {
if (stack.length < m + 1) if (stack.length < m + 1)
return false; return false;
subscript = script.subscript(s, lastSep); subscript = script.subscript(data, lastSep);
for (i = 0; i < m; i++) { for (i = 0; i < m; i++) {
sig = stack[stack.length - 1 - i]; sig = stack[stack.length - 1 - i];
@ -804,7 +803,7 @@ script.execute = function execute(s, stack, tx, index, flags, recurse) {
} }
succ = 0; succ = 0;
for (i = 0, j = 0; i < m && j < n; i++) { for (i = 0, j = 0; i < m; i++) {
sig = stack.pop(); sig = stack.pop();
if (!script.isSignature(sig)) if (!script.isSignature(sig))

View File

@ -606,11 +606,15 @@ TX.prototype.getSubscript = function getSubscript(index) {
TX.prototype.signatureHash = function signatureHash(index, s, type) { TX.prototype.signatureHash = function signatureHash(index, s, type) {
var copy = this.clone(); var copy = this.clone();
var i, input, msg, hash; var i, msg, hash;
if (!Array.isArray(s)) { if (!Array.isArray(s)) {
type = s; type = s;
s = this.inputs[index].out.tx.getSubscript(this.inputs[index].out.index); s = this.inputs[index].out.tx.getSubscript(this.inputs[index].out.index);
if (bcoin.script.isScripthash(s)) {
s = this.inputs[index].script[this.inputs[index.script.length - 1]];
s = bcoin.script.subscript(bcoin.script.decode(s));
}
} }
if (typeof index !== 'number') if (typeof index !== 'number')