script refactor.

This commit is contained in:
Christopher Jeffrey 2016-07-01 21:02:50 -07:00
parent 08692957c7
commit 6a17599f15
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 17 additions and 21 deletions

View File

@ -260,8 +260,6 @@ LowlevelUp.prototype.iterate = function iterate(options, callback) {
var items = []; var items = [];
var iter, opt; var iter, opt;
assert(this.loaded, 'Cannot use database before it is loaded.');
opt = { opt = {
gte: options.gte, gte: options.gte,
lte: options.lte, lte: options.lte,

View File

@ -2833,7 +2833,8 @@ Script.prototype.getAddress = function getAddress() {
Script.prototype.isPubkey = function isPubkey(minimal) { Script.prototype.isPubkey = function isPubkey(minimal) {
if (minimal) { if (minimal) {
return this.raw[0] >= 33 && this.raw[0] <= 65 return this.raw.length >= 35
&& this.raw[0] >= 33 && this.raw[0] <= 65
&& this.raw[0] + 2 === this.raw.length && this.raw[0] + 2 === this.raw.length
&& this.raw[this.raw.length - 1] === opcodes.OP_CHECKSIG; && this.raw[this.raw.length - 1] === opcodes.OP_CHECKSIG;
} }
@ -3174,9 +3175,6 @@ Script.prototype.isMultisigInput = function isMultisigInput() {
if (this.code.length < 3) if (this.code.length < 3)
return false; return false;
if (this.code[0].value !== opcodes.OP_0)
return false;
for (i = 1; i < this.code.length; i++) { for (i = 1; i < this.code.length; i++) {
if (!Script.isSignature(this.code[i].data)) if (!Script.isSignature(this.code[i].data))
return false; return false;
@ -3192,17 +3190,17 @@ Script.prototype.isMultisigInput = function isMultisigInput() {
*/ */
Script.prototype.isScripthashInput = function isScripthashInput() { Script.prototype.isScripthashInput = function isScripthashInput() {
var raw; var op;
if (this.raw.length < 2) if (this.raw.length < 2)
return false; return false;
// Grab the raw redeem script. // Grab the raw redeem script.
raw = this.code[this.code.length - 1].data; op = this.code[this.code.length - 1];
// Last data element should be an array // Last data element should be an array
// for the redeem script. // for the redeem script.
if (!Buffer.isBuffer(raw)) if (!op.data)
return false; return false;
// Testing for scripthash inputs requires // Testing for scripthash inputs requires
@ -3214,16 +3212,16 @@ Script.prototype.isScripthashInput = function isScripthashInput() {
// key, and we ensure that it is at least // key, and we ensure that it is at least
// a script that does not use undefined // a script that does not use undefined
// opcodes. // opcodes.
if (Script.isDummy(raw)) if (Script.isDummy(op.data))
return false; return false;
if (Script.isSignatureEncoding(raw)) if (Script.isSignatureEncoding(op.data))
return false; return false;
if (Script.isKeyEncoding(raw)) if (Script.isKeyEncoding(op.data))
return false; return false;
if (!Script.isCode(raw)) if (!Script.isCode(op.data))
return false; return false;
return true; return true;
@ -3294,23 +3292,23 @@ Script.getCoinbaseHeight = function getCoinbaseHeight(raw) {
/** /**
* Get info about a coinbase script. * Get info about a coinbase script.
* @returns {Object} Object containing `height`, * @returns {Object} Object containing `height`,
* `extraNonce`, `flags`, and `text`. * `nonce`, `flags`, and `text`.
*/ */
Script.prototype.getCoinbaseFlags = function getCoinbaseFlags() { Script.prototype.getCoinbaseFlags = function getCoinbaseFlags() {
var index = 0;
var height = this.getCoinbaseHeight(); var height = this.getCoinbaseHeight();
var extraNonce, flags, text; var index = 0;
var nonce, flags, text;
if (height !== -1) if (height !== -1)
index++; index++;
extraNonce = this.getNumber(1); nonce = this.getNumber(1);
if (extraNonce) if (nonce)
extraNonce = extraNonce.toNumber(); nonce = nonce.toNumber();
else else
extraNonce = -1; nonce = -1;
flags = Script.encode(this.code.slice(index)); flags = Script.encode(this.code.slice(index));
@ -3319,7 +3317,7 @@ Script.prototype.getCoinbaseFlags = function getCoinbaseFlags() {
return { return {
height: height, height: height,
extraNonce: extraNonce, nonce: nonce,
flags: flags, flags: flags,
text: text text: text
}; };