Fixed formatting.

This commit is contained in:
justmoon 2012-02-07 07:37:58 +01:00
parent 041477918c
commit 795abdce1f

View file

@ -96,23 +96,23 @@
*/ */
Script.prototype.getOutType = function () { Script.prototype.getOutType = function () {
if (this.chunks[this.chunks.length-1] == OP_CHECKMULTISIG && this.chunks[this.chunks.length-2] <= 3) { if (this.chunks[this.chunks.length-1] == OP_CHECKMULTISIG && this.chunks[this.chunks.length-2] <= 3) {
// Transfer to M-OF-N // Transfer to M-OF-N
return 'Multisig'; return 'Multisig';
} else if (this.chunks.length == 5 && } else if (this.chunks.length == 5 &&
this.chunks[0] == OP_DUP && this.chunks[0] == OP_DUP &&
this.chunks[1] == OP_HASH160 && this.chunks[1] == OP_HASH160 &&
this.chunks[3] == OP_EQUALVERIFY && this.chunks[3] == OP_EQUALVERIFY &&
this.chunks[4] == OP_CHECKSIG) { this.chunks[4] == OP_CHECKSIG) {
// Transfer to Bitcoin address // Transfer to Bitcoin address
return 'Address'; return 'Address';
} else if (this.chunks.length == 2 && } else if (this.chunks.length == 2 &&
this.chunks[1] == OP_CHECKSIG) { this.chunks[1] == OP_CHECKSIG) {
// Transfer to IP address // Transfer to IP address
return 'Pubkey'; return 'Pubkey';
} else { } else {
return 'Strange'; return 'Strange';
} }
} }
/** /**
@ -288,46 +288,46 @@
/** /**
* Extract bitcoin addresses from an output script * Extract bitcoin addresses from an output script
*/ */
Script.prototype.extractAddresses = function (addresses) Script.prototype.extractAddresses = function (addresses)
{ {
switch (this.getOutType()) { switch (this.getOutType()) {
case 'Address': case 'Address':
addresses.push(new Address(this.chunks[2])); addresses.push(new Address(this.chunks[2]));
return 1; return 1;
case 'Pubkey': case 'Pubkey':
addresses.push(new Address(Util.sha256ripe160(this.chunks[0]))); addresses.push(new Address(Util.sha256ripe160(this.chunks[0])));
return 1; return 1;
case 'Multisig': case 'Multisig':
for (var i = 1; i < this.chunks.length-2; ++i) { for (var i = 1; i < this.chunks.length-2; ++i) {
addresses.push(new Address(Util.sha256ripe160(this.chunks[i]))); addresses.push(new Address(Util.sha256ripe160(this.chunks[i])));
} }
return this.chunks[0] - OP_1 + 1; return this.chunks[0] - OP_1 + 1;
default: default:
throw new Error("Encountered non-standard scriptPubKey"); throw new Error("Encountered non-standard scriptPubKey");
} }
}; };
/** /**
* Create an m-of-n output script * Create an m-of-n output script
*/ */
Script.createMultiSigOutputScript = function (m, pubkeys) Script.createMultiSigOutputScript = function (m, pubkeys)
{ {
var script = new Bitcoin.Script(); var script = new Bitcoin.Script();
script.writeOp(OP_1 + m - 1); script.writeOp(OP_1 + m - 1);
for (var i = 0; i < pubkeys.length; ++i) { for (var i = 0; i < pubkeys.length; ++i) {
script.writeBytes(pubkeys[i]); script.writeBytes(pubkeys[i]);
} }
script.writeOp(OP_1 + pubkeys.length - 1); script.writeOp(OP_1 + pubkeys.length - 1);
script.writeOp(OP_CHECKMULTISIG); script.writeOp(OP_CHECKMULTISIG);
return script; return script;
} };
/** /**
* Create a standard payToPubKeyHash input. * Create a standard payToPubKeyHash input.