From 3d716b66caca66b3bb82c91d04d3c7a3948f9358 Mon Sep 17 00:00:00 2001 From: rsercano Date: Wed, 11 Sep 2019 11:21:41 -0400 Subject: [PATCH] feat(rpc): ListCurrencies enhancement Closes #1067. --- docs/api.md | 48 +++++++-------- lib/cli/commands/addcurrency.ts | 4 +- lib/cli/commands/listcurrencies.ts | 48 +++++++++++++++ lib/grpc/GrpcService.ts | 16 +++-- lib/orderbook/OrderBook.ts | 2 +- lib/proto/xudrpc.swagger.json | 52 ++++++++-------- lib/proto/xudrpc_grpc_pb.d.ts | 20 +++---- lib/proto/xudrpc_grpc_pb.js | 28 ++++----- lib/proto/xudrpc_pb.d.ts | 28 ++++----- lib/proto/xudrpc_pb.js | 95 ++++++++++++++++-------------- lib/service/Service.ts | 2 +- proto/xudrpc.proto | 11 ++-- 12 files changed, 208 insertions(+), 146 deletions(-) create mode 100644 lib/cli/commands/listcurrencies.ts diff --git a/docs/api.md b/docs/api.md index 46e582860..2b91619d0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -4,7 +4,6 @@ ## Table of Contents - [xudrpc.proto](#xudrpc.proto) - - [AddCurrencyRequest](#xudrpc.AddCurrencyRequest) - [AddCurrencyResponse](#xudrpc.AddCurrencyResponse) - [AddPairRequest](#xudrpc.AddPairRequest) - [AddPairResponse](#xudrpc.AddPairResponse) @@ -16,6 +15,7 @@ - [ConnectResponse](#xudrpc.ConnectResponse) - [CreateNodeRequest](#xudrpc.CreateNodeRequest) - [CreateNodeResponse](#xudrpc.CreateNodeResponse) + - [Currency](#xudrpc.Currency) - [DiscoverNodesRequest](#xudrpc.DiscoverNodesRequest) - [DiscoverNodesResponse](#xudrpc.DiscoverNodesResponse) - [ExecuteSwapRequest](#xudrpc.ExecuteSwapRequest) @@ -71,7 +71,7 @@ - [UnlockNodeRequest](#xudrpc.UnlockNodeRequest) - [UnlockNodeResponse](#xudrpc.UnlockNodeResponse) - - [AddCurrencyRequest.SwapClient](#xudrpc.AddCurrencyRequest.SwapClient) + - [Currency.SwapClient](#xudrpc.Currency.SwapClient) - [OrderSide](#xudrpc.OrderSide) - [SwapSuccess.Role](#xudrpc.SwapSuccess.Role) @@ -91,24 +91,6 @@ - - -### AddCurrencyRequest - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| currency | [string](#string) | | The ticker symbol for this currency such as BTC, LTC, ETH, etc... | -| swap_client | [AddCurrencyRequest.SwapClient](#xudrpc.AddCurrencyRequest.SwapClient) | | The payment channel network client to use for executing swaps. | -| token_address | [string](#string) | | The contract address for layered tokens such as ERC20. | -| decimal_places | [uint32](#uint32) | | The number of places to the right of the decimal point of the smallest subunit of the currency. For example, BTC, LTC, and others where the smallest subunits (satoshis) are 0.00000001 full units (bitcoins) have 8 decimal places. ETH has 18. This can be thought of as the base 10 exponent of the smallest subunit expressed as a positive integer. A default value of 8 is used if unspecified. | - - - - - - ### AddCurrencyResponse @@ -259,6 +241,24 @@ + + +### Currency + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| currency | [string](#string) | | The ticker symbol for this currency such as BTC, LTC, ETH, etc... | +| swap_client | [Currency.SwapClient](#xudrpc.Currency.SwapClient) | | The payment channel network client to use for executing swaps. | +| token_address | [string](#string) | | The contract address for layered tokens such as ERC20. | +| decimal_places | [uint32](#uint32) | | The number of places to the right of the decimal point of the smallest subunit of the currency. For example, BTC, LTC, and others where the smallest subunits (satoshis) are 0.00000001 full units (bitcoins) have 8 decimal places. ETH has 18. This can be thought of as the base 10 exponent of the smallest subunit expressed as a positive integer. A default value of 8 is used if unspecified. | + + + + + + ### DiscoverNodesRequest @@ -450,7 +450,7 @@ | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| currencies | [string](#string) | repeated | A list of ticker symbols of the supported currencies. | +| currencies | [Currency](#xudrpc.Currency) | repeated | The list of available currencies in the orderbook. | @@ -1107,9 +1107,9 @@ - + -### AddCurrencyRequest.SwapClient +### Currency.SwapClient | Name | Number | Description | @@ -1154,7 +1154,7 @@ | Method Name | Request Type | Response Type | Description | | ----------- | ------------ | ------------- | ------------| -| AddCurrency | [AddCurrencyRequest](#xudrpc.AddCurrencyRequest) | [AddCurrencyResponse](#xudrpc.AddCurrencyResponse) | Adds a currency to the list of supported currencies. Once added, the currency may be used for new trading pairs. | +| AddCurrency | [Currency](#xudrpc.Currency) | [AddCurrencyResponse](#xudrpc.AddCurrencyResponse) | Adds a currency to the list of supported currencies. Once added, the currency may be used for new trading pairs. | | AddPair | [AddPairRequest](#xudrpc.AddPairRequest) | [AddPairResponse](#xudrpc.AddPairResponse) | Adds a trading pair to the list of supported trading pairs. The newly supported pair is advertised to peers so they may begin sending orders for it. | | RemoveOrder | [RemoveOrderRequest](#xudrpc.RemoveOrderRequest) | [RemoveOrderResponse](#xudrpc.RemoveOrderResponse) | Removes an order from the order book by its local id. This should be called when an order is canceled or filled outside of xud. Removed orders become immediately unavailable for swaps, and peers are notified that the order is no longer valid. Any portion of the order that is on hold due to ongoing swaps will not be removed until after the swap attempts complete. | | GetBalance | [GetBalanceRequest](#xudrpc.GetBalanceRequest) | [GetBalanceResponse](#xudrpc.GetBalanceResponse) | Gets the total balance available across all payment channels and wallets for one or all currencies. | diff --git a/lib/cli/commands/addcurrency.ts b/lib/cli/commands/addcurrency.ts index 8977b0b0f..69f148c3a 100644 --- a/lib/cli/commands/addcurrency.ts +++ b/lib/cli/commands/addcurrency.ts @@ -1,6 +1,6 @@ import { Arguments } from 'yargs'; import { callback, loadXudClient } from '../command'; -import { AddCurrencyRequest } from '../../proto/xudrpc_pb'; +import { Currency } from '../../proto/xudrpc_pb'; import { SwapClientType } from '../../constants/enums'; export const command = 'addcurrency [decimal_places] [token_address]'; @@ -29,7 +29,7 @@ export const builder = { }; export const handler = (argv: Arguments) => { - const request = new AddCurrencyRequest(); + const request = new Currency(); request.setCurrency(argv.currency.toUpperCase()); request.setSwapClient(Number(SwapClientType[argv.swap_client])); request.setTokenAddress(argv.token_address); diff --git a/lib/cli/commands/listcurrencies.ts b/lib/cli/commands/listcurrencies.ts new file mode 100644 index 000000000..df9e73fe9 --- /dev/null +++ b/lib/cli/commands/listcurrencies.ts @@ -0,0 +1,48 @@ +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'; +import { SwapClientType } from '../../constants/enums'; + +const HEADERS = [ + colors.blue('Ticker'), + colors.blue('Digits'), + colors.blue('Token Address'), + colors.blue('Swap Client'), +]; + +const formatCurrencies = (currencies: ListCurrenciesResponse.AsObject) => { + const formatted: any[] = []; + currencies.currenciesList.forEach((currency) => { + const element = []; + element.push(currency.currency, currency.decimalPlaces, currency.tokenAddress, SwapClientType[currency.swapClient]); + 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)); +}; diff --git a/lib/grpc/GrpcService.ts b/lib/grpc/GrpcService.ts index 26d2907a1..9e1ed3850 100644 --- a/lib/grpc/GrpcService.ts +++ b/lib/grpc/GrpcService.ts @@ -12,7 +12,7 @@ import { errorCodes as lndErrorCodes } from '../lndclient/errors'; import { LndInfo } from '../lndclient/types'; import { SwapSuccess, SwapFailure } from '../swaps/types'; import { SwapFailureReason } from '../constants/enums'; -import { TradeInstance, OrderInstance } from '../db/types'; +import { TradeInstance, OrderInstance, CurrencyInstance } from '../db/types'; /** * Creates an xudrpc Order message from an [[Order]]. @@ -227,7 +227,7 @@ class GrpcService { /** * See [[Service.addCurrency]] */ - public addCurrency: grpc.handleUnaryCall = async (call, callback) => { + public addCurrency: grpc.handleUnaryCall = async (call, callback) => { try { await this.service.addCurrency(call.request.toObject()); const response = new xudrpc.AddCurrencyResponse(); @@ -499,9 +499,17 @@ class GrpcService { */ public listCurrencies: grpc.handleUnaryCall = (_, callback) => { try { - const listCurrenciesResponse = this.service.listCurrencies(); + const currencies = this.service.listCurrencies(); const response = new xudrpc.ListCurrenciesResponse(); - response.setCurrenciesList(listCurrenciesResponse); + + currencies.forEach((currency: CurrencyInstance) => { + const resultCurrency = new xudrpc.Currency(); + resultCurrency.setDecimalPlaces(currency.decimalPlaces); + resultCurrency.setCurrency(currency.id); + resultCurrency.setTokenAddress(currency.tokenAddress); + resultCurrency.setSwapClient(currency.swapClient as number); + response.getCurrenciesList().push(resultCurrency); + }); callback(null, response); } catch (err) { diff --git a/lib/orderbook/OrderBook.ts b/lib/orderbook/OrderBook.ts index 1e2b764f1..e853f48c8 100644 --- a/lib/orderbook/OrderBook.ts +++ b/lib/orderbook/OrderBook.ts @@ -90,7 +90,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 }: diff --git a/lib/proto/xudrpc.swagger.json b/lib/proto/xudrpc.swagger.json index 391cb5146..ac526a25e 100644 --- a/lib/proto/xudrpc.swagger.json +++ b/lib/proto/xudrpc.swagger.json @@ -33,7 +33,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/xudrpcAddCurrencyRequest" + "$ref": "#/definitions/xudrpcCurrency" } } ], @@ -654,7 +654,7 @@ } }, "definitions": { - "AddCurrencyRequestSwapClient": { + "CurrencySwapClient": { "type": "string", "enum": [ "LND", @@ -670,28 +670,6 @@ ], "default": "TAKER" }, - "xudrpcAddCurrencyRequest": { - "type": "object", - "properties": { - "currency": { - "type": "string", - "description": "The ticker symbol for this currency such as BTC, LTC, ETH, etc..." - }, - "swap_client": { - "$ref": "#/definitions/AddCurrencyRequestSwapClient", - "description": "The payment channel network client to use for executing swaps." - }, - "token_address": { - "type": "string", - "description": "The contract address for layered tokens such as ERC20." - }, - "decimal_places": { - "type": "integer", - "format": "int64", - "description": "The number of places to the right of the decimal point of the smallest subunit of the currency.\nFor example, BTC, LTC, and others where the smallest subunits (satoshis) are 0.00000001 full\nunits (bitcoins) have 8 decimal places. ETH has 18. This can be thought of as the base 10\nexponent of the smallest subunit expressed as a positive integer. A default value of 8 is\nused if unspecified." - } - } - }, "xudrpcAddCurrencyResponse": { "type": "object" }, @@ -787,6 +765,28 @@ } } }, + "xudrpcCurrency": { + "type": "object", + "properties": { + "currency": { + "type": "string", + "description": "The ticker symbol for this currency such as BTC, LTC, ETH, etc..." + }, + "swap_client": { + "$ref": "#/definitions/CurrencySwapClient", + "description": "The payment channel network client to use for executing swaps." + }, + "token_address": { + "type": "string", + "description": "The contract address for layered tokens such as ERC20." + }, + "decimal_places": { + "type": "integer", + "format": "int64", + "description": "The number of places to the right of the decimal point of the smallest subunit of the currency.\nFor example, BTC, LTC, and others where the smallest subunits (satoshis) are 0.00000001 full\nunits (bitcoins) have 8 decimal places. ETH has 18. This can be thought of as the base 10\nexponent of the smallest subunit expressed as a positive integer. A default value of 8 is\nused if unspecified." + } + } + }, "xudrpcDiscoverNodesRequest": { "type": "object", "properties": { @@ -903,9 +903,9 @@ "currencies": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/xudrpcCurrency" }, - "description": "A list of ticker symbols of the supported currencies." + "description": "The list of available currencies in the orderbook." } } }, diff --git a/lib/proto/xudrpc_grpc_pb.d.ts b/lib/proto/xudrpc_grpc_pb.d.ts index da41f8d74..71213ba8e 100644 --- a/lib/proto/xudrpc_grpc_pb.d.ts +++ b/lib/proto/xudrpc_grpc_pb.d.ts @@ -85,12 +85,12 @@ interface IXudService extends grpc.ServiceDefinition { +interface IXudService_IAddCurrency extends grpc.MethodDefinition { path: string; // "/xudrpc.Xud/AddCurrency" requestStream: boolean; // false responseStream: boolean; // false - requestSerialize: grpc.serialize; - requestDeserialize: grpc.deserialize; + requestSerialize: grpc.serialize; + requestDeserialize: grpc.deserialize; responseSerialize: grpc.serialize; responseDeserialize: grpc.deserialize; } @@ -314,7 +314,7 @@ interface IXudService_ISubscribeSwapFailures extends grpc.MethodDefinition; + addCurrency: grpc.handleUnaryCall; addPair: grpc.handleUnaryCall; removeOrder: grpc.handleUnaryCall; getBalance: grpc.handleUnaryCall; @@ -342,9 +342,9 @@ export interface IXudServer { } export interface IXudClient { - addCurrency(request: xudrpc_pb.AddCurrencyRequest, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; - addCurrency(request: xudrpc_pb.AddCurrencyRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; - addCurrency(request: xudrpc_pb.AddCurrencyRequest, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; + addCurrency(request: xudrpc_pb.Currency, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; + addCurrency(request: xudrpc_pb.Currency, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; + addCurrency(request: xudrpc_pb.Currency, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; addPair(request: xudrpc_pb.AddPairRequest, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddPairResponse) => void): grpc.ClientUnaryCall; addPair(request: xudrpc_pb.AddPairRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddPairResponse) => void): grpc.ClientUnaryCall; addPair(request: xudrpc_pb.AddPairRequest, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddPairResponse) => void): grpc.ClientUnaryCall; @@ -417,9 +417,9 @@ export interface IXudClient { export class XudClient extends grpc.Client implements IXudClient { constructor(address: string, credentials: grpc.ChannelCredentials, options?: object); - public addCurrency(request: xudrpc_pb.AddCurrencyRequest, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; - public addCurrency(request: xudrpc_pb.AddCurrencyRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; - public addCurrency(request: xudrpc_pb.AddCurrencyRequest, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; + public addCurrency(request: xudrpc_pb.Currency, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; + public addCurrency(request: xudrpc_pb.Currency, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; + public addCurrency(request: xudrpc_pb.Currency, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddCurrencyResponse) => void): grpc.ClientUnaryCall; public addPair(request: xudrpc_pb.AddPairRequest, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddPairResponse) => void): grpc.ClientUnaryCall; public addPair(request: xudrpc_pb.AddPairRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddPairResponse) => void): grpc.ClientUnaryCall; public addPair(request: xudrpc_pb.AddPairRequest, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: xudrpc_pb.AddPairResponse) => void): grpc.ClientUnaryCall; diff --git a/lib/proto/xudrpc_grpc_pb.js b/lib/proto/xudrpc_grpc_pb.js index f2cb3af0c..34a0b559c 100644 --- a/lib/proto/xudrpc_grpc_pb.js +++ b/lib/proto/xudrpc_grpc_pb.js @@ -26,17 +26,6 @@ var grpc = require('grpc'); var xudrpc_pb = require('./xudrpc_pb.js'); var annotations_pb = require('./annotations_pb.js'); -function serialize_xudrpc_AddCurrencyRequest(arg) { - if (!(arg instanceof xudrpc_pb.AddCurrencyRequest)) { - throw new Error('Expected argument of type xudrpc.AddCurrencyRequest'); - } - return Buffer.from(arg.serializeBinary()); -} - -function deserialize_xudrpc_AddCurrencyRequest(buffer_arg) { - return xudrpc_pb.AddCurrencyRequest.deserializeBinary(new Uint8Array(buffer_arg)); -} - function serialize_xudrpc_AddCurrencyResponse(arg) { if (!(arg instanceof xudrpc_pb.AddCurrencyResponse)) { throw new Error('Expected argument of type xudrpc.AddCurrencyResponse'); @@ -136,6 +125,17 @@ function deserialize_xudrpc_CreateNodeResponse(buffer_arg) { return xudrpc_pb.CreateNodeResponse.deserializeBinary(new Uint8Array(buffer_arg)); } +function serialize_xudrpc_Currency(arg) { + if (!(arg instanceof xudrpc_pb.Currency)) { + throw new Error('Expected argument of type xudrpc.Currency'); + } + return Buffer.from(arg.serializeBinary()); +} + +function deserialize_xudrpc_Currency(buffer_arg) { + return xudrpc_pb.Currency.deserializeBinary(new Uint8Array(buffer_arg)); +} + function serialize_xudrpc_DiscoverNodesRequest(arg) { if (!(arg instanceof xudrpc_pb.DiscoverNodesRequest)) { throw new Error('Expected argument of type xudrpc.DiscoverNodesRequest'); @@ -625,10 +625,10 @@ var XudService = exports.XudService = { path: '/xudrpc.Xud/AddCurrency', requestStream: false, responseStream: false, - requestType: xudrpc_pb.AddCurrencyRequest, + requestType: xudrpc_pb.Currency, responseType: xudrpc_pb.AddCurrencyResponse, - requestSerialize: serialize_xudrpc_AddCurrencyRequest, - requestDeserialize: deserialize_xudrpc_AddCurrencyRequest, + requestSerialize: serialize_xudrpc_Currency, + requestDeserialize: deserialize_xudrpc_Currency, responseSerialize: serialize_xudrpc_AddCurrencyResponse, responseDeserialize: deserialize_xudrpc_AddCurrencyResponse, }, diff --git a/lib/proto/xudrpc_pb.d.ts b/lib/proto/xudrpc_pb.d.ts index 7f0e5e5e1..4c9fc9457 100644 --- a/lib/proto/xudrpc_pb.d.ts +++ b/lib/proto/xudrpc_pb.d.ts @@ -108,12 +108,12 @@ export namespace UnlockNodeResponse { } } -export class AddCurrencyRequest extends jspb.Message { +export class Currency extends jspb.Message { getCurrency(): string; setCurrency(value: string): void; - getSwapClient(): AddCurrencyRequest.SwapClient; - setSwapClient(value: AddCurrencyRequest.SwapClient): void; + getSwapClient(): Currency.SwapClient; + setSwapClient(value: Currency.SwapClient): void; getTokenAddress(): string; setTokenAddress(value: string): void; @@ -123,19 +123,19 @@ export class AddCurrencyRequest extends jspb.Message { serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): AddCurrencyRequest.AsObject; - static toObject(includeInstance: boolean, msg: AddCurrencyRequest): AddCurrencyRequest.AsObject; + toObject(includeInstance?: boolean): Currency.AsObject; + static toObject(includeInstance: boolean, msg: Currency): Currency.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: AddCurrencyRequest, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): AddCurrencyRequest; - static deserializeBinaryFromReader(message: AddCurrencyRequest, reader: jspb.BinaryReader): AddCurrencyRequest; + static serializeBinaryToWriter(message: Currency, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): Currency; + static deserializeBinaryFromReader(message: Currency, reader: jspb.BinaryReader): Currency; } -export namespace AddCurrencyRequest { +export namespace Currency { export type AsObject = { currency: string, - swapClient: AddCurrencyRequest.SwapClient, + swapClient: Currency.SwapClient, tokenAddress: string, decimalPlaces: number, } @@ -685,9 +685,9 @@ export namespace ListCurrenciesRequest { export class ListCurrenciesResponse extends jspb.Message { clearCurrenciesList(): void; - getCurrenciesList(): Array; - setCurrenciesList(value: Array): void; - addCurrencies(value: string, index?: number): string; + getCurrenciesList(): Array; + setCurrenciesList(value: Array): void; + addCurrencies(value?: Currency, index?: number): Currency; serializeBinary(): Uint8Array; @@ -702,7 +702,7 @@ export class ListCurrenciesResponse extends jspb.Message { export namespace ListCurrenciesResponse { export type AsObject = { - currenciesList: Array, + currenciesList: Array, } } diff --git a/lib/proto/xudrpc_pb.js b/lib/proto/xudrpc_pb.js index 6004fad3c..c87330a42 100644 --- a/lib/proto/xudrpc_pb.js +++ b/lib/proto/xudrpc_pb.js @@ -12,8 +12,6 @@ var goog = jspb; var global = Function('return this')(); var annotations_pb = require('./annotations_pb.js'); -goog.exportSymbol('proto.xudrpc.AddCurrencyRequest', null, global); -goog.exportSymbol('proto.xudrpc.AddCurrencyRequest.SwapClient', null, global); goog.exportSymbol('proto.xudrpc.AddCurrencyResponse', null, global); goog.exportSymbol('proto.xudrpc.AddPairRequest', null, global); goog.exportSymbol('proto.xudrpc.AddPairResponse', null, global); @@ -25,6 +23,8 @@ goog.exportSymbol('proto.xudrpc.ConnectRequest', null, global); goog.exportSymbol('proto.xudrpc.ConnectResponse', null, global); goog.exportSymbol('proto.xudrpc.CreateNodeRequest', null, global); goog.exportSymbol('proto.xudrpc.CreateNodeResponse', null, global); +goog.exportSymbol('proto.xudrpc.Currency', null, global); +goog.exportSymbol('proto.xudrpc.Currency.SwapClient', null, global); goog.exportSymbol('proto.xudrpc.DiscoverNodesRequest', null, global); goog.exportSymbol('proto.xudrpc.DiscoverNodesResponse', null, global); goog.exportSymbol('proto.xudrpc.ExecuteSwapRequest', null, global); @@ -797,12 +797,12 @@ proto.xudrpc.UnlockNodeResponse.prototype.setUnlockedRaiden = function(value) { * @extends {jspb.Message} * @constructor */ -proto.xudrpc.AddCurrencyRequest = function(opt_data) { +proto.xudrpc.Currency = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.xudrpc.AddCurrencyRequest, jspb.Message); +goog.inherits(proto.xudrpc.Currency, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.xudrpc.AddCurrencyRequest.displayName = 'proto.xudrpc.AddCurrencyRequest'; + proto.xudrpc.Currency.displayName = 'proto.xudrpc.Currency'; } @@ -817,8 +817,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.xudrpc.AddCurrencyRequest.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.AddCurrencyRequest.toObject(opt_includeInstance, this); +proto.xudrpc.Currency.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.Currency.toObject(opt_includeInstance, this); }; @@ -827,11 +827,11 @@ proto.xudrpc.AddCurrencyRequest.prototype.toObject = function(opt_includeInstanc * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.xudrpc.AddCurrencyRequest} msg The msg instance to transform. + * @param {!proto.xudrpc.Currency} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.AddCurrencyRequest.toObject = function(includeInstance, msg) { +proto.xudrpc.Currency.toObject = function(includeInstance, msg) { var f, obj = { currency: jspb.Message.getFieldWithDefault(msg, 1, ""), swapClient: jspb.Message.getFieldWithDefault(msg, 2, 0), @@ -850,23 +850,23 @@ proto.xudrpc.AddCurrencyRequest.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.xudrpc.AddCurrencyRequest} + * @return {!proto.xudrpc.Currency} */ -proto.xudrpc.AddCurrencyRequest.deserializeBinary = function(bytes) { +proto.xudrpc.Currency.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.xudrpc.AddCurrencyRequest; - return proto.xudrpc.AddCurrencyRequest.deserializeBinaryFromReader(msg, reader); + var msg = new proto.xudrpc.Currency; + return proto.xudrpc.Currency.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.xudrpc.AddCurrencyRequest} msg The message object to deserialize into. + * @param {!proto.xudrpc.Currency} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.xudrpc.AddCurrencyRequest} + * @return {!proto.xudrpc.Currency} */ -proto.xudrpc.AddCurrencyRequest.deserializeBinaryFromReader = function(msg, reader) { +proto.xudrpc.Currency.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; @@ -878,7 +878,7 @@ proto.xudrpc.AddCurrencyRequest.deserializeBinaryFromReader = function(msg, read msg.setCurrency(value); break; case 2: - var value = /** @type {!proto.xudrpc.AddCurrencyRequest.SwapClient} */ (reader.readEnum()); + var value = /** @type {!proto.xudrpc.Currency.SwapClient} */ (reader.readEnum()); msg.setSwapClient(value); break; case 3: @@ -902,9 +902,9 @@ proto.xudrpc.AddCurrencyRequest.deserializeBinaryFromReader = function(msg, read * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.xudrpc.AddCurrencyRequest.prototype.serializeBinary = function() { +proto.xudrpc.Currency.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.xudrpc.AddCurrencyRequest.serializeBinaryToWriter(this, writer); + proto.xudrpc.Currency.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -912,11 +912,11 @@ proto.xudrpc.AddCurrencyRequest.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.xudrpc.AddCurrencyRequest} message + * @param {!proto.xudrpc.Currency} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.AddCurrencyRequest.serializeBinaryToWriter = function(message, writer) { +proto.xudrpc.Currency.serializeBinaryToWriter = function(message, writer) { var f = undefined; f = message.getCurrency(); if (f.length > 0) { @@ -952,7 +952,7 @@ proto.xudrpc.AddCurrencyRequest.serializeBinaryToWriter = function(message, writ /** * @enum {number} */ -proto.xudrpc.AddCurrencyRequest.SwapClient = { +proto.xudrpc.Currency.SwapClient = { LND: 0, RAIDEN: 1 }; @@ -961,28 +961,28 @@ proto.xudrpc.AddCurrencyRequest.SwapClient = { * optional string currency = 1; * @return {string} */ -proto.xudrpc.AddCurrencyRequest.prototype.getCurrency = function() { +proto.xudrpc.Currency.prototype.getCurrency = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; /** @param {string} value */ -proto.xudrpc.AddCurrencyRequest.prototype.setCurrency = function(value) { +proto.xudrpc.Currency.prototype.setCurrency = function(value) { jspb.Message.setField(this, 1, value); }; /** * optional SwapClient swap_client = 2; - * @return {!proto.xudrpc.AddCurrencyRequest.SwapClient} + * @return {!proto.xudrpc.Currency.SwapClient} */ -proto.xudrpc.AddCurrencyRequest.prototype.getSwapClient = function() { - return /** @type {!proto.xudrpc.AddCurrencyRequest.SwapClient} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +proto.xudrpc.Currency.prototype.getSwapClient = function() { + return /** @type {!proto.xudrpc.Currency.SwapClient} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); }; -/** @param {!proto.xudrpc.AddCurrencyRequest.SwapClient} value */ -proto.xudrpc.AddCurrencyRequest.prototype.setSwapClient = function(value) { +/** @param {!proto.xudrpc.Currency.SwapClient} value */ +proto.xudrpc.Currency.prototype.setSwapClient = function(value) { jspb.Message.setField(this, 2, value); }; @@ -991,13 +991,13 @@ proto.xudrpc.AddCurrencyRequest.prototype.setSwapClient = function(value) { * optional string token_address = 3; * @return {string} */ -proto.xudrpc.AddCurrencyRequest.prototype.getTokenAddress = function() { +proto.xudrpc.Currency.prototype.getTokenAddress = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); }; /** @param {string} value */ -proto.xudrpc.AddCurrencyRequest.prototype.setTokenAddress = function(value) { +proto.xudrpc.Currency.prototype.setTokenAddress = function(value) { jspb.Message.setField(this, 3, value); }; @@ -1006,13 +1006,13 @@ proto.xudrpc.AddCurrencyRequest.prototype.setTokenAddress = function(value) { * optional uint32 decimal_places = 4; * @return {number} */ -proto.xudrpc.AddCurrencyRequest.prototype.getDecimalPlaces = function() { +proto.xudrpc.Currency.prototype.getDecimalPlaces = function() { return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); }; /** @param {number} value */ -proto.xudrpc.AddCurrencyRequest.prototype.setDecimalPlaces = function(value) { +proto.xudrpc.Currency.prototype.setDecimalPlaces = function(value) { jspb.Message.setField(this, 4, value); }; @@ -4672,7 +4672,8 @@ proto.xudrpc.ListCurrenciesResponse.prototype.toObject = function(opt_includeIns */ proto.xudrpc.ListCurrenciesResponse.toObject = function(includeInstance, msg) { var f, obj = { - currenciesList: jspb.Message.getRepeatedField(msg, 1) + currenciesList: jspb.Message.toObjectList(msg.getCurrenciesList(), + proto.xudrpc.Currency.toObject, includeInstance) }; if (includeInstance) { @@ -4710,7 +4711,8 @@ proto.xudrpc.ListCurrenciesResponse.deserializeBinaryFromReader = function(msg, var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); + var value = new proto.xudrpc.Currency; + reader.readMessage(value,proto.xudrpc.Currency.deserializeBinaryFromReader); msg.addCurrencies(value); break; default: @@ -4744,35 +4746,38 @@ proto.xudrpc.ListCurrenciesResponse.serializeBinaryToWriter = function(message, var f = undefined; f = message.getCurrenciesList(); if (f.length > 0) { - writer.writeRepeatedString( + writer.writeRepeatedMessage( 1, - f + f, + proto.xudrpc.Currency.serializeBinaryToWriter ); } }; /** - * repeated string currencies = 1; - * @return {!Array.} + * repeated Currency currencies = 1; + * @return {!Array.} */ proto.xudrpc.ListCurrenciesResponse.prototype.getCurrenciesList = function() { - return /** @type {!Array.} */ (jspb.Message.getRepeatedField(this, 1)); + return /** @type{!Array.} */ ( + jspb.Message.getRepeatedWrapperField(this, proto.xudrpc.Currency, 1)); }; -/** @param {!Array.} value */ +/** @param {!Array.} value */ proto.xudrpc.ListCurrenciesResponse.prototype.setCurrenciesList = function(value) { - jspb.Message.setField(this, 1, value || []); + jspb.Message.setRepeatedWrapperField(this, 1, value); }; /** - * @param {!string} value + * @param {!proto.xudrpc.Currency=} opt_value * @param {number=} opt_index + * @return {!proto.xudrpc.Currency} */ -proto.xudrpc.ListCurrenciesResponse.prototype.addCurrencies = function(value, opt_index) { - jspb.Message.addToRepeatedField(this, 1, value, opt_index); +proto.xudrpc.ListCurrenciesResponse.prototype.addCurrencies = function(opt_value, opt_index) { + return jspb.Message.addToRepeatedWrapperField(this, 1, opt_value, proto.xudrpc.Currency, opt_index); }; diff --git a/lib/service/Service.ts b/lib/service/Service.ts index f6f36b599..2ceabbd26 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -331,7 +331,7 @@ class Service { * @returns A list of supported currency ticker symbols */ public listCurrencies = () => { - return Array.from(this.orderBook.currencies); + return this.orderBook.currencies; } /** diff --git a/proto/xudrpc.proto b/proto/xudrpc.proto index fab4c858f..099933de0 100644 --- a/proto/xudrpc.proto +++ b/proto/xudrpc.proto @@ -63,7 +63,7 @@ message UnlockNodeResponse { service Xud { /* Adds a currency to the list of supported currencies. Once added, the currency may be used for * new trading pairs. */ - rpc AddCurrency(AddCurrencyRequest) returns (AddCurrencyResponse) { + rpc AddCurrency(Currency) returns (AddCurrencyResponse) { option (google.api.http) = { post: "/v1/addcurrency" body: "*" @@ -283,7 +283,7 @@ enum OrderSide { SELL = 1; } -message AddCurrencyRequest { +message Currency { // The ticker symbol for this currency such as BTC, LTC, ETH, etc... string currency = 1 [json_name = "currency"]; enum SwapClient { @@ -301,6 +301,7 @@ message AddCurrencyRequest { // used if unspecified. uint32 decimal_places = 4 [json_name = "decimal_places"]; } + message AddCurrencyResponse {} message AddPairRequest { @@ -428,8 +429,8 @@ message ListOrdersResponse { message ListCurrenciesRequest {} message ListCurrenciesResponse { - // A list of ticker symbols of the supported currencies. - repeated string currencies = 1 [json_name = "currencies"]; + // The list of available currencies in the orderbook. + repeated Currency currencies = 1 [json_name = "currencies"]; } message ListPairsRequest {} @@ -551,7 +552,7 @@ message Peer { string address = 1 [json_name = "address"]; // The node pub key to uniquely identify this peer. string node_pub_key = 2 [json_name = "node_pub_key"]; - // A map of ticker symbols to lnd pub keys for this peer + // A map of ticker symbols to lnd pub keys for this peer map lnd_pub_keys = 3 [json_name = "lnd_pub_keys"]; // Indicates whether this peer was connected inbound. bool inbound = 4 [json_name = "inbound"];