Feat: newAddress route
This commit is contained in:
parent
df37bcc519
commit
845c885aad
1 changed files with 31 additions and 23 deletions
|
|
@ -21,45 +21,53 @@ function checkCryptoCode (cryptoCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function balance (account, cryptoCode, settings, operatorId) {
|
function balance (account, cryptoCode, settings, operatorId) {
|
||||||
return checkCryptoCode(cryptoCode).then(() => {
|
return checkCryptoCode(cryptoCode)
|
||||||
return axios.post('/balance', {
|
.then(() => {
|
||||||
account,
|
return axios.post('/balance', {
|
||||||
cryptoCode,
|
account,
|
||||||
settings,
|
cryptoCode,
|
||||||
operatorId
|
settings,
|
||||||
}).then(({ data }) => {
|
operatorId
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(({ data }) => {
|
||||||
if (data.error) throw new Error(JSON.stringify({ errorCode: data.error.errorCode, message: data.error.message }))
|
if (data.error) throw new Error(JSON.stringify({ errorCode: data.error.errorCode, message: data.error.message }))
|
||||||
return BN(data.balance)
|
return BN(data.balance)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendCoins (account, tx, settings, operatorId) {
|
function sendCoins (account, tx, settings, operatorId) {
|
||||||
const { cryptoCode } = tx
|
const { cryptoCode } = tx
|
||||||
return checkCryptoCode(cryptoCode).then(() => {
|
return checkCryptoCode(cryptoCode)
|
||||||
return axios.post('/sendCoins', {
|
.then(() => {
|
||||||
account,
|
return axios.post('/sendCoins', {
|
||||||
tx,
|
account,
|
||||||
settings,
|
tx,
|
||||||
operatorId
|
settings,
|
||||||
}).then(({ data }) => {
|
operatorId
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.then(({ data }) => {
|
||||||
if (data.error && data.error.errorCode === 'sc-001') throw new E.InsufficientFundsError()
|
if (data.error && data.error.errorCode === 'sc-001') throw new E.InsufficientFundsError()
|
||||||
else if (data.error) throw new Error(JSON.stringify({ errorCode: data.error.errorCode, message: data.error.message }))
|
else if (data.error) throw new Error(JSON.stringify({ errorCode: data.error.errorCode, message: data.error.message }))
|
||||||
const fee = BN(data.fee).round()
|
const fee = BN(data.fee).round()
|
||||||
const txid = data.txid
|
const txid = data.txid
|
||||||
return { txid, fee }
|
return { txid, fee }
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (account, info, tx, settings, operatorId) {
|
function newAddress (account, info, tx, settings, operatorId) {
|
||||||
return axios.post('/newAddress', {
|
return checkCryptoCode(info.cryptoCode)
|
||||||
account,
|
.then(() => axios.post('/newAddress', {
|
||||||
info,
|
account,
|
||||||
tx,
|
info,
|
||||||
settings,
|
tx,
|
||||||
operatorId
|
settings,
|
||||||
}).catch(console.error)
|
operatorId
|
||||||
|
}))
|
||||||
|
.then(({ data }) => {
|
||||||
|
return data.newAddress
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function newFunding (account, cryptoCode, settings, operatorId) {
|
function newFunding (account, cryptoCode, settings, operatorId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue