chore: revert sendCoins and cash-out to use transparent addresses

This commit is contained in:
Sérgio Salgado 2022-06-13 19:10:28 +01:00
parent f56035aa43
commit d78e7bb18c

View file

@ -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
}))