Fix endianess of checklocktimeverify
This commit is contained in:
parent
d53c236ec3
commit
cedc6dddaf
2 changed files with 9 additions and 9 deletions
14
js/coin.js
14
js/coin.js
|
@ -141,14 +141,14 @@
|
|||
|
||||
may throw a string on failure!
|
||||
*/
|
||||
coinjs.simpleHodlAddress = function(pubkey, locktime) {
|
||||
coinjs.simpleHodlAddress = function(pubkey, checklocktimeverify) {
|
||||
|
||||
if(locktime < 0) {
|
||||
throw "Locktime is negative.";
|
||||
if(checklocktimeverify < 0) {
|
||||
throw "Parameter for OP_CHECKLOCKTIMEVERIFY is negative.";
|
||||
}
|
||||
|
||||
var s = coinjs.script();
|
||||
s.writeBytes(Crypto.util.hexToBytes(locktime.toString(16)));
|
||||
s.writeBytes(Crypto.util.hexToBytes(checklocktimeverify.toString(16)).reverse());
|
||||
s.writeOp(177);//OP_CHECKLOCKTIMEVERIFY
|
||||
s.writeOp(117);//OP_DROP
|
||||
s.writeBytes(Crypto.util.hexToBytes(pubkey));
|
||||
|
@ -681,11 +681,11 @@
|
|||
r.address = multi['address'];
|
||||
r.type = 'multisig__'; // using __ for now to differentiat from the other object .type == "multisig"
|
||||
} else if(s.chunks.length == 5 && s.chunks[1] == 177 && s.chunks[2] == 117 && s.chunks[4] == 172){
|
||||
// ^ <locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> OP_CHECKSIG ^
|
||||
// ^ <unlocktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <pubkey> OP_CHECKSIG ^
|
||||
r = {}
|
||||
r.pubkey = Crypto.util.bytesToHex(s.chunks[3]);
|
||||
r.locktime = parseInt(Crypto.util.bytesToHex(s.chunks[0]), 16); // TODO is this endian safe?
|
||||
r.address = coinjs.simpleHodlAddress(r.pubkey, r.locktime).address;
|
||||
r.checklocktimeverify = parseInt(Crypto.util.bytesToHex(s.chunks[0].slice().reverse()), 16);
|
||||
r.address = coinjs.simpleHodlAddress(r.pubkey, r.checklocktimeverify).address;
|
||||
r.type = "hodl__";
|
||||
}
|
||||
} catch(e) {
|
||||
|
|
|
@ -635,7 +635,7 @@ $(document).ready(function() {
|
|||
if($("#redeemFromStatus").hasClass("hidden")) {
|
||||
// An ethical dilemma: Should we automatically set nLockTime?
|
||||
if(redeem.from == 'redeemScript' && redeem.decodedRs.type == "hodl__") {
|
||||
$("#nLockTime").val(redeem.decodedRs.locktime);
|
||||
$("#nLockTime").val(redeem.decodedRs.checklocktimeverify);
|
||||
} else {
|
||||
$("#nLockTime").val(0);
|
||||
}
|
||||
|
@ -1007,7 +1007,7 @@ $(document).ready(function() {
|
|||
var d = $("#verifyRsDataHodl .date").data("DateTimePicker");
|
||||
$("#verifyRsDataHodl .address").val(decode['address']);
|
||||
$("#verifyRsDataHodl .pubkey").val(coinjs.pubkey2address(decode['pubkey']));
|
||||
$("#verifyRsDataHodl .date").val(decode['locktime'] >= 500000000? moment.unix(decode['locktime']).format("MM/DD/YYYY HH:mm") : decode['locktime']);
|
||||
$("#verifyRsDataHodl .date").val(decode['checklocktimeverify'] >= 500000000? moment.unix(decode['checklocktimeverify']).format("MM/DD/YYYY HH:mm") : decode['checklocktimeverify']);
|
||||
$("#verifyRsData").removeClass("hidden");
|
||||
$("#verifyRsDataHodl").removeClass('hidden');
|
||||
$(".verifyLink").attr('href','?verify='+$("#verifyScript").val());
|
||||
|
|
Loading…
Reference in a new issue