script hashes.

This commit is contained in:
Christopher Jeffrey 2016-03-26 03:49:45 -07:00
parent 6194c66d8f
commit e5c353f083

View File

@ -55,6 +55,10 @@ Witness.prototype.getInputAddress = function getInputAddress(prev) {
return Script.getInputAddress(this.items, prev, true);
};
Witness.prototype.getInputHash = function getInputHash(prev) {
return Script.getInputHash(this.items, prev, true);
};
Witness.prototype.isPubkeyInput = function isPubkeyInput(key) {
return Script.isPubkeyInput(this.items, key);
};
@ -1406,23 +1410,27 @@ Script.prototype.getLocktime = function getLocktime() {
return { type: 'time', value: locktime };
};
Script.prototype.getInputAddress = function getInputAddress(prev, isWitness) {
Script.prototype.getInputAddress = function getInputAddress(prev) {
return Script.getInputAddress(this.code, prev, false);
};
Script.getInputAddress = function getInputAddress(code, prev, isWitness) {
if (prev)
return prev.getAddress();
if (this.isPubkeyInput())
if (Script.isPubkeyInput(code))
return;
if (this.isPubkeyhashInput()) {
return bcoin.address.compileData(this.code[1],
if (Script.isPubkeyhashInput(code)) {
return bcoin.address.compileData(code[1],
isWitness ? 'witnesspubkeyhash' : 'pubkeyhash');
}
if (this.isMultisigInput(null, isWitness))
if (Script.isMultisigInput(code, null, isWitness))
return;
if (this.isScripthashInput(null, isWitness)) {
return bcoin.address.compileData(this.code[this.code.length - 1],
if (Script.isScripthashInput(code, null, isWitness)) {
return bcoin.address.compileData(code[code.length - 1],
isWitness ? 'witnessscripthash' : 'scripthash');
}
};
@ -1452,6 +1460,53 @@ Script.prototype.getAddress = function getAddress() {
return bcoin.address.compileHash(this.code[1], 'scripthash');
};
Script.prototype.getInputHash = function getInputHash(prev) {
return Script.getInputHash(this.code, prev, false);
};
Script.getInputHash = function getInputHash(prev, isWitness) {
if (prev)
return prev.getHash();
if (Script.isPubkeyInput(code))
return;
if (Script.isPubkeyhashInput(code))
return utils.ripesha(code[1]);
if (Script.isMultisigInput(code, null, isWitness))
return;
if (Script.isScripthashInput(code, null, isWitness)) {
return isWitness
? utils.sha256(code[code.length - 1])
: utils.ripesha(code[code.length - 1]);
}
};
Script.prototype.getHash = function getHash() {
var program;
if (this.isWitnessProgram()) {
program = this.getWitnessProgram();
if (!program.type || program.type === 'unknown')
return;
return program.data;
}
if (this.isPubkey())
return utils.ripesha(this.code[0]);
if (this.isPubkeyhash())
return this.code[2];
if (this.isMultisig())
return utils.ripesha(this.encode());
if (this.isScripthash())
return this.code[1];
};
Script.prototype.isPubkey = function isPubkey(key) {
var res;