adamant-api
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -24,3 +24,2 @@ // https://web3js.readthedocs.io/en/1.0/web3-eth.html#eth-getbalance | ||
}; | ||
}; | ||
module.exports = eth; | ||
}; |
@@ -5,4 +5,4 @@ const request = require('sync-request'); | ||
module.exports = (hotNode) => { | ||
return (type, input) => { | ||
module.exports = (syncReq) => { | ||
return async (type, input) => { | ||
let endpoint = false, | ||
@@ -12,54 +12,58 @@ explorer_url = false, | ||
switch (type) { | ||
case 'account': | ||
endpoint = '/api/accounts?address=' + input | ||
break | ||
case 'full_account': | ||
explorer_url = 'https://explorer.adamant.im/api/getAccount?address=' + input | ||
break | ||
case 'delegate_forged': | ||
endpoint = '/api/delegates/forging/getForgedByAccount?generatorPublicKey=' + input | ||
break; | ||
case 'account_delegates': | ||
endpoint = '/api/accounts/delegates?address=' + input | ||
returned_field = 'delegates'; | ||
break | ||
case 'block': | ||
endpoint = '/api/blocks/get?id=' + input | ||
break | ||
case 'state': | ||
endpoint = '/api/states/get?id=' + input | ||
break | ||
case 'delegate': | ||
endpoint = '/api/delegates/get?username=' + input | ||
returned_field = 'delegate'; | ||
break | ||
case 'delegate_voters': | ||
endpoint = '/api/delegates/voters?publicKey=' + input | ||
returned_field = 'accounts'; | ||
break | ||
case 'blocks': | ||
endpoint = '/api/blocks'; | ||
returned_field = 'blocks'; | ||
break | ||
case 'transaction': | ||
endpoint = '/api/transactions/get?id=' + input | ||
break | ||
case 'transactions': | ||
endpoint = '/api/transactions?' + input.split(' ').join('').split(',').join('&') | ||
break | ||
case 'uri': | ||
endpoint = '/api/' + input; | ||
break | ||
default: | ||
log.error('Not implemented yet') | ||
return false; | ||
case 'account': | ||
endpoint = '/api/accounts?address=' + input; | ||
break; | ||
case 'full_account': | ||
explorer_url = 'https://explorer.adamant.im/api/getAccount?address=' + input; | ||
break; | ||
case 'delegate_forged': | ||
endpoint = '/api/delegates/forging/getForgedByAccount?generatorPublicKey=' + input; | ||
break; | ||
case 'account_delegates': | ||
endpoint = '/api/accounts/delegates?address=' + input; | ||
returned_field = 'delegates'; | ||
break; | ||
case 'block': | ||
endpoint = '/api/blocks/get?id=' + input; | ||
break; | ||
case 'state': | ||
endpoint = '/api/states/get?id=' + input; | ||
break; | ||
case 'delegate': | ||
endpoint = '/api/delegates/get?username=' + input; | ||
returned_field = 'delegate'; | ||
break; | ||
case 'delegate_voters': | ||
endpoint = '/api/delegates/voters?publicKey=' + input; | ||
returned_field = 'accounts'; | ||
break; | ||
case 'blocks': | ||
endpoint = '/api/blocks'; | ||
returned_field = 'blocks'; | ||
break; | ||
case 'transaction': | ||
endpoint = '/api/transactions/get?id=' + input; | ||
break; | ||
case 'transactions': | ||
endpoint = '/api/transactions?' + input.split(' ').join('').split(',').join('&'); | ||
break; | ||
case 'uri': | ||
endpoint = '/api/' + input; | ||
break; | ||
default: | ||
log.error('ADM api Not implemented yet'); | ||
return false; | ||
} | ||
try { | ||
const url = explorer_url || hotNode() + endpoint; | ||
const res = JSON.parse(request('GET', url).getBody().toString()); | ||
if (res.success) { | ||
if (returned_field) return res[returned_field]; | ||
// const url = explorer_url || hotNode() + endpoint; | ||
const url = explorer_url || endpoint; | ||
// const res = JSON.parse(request('GET', url).getBody().toString()); | ||
const res = await syncReq(url, explorer_url); | ||
if (res && res.success) { | ||
if (returned_field) { | ||
return res[returned_field]; | ||
} | ||
return res; | ||
} | ||
log.error('Failed Get request: ' + type + ' ' + url + ' ' + res.error); | ||
@@ -71,6 +75,3 @@ return false; | ||
} | ||
} | ||
} | ||
}; | ||
}; |
13
index.js
@@ -6,11 +6,14 @@ const Get = require('./groups/get'); | ||
const eth = require('./groups/eth'); | ||
const syncGet = require('./groups/syncGet'); | ||
module.exports = (config) => { | ||
const hotNode = healthCheck(config.node); | ||
module.exports = (params) => { | ||
const hotNode = healthCheck(params.node); | ||
const syncReq = syncGet(hotNode); | ||
return { | ||
get: Get(hotNode), | ||
get: Get(syncReq), | ||
send: Send(hotNode), | ||
decodeMsg, | ||
eth | ||
eth, | ||
syncGet: syncReq | ||
}; | ||
}; | ||
}; |
{ | ||
"name": "adamant-api", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "\"REST API for ADAMANT Blockchain\"", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63319
19
805