From d78e7bb18c152c676a3e71246e84f92986956c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Mon, 13 Jun 2022 19:10:28 +0100 Subject: [PATCH] chore: revert sendCoins and cash-out to use transparent addresses --- lib/plugins/wallet/zcashd/zcashd.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/plugins/wallet/zcashd/zcashd.js b/lib/plugins/wallet/zcashd/zcashd.js index 199ccc6e..26c31b62 100644 --- a/lib/plugins/wallet/zcashd/zcashd.js +++ b/lib/plugins/wallet/zcashd/zcashd.js @@ -33,18 +33,14 @@ function checkCryptoCode (cryptoCode) { function accountBalance (cryptoCode) { return checkCryptoCode(cryptoCode) - .then(() => fetch('z_listaccounts')) - .then(accountsRes => _.isEmpty(accountsRes) ? fetch('z_getnewaccount') : Promise.resolve(_.first(accountsRes))) - .then(account => fetch('z_getbalanceforaccount', [account.account, 1])) - .then(res => new BN(res.pools.transparent.valueZat).plus(res.pools.sapling.valueZat).plus(res.pools.orchard.valueZat)) + .then(() => fetch('getwalletinfo')) + .then(({ balance }) => new BN(balance).shiftedBy(unitScale).decimalPlaces(0)) } function accountUnconfirmedBalance (cryptoCode) { return checkCryptoCode(cryptoCode) - .then(() => fetch('z_listaccounts')) - .then(accountsRes => _.isEmpty(accountsRes) ? fetch('z_getnewaccount') : Promise.resolve(_.first(accountsRes))) - .then(account => fetch('z_getbalanceforaccount', [account.account, 0])) - .then(res => new BN(res.pools.transparent.valueZat).plus(res.pools.sapling.valueZat).plus(res.pools.orchard.valueZat)) + .then(() => fetch('getwalletinfo')) + .then(({ unconfirmed_balance: balance }) => new BN(balance).shiftedBy(unitScale).decimalPlaces(0)) } // We want a balance that includes all spends (0 conf) but only deposits that @@ -78,7 +74,7 @@ function sendCoins (account, tx, settings, operatorId) { const checker = opid => pRetry(() => checkSendStatus(opid), { retries: 20, minTimeout: 300, factor: 1.05 }) return checkCryptoCode(cryptoCode) - .then(() => fetch('z_sendmany', [defaultAddress(account, { cryptoCode }), [{ address: toAddress, amount: coins }]])) + .then(() => fetch('z_sendmany', ['ANY_TADDR', [{ address: toAddress, amount: coins }], null, null, 'NoPrivacy'])) .then(checker) .then((res) => { return { @@ -105,10 +101,7 @@ function defaultAddress (account, info, tx, settings, operatorId) { function newAddress (account, info, tx, settings, operatorId) { return checkCryptoCode(info.cryptoCode) - .then(() => fetch('z_listaccounts')) - .then(accountsRes => _.isEmpty(accountsRes) ? fetch('z_getnewaccount') : Promise.resolve(_.first(accountsRes))) - .then(account => fetch('z_getaddressforaccount', [account.account])) - .then(res => res.address) + .then(() => fetch('getnewaddress')) } function addressBalance (address, confs) { @@ -148,13 +141,13 @@ function newFunding (account, cryptoCode, settings, operatorId) { const promises = [ accountUnconfirmedBalance(cryptoCode), accountBalance(cryptoCode), - defaultAddress(account, { cryptoCode }) + newAddress(account, { cryptoCode }) ] return Promise.all(promises) }) - .then(([fundingUnconfirmedBalance, fundingConfirmedBalance, fundingAddress]) => ({ - fundingPendingBalance: new BN(fundingUnconfirmedBalance).minus(fundingConfirmedBalance), + .then(([fundingPendingBalance, fundingConfirmedBalance, fundingAddress]) => ({ + fundingPendingBalance, fundingConfirmedBalance, fundingAddress }))