script refactor.
This commit is contained in:
parent
08692957c7
commit
6a17599f15
@ -260,8 +260,6 @@ LowlevelUp.prototype.iterate = function iterate(options, callback) {
|
||||
var items = [];
|
||||
var iter, opt;
|
||||
|
||||
assert(this.loaded, 'Cannot use database before it is loaded.');
|
||||
|
||||
opt = {
|
||||
gte: options.gte,
|
||||
lte: options.lte,
|
||||
|
||||
@ -2833,7 +2833,8 @@ Script.prototype.getAddress = function getAddress() {
|
||||
|
||||
Script.prototype.isPubkey = function isPubkey(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[this.raw.length - 1] === opcodes.OP_CHECKSIG;
|
||||
}
|
||||
@ -3174,9 +3175,6 @@ Script.prototype.isMultisigInput = function isMultisigInput() {
|
||||
if (this.code.length < 3)
|
||||
return false;
|
||||
|
||||
if (this.code[0].value !== opcodes.OP_0)
|
||||
return false;
|
||||
|
||||
for (i = 1; i < this.code.length; i++) {
|
||||
if (!Script.isSignature(this.code[i].data))
|
||||
return false;
|
||||
@ -3192,17 +3190,17 @@ Script.prototype.isMultisigInput = function isMultisigInput() {
|
||||
*/
|
||||
|
||||
Script.prototype.isScripthashInput = function isScripthashInput() {
|
||||
var raw;
|
||||
var op;
|
||||
|
||||
if (this.raw.length < 2)
|
||||
return false;
|
||||
|
||||
// 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
|
||||
// for the redeem script.
|
||||
if (!Buffer.isBuffer(raw))
|
||||
if (!op.data)
|
||||
return false;
|
||||
|
||||
// Testing for scripthash inputs requires
|
||||
@ -3214,16 +3212,16 @@ Script.prototype.isScripthashInput = function isScripthashInput() {
|
||||
// key, and we ensure that it is at least
|
||||
// a script that does not use undefined
|
||||
// opcodes.
|
||||
if (Script.isDummy(raw))
|
||||
if (Script.isDummy(op.data))
|
||||
return false;
|
||||
|
||||
if (Script.isSignatureEncoding(raw))
|
||||
if (Script.isSignatureEncoding(op.data))
|
||||
return false;
|
||||
|
||||
if (Script.isKeyEncoding(raw))
|
||||
if (Script.isKeyEncoding(op.data))
|
||||
return false;
|
||||
|
||||
if (!Script.isCode(raw))
|
||||
if (!Script.isCode(op.data))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -3294,23 +3292,23 @@ Script.getCoinbaseHeight = function getCoinbaseHeight(raw) {
|
||||
/**
|
||||
* Get info about a coinbase script.
|
||||
* @returns {Object} Object containing `height`,
|
||||
* `extraNonce`, `flags`, and `text`.
|
||||
* `nonce`, `flags`, and `text`.
|
||||
*/
|
||||
|
||||
Script.prototype.getCoinbaseFlags = function getCoinbaseFlags() {
|
||||
var index = 0;
|
||||
var height = this.getCoinbaseHeight();
|
||||
var extraNonce, flags, text;
|
||||
var index = 0;
|
||||
var nonce, flags, text;
|
||||
|
||||
if (height !== -1)
|
||||
index++;
|
||||
|
||||
extraNonce = this.getNumber(1);
|
||||
nonce = this.getNumber(1);
|
||||
|
||||
if (extraNonce)
|
||||
extraNonce = extraNonce.toNumber();
|
||||
if (nonce)
|
||||
nonce = nonce.toNumber();
|
||||
else
|
||||
extraNonce = -1;
|
||||
nonce = -1;
|
||||
|
||||
flags = Script.encode(this.code.slice(index));
|
||||
|
||||
@ -3319,7 +3317,7 @@ Script.prototype.getCoinbaseFlags = function getCoinbaseFlags() {
|
||||
|
||||
return {
|
||||
height: height,
|
||||
extraNonce: extraNonce,
|
||||
nonce: nonce,
|
||||
flags: flags,
|
||||
text: text
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user