Skip to content

Commit 42308cd

Browse files
committed
Rebased
2 parents c42d58c + 8d10df0 commit 42308cd

File tree

19 files changed

+1019
-273
lines changed

19 files changed

+1019
-273
lines changed

docs/api.md

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Logger.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ const LevelPriorities = {
2323
trace: 6,
2424
};
2525

26+
enum LevelPriority {
27+
alert,
28+
error,
29+
warn,
30+
info,
31+
verbose,
32+
debug,
33+
trace,
34+
}
35+
2636
export enum Context {
2737
Global = 'GLOBAL',
2838
DB = 'DB',
@@ -138,6 +148,12 @@ class Logger {
138148
});
139149
}
140150

151+
public setLogLevel = (level: Level) => {
152+
this.logger?.transports.forEach((transport) => {
153+
transport.level = level;
154+
});
155+
}
156+
141157
private getLogFormat = (colorize: boolean, dateFormat?: string) => {
142158
const { format } = winston;
143159

@@ -219,4 +235,4 @@ class Logger {
219235
}
220236

221237
export default Logger;
222-
export { Level, Loggers };
238+
export { Level, Loggers, LevelPriority };

lib/Xud.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ class Xud extends EventEmitter {
213213
shutdown: this.beginShutdown,
214214
});
215215

216+
this.service.on('logLevel', (level) => {
217+
this.swapClientManager?.setLogLevel(level);
218+
Object.values(loggers).forEach((logger) => {
219+
logger.setLogLevel(level);
220+
});
221+
});
222+
216223
if (this.swapClientManager.connextClient?.isOperational()) {
217224
this.httpServer = new HttpServer(loggers.http, this.service);
218225
await this.httpServer.listen(

lib/cli/commands/loglevel.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Arguments, Argv } from 'yargs';
2+
import { LogLevel, SetLogLevelRequest } from '../../proto/xudrpc_pb';
3+
import { callback, loadXudClient } from '../command';
4+
import { LevelPriority } from '../../Logger';
5+
6+
export const command = 'loglevel <level>';
7+
8+
export const describe = 'set the logging level for xud';
9+
10+
export const builder = (argv: Argv) => argv
11+
.positional('level', {
12+
description: 'the logging level',
13+
type: 'string',
14+
choices: ['alert', 'error', 'warn', 'verbose', 'info', 'debug', 'trace'],
15+
coerce: (logLevelStr: string) => {
16+
const logLevelLower = logLevelStr.toLowerCase();
17+
return logLevelLower;
18+
},
19+
})
20+
.example('$0 loglevel trace', 'set log level to trace')
21+
.example('$0 loglevel info', 'set log level to info');
22+
23+
export const handler = async (argv: Arguments<any>) => {
24+
const request = new SetLogLevelRequest();
25+
const levelPriority = LevelPriority[argv.level] as unknown as number;
26+
const logLevel: LogLevel = levelPriority as LogLevel;
27+
request.setLogLevel(logLevel);
28+
(await loadXudClient(argv)).setLogLevel(request, callback(argv));
29+
};

lib/cli/commands/unlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const describe = 'unlock local xud node';
1010
export const builder = {};
1111

1212
const formatOutput = (response: UnlockNodeResponse.AsObject) => {
13-
console.log('xud was unlocked succesfully');
13+
console.log('xud was unlocked successfully');
1414
if (response.unlockedLndsList.length) {
1515
console.log(`The following wallets were unlocked: ${response.unlockedLndsList.join(', ')}`);
1616
}

lib/cli/placeorder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export const placeOrderBuilder = (argv: Argv, side: OrderSide) => {
4040
})
4141
.example(`$0 ${command} 5 LTC/BTC .01 1337`, `place a limit order to ${command} 5 LTC @ 0.01 BTC with local order id 1337`)
4242
.example(`$0 ${command} max LTC/BTC .01`, `place a limit order to ${command} max LTC @ 0.01 BTC`)
43-
.example(`$0 ${command} max BTC/USDT mkt`, `place a market order to ${command} max BTC for USDT`)
4443
.example(`$0 ${command} 3 BTC/USDT mkt`, `place a market order to ${command} 3 BTC for USDT`)
4544
.example(`$0 ${command} 1 BTC/USDT market`, `place a market order to ${command} 1 BTC for USDT`);
4645
};

lib/grpc/GrpcService.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,20 @@ class GrpcService {
843843
}
844844
}
845845

846+
public setLogLevel: grpc.handleUnaryCall<xudrpc.SetLogLevelRequest, xudrpc.SetLogLevelResponse> = async (call, callback) => {
847+
if (!this.isReady(this.service, callback)) {
848+
return;
849+
}
850+
try {
851+
await this.service.setLogLevel(call.request.toObject());
852+
853+
const response = new xudrpc.SetLogLevelResponse();
854+
callback(null, response);
855+
} catch (err) {
856+
callback(getGrpcError(err), null);
857+
}
858+
}
859+
846860
public shutdown: grpc.handleUnaryCall<xudrpc.ShutdownRequest, xudrpc.ShutdownResponse> = (_, callback) => {
847861
if (!this.isReady(this.service, callback)) {
848862
return;

lib/grpc/getGrpcError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const getGrpcError = (err: any) => {
2222
case orderErrorCodes.MIN_QUANTITY_VIOLATED:
2323
case orderErrorCodes.QUANTITY_DOES_NOT_MATCH:
2424
case swapErrorCodes.REMOTE_IDENTIFIER_MISSING:
25+
case orderErrorCodes.DUPLICATE_PAIR_CURRENCIES:
2526
code = status.INVALID_ARGUMENT;
2627
break;
2728
case orderErrorCodes.PAIR_DOES_NOT_EXIST:

lib/orderbook/OrderBook.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ class OrderBook extends EventEmitter {
290290

291291
public addPair = async (pair: Pair) => {
292292
const pairId = derivePairId(pair);
293+
if (pair.baseCurrency.toLowerCase() === pair.quoteCurrency.toLowerCase()) {
294+
throw errors.DUPLICATE_PAIR_CURRENCIES(pair.baseCurrency, pair.quoteCurrency);
295+
}
293296
if (this.pairInstances.has(pairId)) {
294297
throw errors.PAIR_ALREADY_EXISTS(pairId);
295298
}

lib/orderbook/errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const errorCodes = {
1616
INSUFFICIENT_OUTBOUND_BALANCE: codesPrefix.concat('.12'),
1717
MIN_QUANTITY_VIOLATED: codesPrefix.concat('.13'),
1818
QUANTITY_ON_HOLD: codesPrefix.concat('.15'),
19+
DUPLICATE_PAIR_CURRENCIES: codesPrefix.concat('.16'),
1920
};
2021

2122
const errors = {
@@ -75,6 +76,10 @@ const errors = {
7576
message: `order with local id ${localId} has a quantity of ${holdQuantity} satoshis on hold, try again later`,
7677
code: errorCodes.QUANTITY_DOES_NOT_MATCH,
7778
}),
79+
DUPLICATE_PAIR_CURRENCIES: (baseCurrency: string, quoteCurrency: string) => ({
80+
message: `base asset (${baseCurrency}) and quote asset (${quoteCurrency}) have to be different`,
81+
code: errorCodes.DUPLICATE_PAIR_CURRENCIES,
82+
}),
7883
};
7984

8085
export { errorCodes };

0 commit comments

Comments
 (0)