Skip to content

Commit

Permalink
initial commit for #1067
Browse files Browse the repository at this point in the history
  • Loading branch information
rsercano committed Jul 24, 2019
1 parent 6df5e0d commit 059035a
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 50 deletions.
20 changes: 19 additions & 1 deletion docs/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions lib/cli/commands/listcurrencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { callback, loadXudClient } from '../command';
import { Arguments } from 'yargs';
import colors from 'colors/safe';
import Table, { HorizontalTable } from 'cli-table3';
import { ListCurrenciesRequest, ListCurrenciesResponse } from '../../proto/xudrpc_pb';

const HEADERS = [
colors.blue('Ticker'),
colors.blue('Digits'),
colors.blue('Global Identifier'),
];

const formatCurrencies = (currencies: ListCurrenciesResponse.AsObject) => {
const formatted: any[] = [];
currencies.currenciesList.forEach((currency) => {
const element = [];
element.push(currency.tickerSymbol, currency.digits, currency.globalIdentifier);
formatted.push(element);
});
return formatted;
};

const createTable = () => {
const table = new Table({
head: HEADERS,
}) as HorizontalTable;
return table;
};

const displayTable = (response: ListCurrenciesResponse.AsObject) => {
const table = createTable();

formatCurrencies(response).forEach((currency) => {
table.push(currency);
});
console.log(colors.underline(colors.bold('\nCurrencies:')));
console.log(table.toString());
};

export const command = 'listcurrencies';

export const describe = 'list available currencies';

export const handler = (argv: Arguments) => {
loadXudClient(argv).listCurrencies(new ListCurrenciesRequest(), callback(argv, displayTable));
};
11 changes: 9 additions & 2 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,16 @@ class GrpcService {
*/
public listCurrencies: grpc.handleUnaryCall<xudrpc.ListCurrenciesRequest, xudrpc.ListCurrenciesResponse> = (_, callback) => {
try {
const listCurrenciesResponse = this.service.listCurrencies();
const currencies = this.service.listCurrencies();
const response = new xudrpc.ListCurrenciesResponse();
response.setCurrenciesList(listCurrenciesResponse);

currencies.forEach((currency) => {
const resultCurrency = new xudrpc.Currency();
resultCurrency.setDigits(currency.decimalPlaces);
resultCurrency.setTickerSymbol(currency.id);
resultCurrency.setGlobalIdentifier('TODO');
response.getCurrenciesList().push(resultCurrency);
});

callback(null, response);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/orderbook/OrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class OrderBook extends EventEmitter {
}

public get currencies() {
return this.currencyInstances.keys();
return this.currencyInstances;
}

constructor({ logger, models, thresholds, pool, swaps, nosanityswaps, nobalancechecks, nomatching = false }:
Expand Down
70 changes: 44 additions & 26 deletions lib/proto/xudrpc.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 059035a

Please sign in to comment.