feat: support shielded zec sends
This commit is contained in:
parent
7af8079a2a
commit
d1bf6f5f3c
1 changed files with 35 additions and 4 deletions
|
|
@ -52,11 +52,42 @@ function balance (account, cryptoCode) {
|
||||||
|
|
||||||
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
const coins = cryptoAtoms.shift(-unitScale).toFixed(8)
|
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)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
.then(() => fetch('z_sendmany', ["ANY_TADDR", [{address, amount: coins}]]))
|
||||||
.then((txId) => fetch('gettransaction', [txId]))
|
.then(checkSendStatus)
|
||||||
.then((res) => _.pick(['fee', 'txid'], res))
|
.then((res) => {
|
||||||
|
return {
|
||||||
|
fee: _.get('params.fee', res),
|
||||||
|
txid: _.get('result.txid', res)
|
||||||
|
}
|
||||||
|
})
|
||||||
.then((pickedObj) => {
|
.then((pickedObj) => {
|
||||||
return {
|
return {
|
||||||
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue