Feat: sendcoins pazuz
This commit is contained in:
parent
ee9f4a766e
commit
800d09dd71
1 changed files with 34 additions and 11 deletions
|
|
@ -1,15 +1,25 @@
|
||||||
const axios_ = require('axios')
|
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
|
const BN = require('../../../bn')
|
||||||
|
const E = require('../../../error')
|
||||||
|
|
||||||
const URL = 'https://localhost:5555/api/'
|
const axios = require('axios').create({
|
||||||
|
// TODO: get rejectUnauthorized true to work
|
||||||
const axios = axios_.create({
|
baseURL: 'https://localhost:5555/api/',
|
||||||
baseURL: URL,
|
|
||||||
httpsAgent: new https.Agent({
|
httpsAgent: new https.Agent({
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const SUPPORTED_COINS = ['BTC']
|
||||||
|
|
||||||
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
if (!SUPPORTED_COINS.includes(cryptoCode)) {
|
||||||
|
return Promise.reject(new Error('Unsupported crypto: ' + cryptoCode))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
function balance (account, cryptoCode, settings, operatorId) {
|
function balance (account, cryptoCode, settings, operatorId) {
|
||||||
return axios.post('/balance', {
|
return axios.post('/balance', {
|
||||||
account,
|
account,
|
||||||
|
|
@ -20,12 +30,25 @@ function balance (account, cryptoCode, settings, operatorId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendCoins (account, tx, settings, operatorId) {
|
function sendCoins (account, tx, settings, operatorId) {
|
||||||
return axios.post('/sendCoins', {
|
const { cryptoCode } = tx
|
||||||
account,
|
try {
|
||||||
tx,
|
return checkCryptoCode(cryptoCode).then(() => {
|
||||||
settings,
|
return axios.post('/sendCoins', {
|
||||||
operatorId
|
account,
|
||||||
}).catch(console.error)
|
tx,
|
||||||
|
settings,
|
||||||
|
operatorId
|
||||||
|
}).then(({ data }) => {
|
||||||
|
if (data.error && data.error.message === 'insufficient funds') throw new E.InsufficientFundsError()
|
||||||
|
else if (data.error) throw new Error({ error: data.error, message: data.error.message })
|
||||||
|
const fee = BN(data.fee).round()
|
||||||
|
const txid = data.txid
|
||||||
|
return { txid, fee }
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function newAddress (account, info, tx, settings, operatorId) {
|
function newAddress (account, info, tx, settings, operatorId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue