From d1bf6f5f3c83b682680e044abfca25509eb26e95 Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 17 Nov 2020 11:26:12 -0500 Subject: [PATCH] feat: support shielded zec sends --- lib/plugins/wallet/zcashd/zcashd.js | 39 ++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index c2749e3e..867b4ee7 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -52,11 +52,42 @@ function balance (account, cryptoCode) { function sendCoins (account, address, cryptoAtoms, cryptoCode) { const coins = cryptoAtoms.shift(-unitScale).toFixed(8) - + const checkSendStatus = function (opid) { + return new Promise((resolve, reject) => { + function checker(timeout) { + setTimeout(() => { + fetch('z_getoperationstatus', [[opid]]) + .then(res => { + const status = _.get('status', res[0]) + switch(status) { + case 'success': + resolve(res[0]) + break + case 'failed': + reject(res[0].error) + break + case 'executing': + if (timeout > 0) { + checker(timeout - 500) + } else { + reject(res) + } + } + }) + }, 500) + } + checker(10000) + }) + } return checkCryptoCode(cryptoCode) - .then(() => fetch('sendtoaddress', [address, coins])) - .then((txId) => fetch('gettransaction', [txId])) - .then((res) => _.pick(['fee', 'txid'], res)) + .then(() => fetch('z_sendmany', ["ANY_TADDR", [{address, amount: coins}]])) + .then(checkSendStatus) + .then((res) => { + return { + fee: _.get('params.fee', res), + txid: _.get('result.txid', res) + } + }) .then((pickedObj) => { return { fee: BN(pickedObj.fee).abs().shift(unitScale).round(),