Multisig signTx improvement

- multisig.signTx no longer require tx_hex as argument.
- automatically get the latest available tx_hex from IDB (pipeline chat)
This commit is contained in:
sairajzero 2022-08-16 22:03:18 +05:30
parent b8b58503f6
commit fcd64fe4d4

View File

@ -1034,18 +1034,21 @@
}) })
} }
MultiSig.signTx = function(pipeID, tx_hex) { MultiSig.signTx = function(pipeID) {
return new Promise(async (resolve, reject) => { return new Promise((resolve, reject) => {
if (_loaded.pipeline[pipeID].disabled)
return reject("Pipeline is already closed");
getChat(pipeID).then(async result => {
let pipeline = _loaded.pipeline[pipeID], let pipeline = _loaded.pipeline[pipeID],
tx = coinjs.transaction().deserialize(tx_hex);; tx_hex_latest = Object.keys(result).sort().map(i => result[i].message).filter(x => x).pop();
let privateKey = await floDapps.user.private; let privateKey = await floDapps.user.private;
tx_hex = btcOperator.signTx(tx, privateKey); let tx_hex_signed = btcOperator.signTx(tx_hex_latest, privateKey);
let message = encrypt(tx_hex, pipeline.eKey); let message = encrypt(tx_hex_signed, pipeline.eKey);
sendRaw(message, pipeline.id, "TRANSACTION", false).then(result => { sendRaw(message, pipeline.id, "TRANSACTION", false).then(result => {
if (!btcOperator.checkSigned(tx)) if (!btcOperator.checkSigned(tx_hex_signed))
return resolve(tx_hex); return resolve(tx_hex_signed);
debugger; debugger;
btcOperator.broadcast(tx_hex).then(result => { btcOperator.broadcast(tx_hex_signed).then(result => {
let txid = result.txid; let txid = result.txid;
console.debug(txid); console.debug(txid);
sendRaw(encrypt(txid, pipeline.eKey), pipeline.id, "BROADCAST", false) sendRaw(encrypt(txid, pipeline.eKey), pipeline.id, "BROADCAST", false)
@ -1053,6 +1056,7 @@
.catch(error => reject(error)) .catch(error => reject(error))
}).catch(error => reject(error)) }).catch(error => reject(error))
}).catch(error => reject(error)) }).catch(error => reject(error))
}).catch(error => console.error(error))
}) })
} }