diff --git a/app/controller/token.js b/app/controller/token.js index 047fba9..cc186d8 100644 --- a/app/controller/token.js +++ b/app/controller/token.js @@ -127,6 +127,48 @@ class TokenController extends Controller { } } + async getPricesTokensOfAelf() { + const { + ctx + } = this; + + const { + type = 'USD' + } = ctx.request.query; + + try { + + const tokenList = await ctx.service.token.getTokenList({ + limit: 2000, + page: 0 + }); + + // TODO: valid token pool. if the same name in public market. + // For Example: LOT, DISK, NET is now in public market. + const validPool = [ 'ELF', 'AEUSD' ]; + const pairs = []; + tokenList.forEach(token => { + if (/^AE/.test(token.symbol) && token.symbol !== 'AEUSD') { + pairs.push({ + fsym: token.symbol.replace(/^AE/, ''), + tsyms: type + }); + } else if (validPool.includes(token.symbol)) { + pairs.push({ + fsym: token.symbol, + tsyms: type + }); + } + }); + + const result = await ctx.service.token.getPrices(pairs); + + formatOutput(ctx, 'get', result); + } catch (error) { + formatOutput(ctx, 'error', error, 422); + } + } + } module.exports = TokenController; diff --git a/app/router.js b/app/router.js index e0bbba2..175e1f5 100644 --- a/app/router.js +++ b/app/router.js @@ -59,7 +59,8 @@ module.exports = app => { router.get('/api/token/txs', controller.token.getTxs); router.get('/api/token/price', controller.token.getPrice); - router.get('/api/token/prices', controller.token.getPrices); + router.get('/api/token/prices-tokens-of-aelf', controller.token.getPricesTokensOfAelf); + router.post('/api/token/prices', controller.token.getPrices); router.post('/api/vote/addTeamDesc', controller.vote.addTeamDesc); router.get('/api/vote/getTeamDesc', controller.vote.getTeamDesc); diff --git a/app/service/token.js b/app/service/token.js index 12d1194..ee6dab6 100644 --- a/app/service/token.js +++ b/app/service/token.js @@ -118,6 +118,18 @@ class TokenService extends BaseService { }); })); } + + async getTokenList(options) { + const aelf0 = this.ctx.app.mysql.get('aelf0'); + const { + limit = 1000, + page = 0, + } = options; + + const offset = page * limit; + const sql = 'select * from contract_aelf20 order by id desc limit ? offset ?'; + return this.selectQuery(aelf0, sql, [ limit, offset ]); + } } module.exports = TokenService;