Add full zksnarks tx support

This commit is contained in:
joeuhren
2021-03-21 18:20:49 -06:00
parent d2521a879f
commit 4bef1a17be
4 changed files with 57 additions and 24 deletions
+56 -17
View File
@@ -1082,26 +1082,65 @@ module.exports = {
// check if zksnarks is enabled
if (settings.blockchain_specific.zksnarks.enabled == true) {
// check for hidden/anonymous outputs
vhidden.forEach(function(vanon, i) {
if (vanon.vpub_old > 0) {
module.exports.convert_to_satoshi(parseFloat(vanon.vpub_old), function(amount_sat) {
arr_vout.push({addresses: 'hidden_address', amount: amount_sat});
});
} else {
module.exports.convert_to_satoshi(parseFloat(vanon.vpub_new), function(amount_sat) {
if (vhidden.length > 0 && (!vout || vout.length == 0) && (!vin || vin.length == 0)) {
if (vhidden != null && vhidden.length > 0) {
tx_type = "zksnarks";
// loop through all hidden/anonymous outputs
module.exports.syncLoop(vhidden.length, function (loop) {
var i = loop.iteration();
if (vhidden[i].vpub_old > 0) {
// process vout addresses
processVoutAddresses(['hidden_address'], parseFloat(vhidden[i].vpub_old), arr_vout, function(vout_array) {
// save updated array
arr_vout = vout_array;
// move to next vout
loop.next();
});
} else {
if ((!vout || vout.length == 0) && (!vin || vin.length == 0)) {
// hidden sender is sending to hidden recipient
// the sent and received values are not known in this case. only the fee paid is known and subtracted from the sender.
arr_vout.push({addresses: 'hidden_address', amount: 0});
// process vout addresses
processVoutAddresses(['hidden_address'], 0, arr_vout, function(vout_array) {
// save updated array
arr_vout = vout_array;
// add a private send address with the known amount sent
module.exports.is_unique(arr_vin, 'hidden_address', function(unique, index) {
if (unique == true) {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
// move to next vout
loop.next();
});
} else {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin[index].amount = arr_vin[index].amount + amount_sat;
// move to next vout
loop.next();
});
}
});
});
} else {
module.exports.is_unique(arr_vin, 'hidden_address', function(unique, index) {
if (unique == true) {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
// move to next vout
loop.next();
});
} else {
module.exports.convert_to_satoshi(parseFloat(vhidden[i].vpub_new), function(amount_sat) {
arr_vin[index].amount = arr_vin[index].amount + amount_sat;
// move to next vout
loop.next();
});
}
});
}
// add a private send address with the known amount sent
arr_vin.push({addresses: 'hidden_address', amount: amount_sat});
});
}
tx_type = "zksnarks";
});
}
});
}
}
if (typeof vout[0] !== 'undefined' && vout[0].scriptPubKey.type == 'nonstandard') {