feat: support shielded zec sends

This commit is contained in:
Neal 2020-11-17 11:26:12 -05:00 committed by Josh Harvey
parent 7af8079a2a
commit d1bf6f5f3c

View file

@ -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(),