feat: support shielded zec sends
This commit is contained in:
parent
de98ed4c2c
commit
74d3691812
1 changed files with 35 additions and 4 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue