Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): InitSwapClient #1961

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions docs/api.md

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

1 change: 1 addition & 0 deletions lib/Xud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class Xud extends EventEmitter {

this.service = new Service({
version,
nodeKey,
orderBook: this.orderBook,
swapClientManager: this.swapClientManager,
pool: this.pool,
Expand Down
32 changes: 32 additions & 0 deletions lib/cli/commands/initclient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Arguments, Argv } from 'yargs';
import { SwapClientType } from '../../constants/enums';
import { InitSwapClientRequest } from '../../proto/xudrpc_pb';
import { callback, loadXudClient } from '../command';

export const command = 'initclient <swap_client> [currency]';

export const describe = 'initialize a swap client with the xud master key & password';

export const builder = (argv: Argv) => argv
.positional('swap_client', {
description: 'the swap client to initialize',
type: 'string',
choices: ['Lnd', 'Connext'],
coerce: (swapClientStr: string) => {
const swapClientLower = swapClientStr.toLowerCase();
return swapClientLower.charAt(0).toUpperCase() + swapClientLower.slice(1);
},
})
.option('currency', {
description: 'the currency for the swap client, if applicable',
type: 'string',
})
.example('$0 initclient Lnd LTC', 'initialize an Lnd client for LTC')
.example('$0 initclient Connext', 'initialize a Connext client');

export const handler = async (argv: Arguments<any>) => {
const request = new InitSwapClientRequest();
request.setSwapClient(Number(SwapClientType[argv.swap_client]));
request.setCurrency(argv.currency.toUpperCase());
(await loadXudClient(argv)).initSwapClient(request, callback(argv));
};
17 changes: 17 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,23 @@ class GrpcService {
}
}

/**
* See [[Service.initSwapClient]]
*/
public initSwapClient: grpc.handleUnaryCall<xudrpc.InitSwapClientRequest, xudrpc.InitSwapClientResponse> = async (call, callback) => {
if (!this.isReady(this.service, callback)) {
return;
}
try {
await this.service.initSwapClient(call.request.toObject());
const response = new xudrpc.InitSwapClientResponse();

callback(null, response);
} catch (err) {
callback(getGrpcError(err), null);
}
}

/**
* See [[Service.tradingLimits]]
*/
Expand Down
59 changes: 50 additions & 9 deletions lib/proto/xudrpc.swagger.json

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

17 changes: 17 additions & 0 deletions lib/proto/xudrpc_grpc_pb.d.ts

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

36 changes: 36 additions & 0 deletions lib/proto/xudrpc_grpc_pb.js

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

Loading