Many small improvements

This commit is contained in:
vub 2013-11-02 06:20:09 -04:00
parent 45ec63d2f1
commit a34bc9e2ea
4 changed files with 45 additions and 39 deletions

6
bitcoinjs-min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -42,7 +42,6 @@ var ECKey = function (input) {
this.compressed = true;
} else {
// hex string?
// Prepend zero byte to prevent interpretation as negative integer
this.priv = BigInteger.fromByteArrayUnsigned(conv.hexToBytes(input));
}
}

View file

@ -121,19 +121,17 @@ Script.prototype.getOutType = function () {
if (this.chunks[this.chunks.length-1] == Opcode.map.OP_CHECKMULTISIG &&
this.chunks[this.chunks.length-2] <= 3) {
// Transfer to M-OF-N
return 'Multisig';
} else if (this.chunks.length == 5 &&
return 'P2SH';
}
else if (this.chunks.length == 5 &&
this.chunks[0] == Opcode.map.OP_DUP &&
this.chunks[1] == Opcode.map.OP_HASH160 &&
this.chunks[3] == Opcode.map.OP_EQUALVERIFY &&
this.chunks[4] == Opcode.map.OP_CHECKSIG) {
// Transfer to Bitcoin address
return 'Address';
} else if (this.chunks.length == 2 &&
this.chunks[1] == Opcode.map.OP_CHECKSIG) {
// Transfer to IP address
return 'Pubkey';
} else {
}
else {
return 'Strange';
}
}
@ -145,9 +143,8 @@ Script.prototype.getOutType = function () {
Script.prototype.toScriptHash = function () {
var outType = this.getOutType();
return outType == 'Address' ? this.chunks[2]
: outType == 'Pubkey' ? util.sha256ripe160(this.chunks[0])
: outType == 'Multisig' ? util.sha256ripe160(this.buffer)
return outType == 'Pubkey' ? this.chunks[2]
: outType == 'P2SH' ? util.sha256ripe160(this.buffer)
: util.sha256ripe160(this.buffer)
};
@ -368,7 +365,7 @@ Script.createMultiSigInputScript = function(signatures, script)
if (signatures.length < k) return false; //Not enough sigs
var inScript = new Script();
inScript.writeOp(Opcode.map.OP_0);
signatures.map(inScript.writeBytes.bind(inScript));
signatures.map(function(sig) { inScript.writeBytes(sig) });
inScript.writeBytes(script.buffer);
return inScript;
}

View file

@ -17,6 +17,9 @@ var Transaction = function (doc) {
this.block = null;
if (doc) {
if (typeof doc == "string" || util.isArray(doc)) {
doc = Transaction.deserialize(doc)
}
if (doc.hash) this.hash = doc.hash;
if (doc.version) this.version = doc.version;
if (doc.lock_time) this.lock_time = doc.lock_time;
@ -412,6 +415,9 @@ Transaction.prototype.calcImpact = function (wallet) {
*/
Transaction.deserialize = function(buffer) {
if (typeof buffer == "string") {
buffer = conv.hexToBytes(buffer)
}
var pos = 0;
var readAsInt = function(bytes) {
if (bytes == 0) return 0;
@ -516,6 +522,10 @@ Transaction.prototype.p2shsign = function(index, script, key, type) {
Transaction.prototype.multisign = Transaction.prototype.p2shsign;
Transaction.prototype.applyMultisigs = function(index, script, sigs, type) {
this.ins[index].script = Script.createMultiSigInputScript(sigs, script);
}
Transaction.prototype.validateSig = function(index, script, sig, pub) {
script = new Script(script);
var hash = this.hashTransactionForSignature(script,index,1);