Merge pull request #53 from DanielWeigl/master

Error in serialization for nLockTime values
This commit is contained in:
OutCast3k 2016-08-04 14:04:34 +01:00 committed by GitHub
commit 74a0fad4d2

View file

@ -148,7 +148,7 @@
}
var s = coinjs.script();
s.writeBytes(Crypto.util.hexToBytes(checklocktimeverify.toString(16)).reverse());
s.writeBytes(coinjs.numToByteArray(checklocktimeverify).reverse());
s.writeOp(177);//OP_CHECKLOCKTIMEVERIFY
s.writeOp(117);//OP_DROP
s.writeBytes(Crypto.util.hexToBytes(pubkey));
@ -687,7 +687,7 @@
// ^ <unlocktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> OP_CHECKSIG ^
r = {}
r.pubkey = Crypto.util.bytesToHex(s.chunks[3]);
r.checklocktimeverify = parseInt(Crypto.util.bytesToHex(s.chunks[0].slice().reverse()), 16);
r.checklocktimeverify = coinjs.bytesToNum(s.chunks[0].slice().reverse());
r.address = coinjs.simpleHodlAddress(r.pubkey, r.checklocktimeverify).address;
r.type = "hodl__";
}
@ -1454,6 +1454,14 @@
}
}
coinjs.numToByteArray = function(num) {
if (num <= 256) {
return [num];
} else {
return [num % 256].concat(coinjs.numToByteArray(Math.floor(num / 256)));
}
}
coinjs.numToVarInt = function(num) {
if (num < 253) {
return [num];