fix: initial zcash 5.0 fixes
This commit is contained in:
parent
157137afc0
commit
f56035aa43
2 changed files with 27 additions and 8 deletions
|
|
@ -33,14 +33,18 @@ function checkCryptoCode (cryptoCode) {
|
|||
|
||||
function accountBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ balance }) => new BN(balance).shiftedBy(unitScale).decimalPlaces(0))
|
||||
.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))
|
||||
}
|
||||
|
||||
function accountUnconfirmedBalance (cryptoCode) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => fetch('getwalletinfo'))
|
||||
.then(({ unconfirmed_balance: balance }) => new BN(balance).shiftedBy(unitScale).decimalPlaces(0))
|
||||
.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))
|
||||
}
|
||||
|
||||
// We want a balance that includes all spends (0 conf) but only deposits that
|
||||
|
|
@ -74,7 +78,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', ['ANY_TADDR', [{ address: toAddress, amount: coins }]]))
|
||||
.then(() => fetch('z_sendmany', [defaultAddress(account, { cryptoCode }), [{ address: toAddress, amount: coins }]]))
|
||||
.then(checker)
|
||||
.then((res) => {
|
||||
return {
|
||||
|
|
@ -91,6 +95,14 @@ function sendCoins (account, tx, settings, operatorId) {
|
|||
.catch(errorHandle)
|
||||
}
|
||||
|
||||
function defaultAddress (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, [], 0]))
|
||||
.then(res => res.address)
|
||||
}
|
||||
|
||||
function newAddress (account, info, tx, settings, operatorId) {
|
||||
return checkCryptoCode(info.cryptoCode)
|
||||
.then(() => fetch('z_listaccounts'))
|
||||
|
|
@ -136,13 +148,13 @@ function newFunding (account, cryptoCode, settings, operatorId) {
|
|||
const promises = [
|
||||
accountUnconfirmedBalance(cryptoCode),
|
||||
accountBalance(cryptoCode),
|
||||
newAddress(account, { cryptoCode })
|
||||
defaultAddress(account, { cryptoCode })
|
||||
]
|
||||
|
||||
return Promise.all(promises)
|
||||
})
|
||||
.then(([fundingPendingBalance, fundingConfirmedBalance, fundingAddress]) => ({
|
||||
fundingPendingBalance,
|
||||
.then(([fundingUnconfirmedBalance, fundingConfirmedBalance, fundingAddress]) => ({
|
||||
fundingPendingBalance: new BN(fundingUnconfirmedBalance).minus(fundingConfirmedBalance),
|
||||
fundingConfirmedBalance,
|
||||
fundingAddress
|
||||
}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue