block and tx getters. coinbase height. multisig input test.
This commit is contained in:
parent
1f8bf8c377
commit
afcb89f76f
@ -61,7 +61,7 @@ function Block(data, subtype) {
|
||||
return tx;
|
||||
});
|
||||
|
||||
if (this.version >= 2) {
|
||||
if (this.version >= 2 && this._height === -1) {
|
||||
tx = this.txs[0];
|
||||
if (tx && tx.inputs[0] && +tx.inputs[0].out.hash === 0) {
|
||||
height = bcoin.script.coinbaseHeight(tx.inputs[0].script, this);
|
||||
@ -337,6 +337,10 @@ Block.prototype.getReward = function getReward() {
|
||||
};
|
||||
};
|
||||
|
||||
Block.prototype.__defineGetter__('rhash', function() {
|
||||
return utils.revHex(this.hash('hex'));
|
||||
});
|
||||
|
||||
Block.prototype.__defineSetter__('height', function(height) {
|
||||
return this._height = height;
|
||||
});
|
||||
@ -349,10 +353,6 @@ Block.prototype.__defineGetter__('nextBlock', function() {
|
||||
return this.getNextBlock(bcoin.chain.global);
|
||||
});
|
||||
|
||||
Block.prototype.__defineGetter__('rhash', function() {
|
||||
return utils.revHex(this.hash('hex'));
|
||||
});
|
||||
|
||||
Block.prototype.__defineGetter__('reward', function() {
|
||||
return this.getReward().reward;
|
||||
});
|
||||
|
||||
@ -213,6 +213,8 @@ Input.getData = function getData(input) {
|
||||
} else if (data.type === 'pubkeyhash') {
|
||||
data.sigs = [sub[0]];
|
||||
data.pubs = [sub[1]];
|
||||
} else if (data.type === 'multisig') {
|
||||
data.sigs = sub.slice(1);
|
||||
} else if (data.type === 'scripthash') {
|
||||
// We work backwards here: scripthash is one of the few cases
|
||||
// where we get more data from the input than the output.
|
||||
@ -225,8 +227,6 @@ Input.getData = function getData(input) {
|
||||
val.value = data.value;
|
||||
val.script = data.script;
|
||||
data = val;
|
||||
} else if (data.type === 'multisig') {
|
||||
data.sigs = sub.slice(1);
|
||||
}
|
||||
return utils.merge(data, {
|
||||
seq: def.seq,
|
||||
@ -257,6 +257,16 @@ Input.getData = function getData(input) {
|
||||
});
|
||||
}
|
||||
|
||||
if (bcoin.script.isMultisigInput(s)) {
|
||||
sig = sub.slice(1);
|
||||
return utils.merge(def, {
|
||||
type: 'multisig',
|
||||
sigs: sig,
|
||||
m: sig.length,
|
||||
none: true
|
||||
});
|
||||
}
|
||||
|
||||
if (bcoin.script.isScripthashInput(s)) {
|
||||
sig = sub.slice(1, -1);
|
||||
redeem = sub[sub.length - 1];
|
||||
@ -279,16 +289,6 @@ Input.getData = function getData(input) {
|
||||
});
|
||||
}
|
||||
|
||||
if (bcoin.script.isMultisigInput(s)) {
|
||||
sig = sub.slice(1);
|
||||
return utils.merge(def, {
|
||||
type: 'multisig',
|
||||
sigs: sig,
|
||||
m: sig.length,
|
||||
none: true
|
||||
});
|
||||
}
|
||||
|
||||
return utils.merge(def, {
|
||||
type: 'unknown',
|
||||
none: true
|
||||
|
||||
@ -900,7 +900,7 @@ script.lockTime = function lockTime(s) {
|
||||
|
||||
// Number can only store 6 & 5/8 bytes
|
||||
if (lock.length > 6)
|
||||
lock = [0x1f].concat(lock.slice(0, 6));
|
||||
lock = lock.slice(0, 6);
|
||||
|
||||
return new bn(lock);
|
||||
};
|
||||
@ -1066,8 +1066,8 @@ script.colored = function colored(s) {
|
||||
script.standardInput = function standardInput(s) {
|
||||
return (script.isPubkeyInput(s) && 'pubkey')
|
||||
|| (script.isPubkeyhashInput(s) && 'pubkeyhash')
|
||||
|| (script.isScripthashInput(s) && 'scripthash')
|
||||
|| (script.isMultisigInput(s) && 'multisig')
|
||||
|| (script.isScripthashInput(s) && 'scripthash')
|
||||
|| null;
|
||||
};
|
||||
|
||||
@ -1116,6 +1116,10 @@ script.isPubkeyhashInput = function isPubkeyhashInput(s, key) {
|
||||
script.isMultisigInput = function isMultisigInput(s, pubs, tx, i) {
|
||||
var i, res, o;
|
||||
|
||||
// We need to rule out scripthash because it may look like multisig
|
||||
if (script.isScripthashInput(s))
|
||||
return false;
|
||||
|
||||
s = script.subscript(s);
|
||||
|
||||
if (s.length < 3)
|
||||
|
||||
@ -60,11 +60,11 @@ function TX(data, block) {
|
||||
}
|
||||
}
|
||||
|
||||
// ps = Pending Since
|
||||
this.ps = this.ts === 0 ? +new Date() / 1000 : 0;
|
||||
|
||||
this.changeAddress = data.changeAddress || null;
|
||||
this.changeOutput = data.changeOutput || null;
|
||||
|
||||
// ps = Pending Since
|
||||
this.ps = this.ts === 0 ? +new Date() / 1000 : 0;
|
||||
}
|
||||
|
||||
TX.fee = 10000;
|
||||
@ -837,18 +837,6 @@ TX.prototype.funds = function funds(side) {
|
||||
return acc;
|
||||
};
|
||||
|
||||
TX.prototype.__defineSetter__('height', function(height) {
|
||||
return this._height = height;
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('height', function() {
|
||||
return this.getHeight(bcoin.chain.global);
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('confirmations', function() {
|
||||
return this.getConfirmations(bcoin.chain.global);
|
||||
});
|
||||
|
||||
TX.prototype.getHeight = function getHeight(chain) {
|
||||
if (this._height >= 0)
|
||||
return this._height;
|
||||
@ -893,6 +881,26 @@ TX.prototype.__defineGetter__('rhash', function() {
|
||||
return utils.revHex(this.hash('hex'));
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('fee', function() {
|
||||
return this.getFee();
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('value', function() {
|
||||
return this.funds('in');
|
||||
});
|
||||
|
||||
TX.prototype.__defineSetter__('height', function(height) {
|
||||
return this._height = height;
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('height', function() {
|
||||
return this.getHeight(bcoin.chain.global);
|
||||
});
|
||||
|
||||
TX.prototype.__defineGetter__('confirmations', function() {
|
||||
return this.getConfirmations(bcoin.chain.global);
|
||||
});
|
||||
|
||||
TX.prototype.inspect = function inspect() {
|
||||
var copy = bcoin.tx(this);
|
||||
copy.__proto__ = null;
|
||||
@ -902,6 +910,8 @@ TX.prototype.inspect = function inspect() {
|
||||
copy.hash = this.hash('hex');
|
||||
copy.rhash = this.rhash;
|
||||
copy.rblock = this.rblock;
|
||||
copy.value = utils.btc(this.value);
|
||||
copy.fee = utils.btc(this.fee);
|
||||
copy.height = this.height;
|
||||
copy.confirmations = this.confirmations;
|
||||
return copy;
|
||||
|
||||
@ -410,12 +410,12 @@ Wallet.prototype.ownInput = function ownInput(tx, index) {
|
||||
if (bcoin.script.isPubkeyhashInput(input.script, key))
|
||||
return true;
|
||||
|
||||
if (bcoin.script.isScripthashInput(input.script, redeem))
|
||||
return true;
|
||||
|
||||
// if (bcoin.script.isMultisigInput(input.script, key, tx, i))
|
||||
// return true;
|
||||
|
||||
if (bcoin.script.isScripthashInput(input.script, redeem))
|
||||
return true;
|
||||
|
||||
if (!input.out.tx)
|
||||
return false;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user