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++;
}