Feat: newAddress route

This commit is contained in:
csrapr 2021-03-25 18:47:11 +00:00 committed by Josh Harvey
parent df37bcc519
commit 845c885aad

View file

@ -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)
.then(() => {
return axios.post('/balance', { return axios.post('/balance', {
account, account,
cryptoCode, cryptoCode,
settings, settings,
operatorId operatorId
}).then(({ data }) => { })
})
.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)
.then(() => {
return axios.post('/sendCoins', { return axios.post('/sendCoins', {
account, account,
tx, tx,
settings, settings,
operatorId operatorId
}).then(({ data }) => { })
})
.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)
.then(() => axios.post('/newAddress', {
account, account,
info, info,
tx, tx,
settings, settings,
operatorId operatorId
}).catch(console.error) }))
.then(({ data }) => {
return data.newAddress
})
} }
function newFunding (account, cryptoCode, settings, operatorId) { function newFunding (account, cryptoCode, settings, operatorId) {