code was missing for the segwit feature from the #wallet section

This commit is contained in:
btc
2017-09-20 09:56:20 +00:00
parent 4a4f302fe6
commit ecb18acb0f
4 changed files with 21 additions and 12 deletions
+12 -2
View File
@@ -876,7 +876,7 @@
}
/* add unspent to transaction */
r.addUnspent = function(address, callback, script){
r.addUnspent = function(address, callback, script, segwit){
var self = this;
this.listUnspent(address, function(data){
var s = coinjs.script();
@@ -902,8 +902,18 @@
var n = u.getElementsByTagName("tx_output_n")[0].childNodes[0].nodeValue;
var scr = script || u.getElementsByTagName("script")[0].childNodes[0].nodeValue;
self.addinput(txhash, n, scr);
if(segwit){
/* this is a small hack to include the value with the redeemscript to make the signing procedure smoother.
It is not standard and removed during the signing procedure. */
s = coinjs.script();
s.writeBytes(Crypto.util.hexToBytes(script));
s.writeOp(0);
s.writeBytes(coinjs.numToBytes(u.getElementsByTagName("value")[0].childNodes[0].nodeValue*1, 8));
scr = Crypto.util.bytesToHex(s.buffer);
}
self.addinput(txhash, n, scr);
value += u.getElementsByTagName("value")[0].childNodes[0].nodeValue*1;
total++;
}
+3 -4
View File
@@ -124,7 +124,7 @@ $(document).ready(function() {
var script = false;
if($("#walletSegwit").is(":checked")){
var sw = coinjs.segwitAddress($("#walletKeys .pubkey").val());
scrip = sw.redeemscript;
script = sw.redeemscript;
}
tx.addUnspent($("#walletAddress").html(), function(data){
@@ -148,7 +148,7 @@ $(document).ready(function() {
// and finally broadcast!
tx2.broadcast(function(data){
if($(data).find("result").text()=="1"){
$("#walletSendConfirmStatus").removeClass('hidden').addClass('alert-success').html("txid: "+$(data).find("txid").text());
$("#walletSendConfirmStatus").removeClass('hidden').addClass('alert-success').html('txid: <a href="https://coinb.in/tx/'+$(data).find("txid").text()+'" target="_blank">'+$(data).find("txid").text()+'</a>');
} else {
$("#walletSendConfirmStatus").removeClass('hidden').addClass('alert-danger').html(unescape($(data).find("response").text()).replace(/\+/g,' '));
$("#walletSendFailTransaction").removeClass('hidden');
@@ -167,7 +167,7 @@ $(document).ready(function() {
$("#walletLoader").addClass("hidden");
}, script);
}, script, script);
});
$("#walletSendBtn").click(function(){
@@ -1262,7 +1262,6 @@ $(document).ready(function() {
var tx = coinjs.transaction();
try {
var decode = tx.deserialize($("#verifyScript").val());
// console.log(decode);
$("#verifyTransactionData .transactionVersion").html(decode['version']);
$("#verifyTransactionData .transactionSize").html(decode.size()+' <i>bytes</i>');
$("#verifyTransactionData .transactionLockTime").html(decode['lock_time']);