generalize bitcoind json-rpc
This commit is contained in:
parent
f70211d774
commit
2c525c1e5c
11 changed files with 468 additions and 121 deletions
|
|
@ -1,26 +1,40 @@
|
|||
const _ = require('lodash/fp')
|
||||
|
||||
const coins = {
|
||||
BTC: {unitScale: 8},
|
||||
ETH: {unitScale: 18},
|
||||
ZEC: {unitScale: 8}
|
||||
ZEC: {unitScale: 8},
|
||||
LTC: {unitScale: 8},
|
||||
DASH: {unitScale: 8}
|
||||
}
|
||||
|
||||
const cryptoDisplays = [
|
||||
{cryptoCode: 'BTC', display: 'Bitcoin'},
|
||||
{cryptoCode: 'ETH', display: 'Ethereum'},
|
||||
{cryptoCode: 'ZEC', display: 'Zcash'}
|
||||
{cryptoCode: 'ZEC', display: 'Zcash'},
|
||||
{cryptoCode: 'LTC', display: 'Litecoin'},
|
||||
{cryptoCode: 'DASH', display: 'Dash'}
|
||||
]
|
||||
|
||||
module.exports = {coins, cryptoDisplays, buildUrl, unitScale}
|
||||
module.exports = {coins, cryptoDisplays, buildUrl, unitScale, display}
|
||||
|
||||
function buildUrl (cryptoCode, address) {
|
||||
switch (cryptoCode) {
|
||||
case 'BTC': return `bitcoin:${address}`
|
||||
case 'ETH': return `ethereum:${address}`
|
||||
case 'ZEC': return `zcash:${address}`
|
||||
case 'LTC': return `litecoin:${address}`
|
||||
case 'DASH': return `dash:${address}`
|
||||
default: throw new Error(`Unsupported crypto: ${cryptoCode}`)
|
||||
}
|
||||
}
|
||||
|
||||
function display (cryptoCode) {
|
||||
const rec = _.find(['cryptoCode', cryptoCode], cryptoDisplays)
|
||||
if (!rec) throw new Error(`Unsupported crypto: ${cryptoCode}`)
|
||||
return rec.display
|
||||
}
|
||||
|
||||
function unitScale (cryptoCode) {
|
||||
const scaleRec = coins[cryptoCode]
|
||||
if (!scaleRec) throw new Error(`Unsupported crypto: ${cryptoCode}`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue