Skip to content

Commit

Permalink
feat(rpc): add flag for connext to unlock response
Browse files Browse the repository at this point in the history
This adds a flag to the `UnlockNode` response to indicate whether
a Connext client is connected and ready to accept calls. In the cli,
`ETH` gets added to the list of wallets that are unlocked and ready when
this new flag is true.

Closes #1932.
  • Loading branch information
sangaman committed Oct 28, 2020
1 parent 8483e1e commit 40ffaba
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 159 deletions.
1 change: 1 addition & 0 deletions docs/api.md

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

8 changes: 6 additions & 2 deletions lib/cli/commands/unlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ export const builder = {};

const formatOutput = (response: UnlockNodeResponse.AsObject) => {
console.log('xud was unlocked successfully');
const readyClients = response.unlockedLndsList;
if (response.connextReady) {
readyClients.push('ETH');
}
if (response.unlockedLndsList.length) {
console.log(`The following wallets were unlocked: ${response.unlockedLndsList.join(', ')}`);
console.log(`The following wallets are unlocked and ready: ${readyClients.join(', ')}`);
}
if (response.lockedLndsList.length) {
console.log(`The following wallets could not be unlocked: ${response.lockedLndsList.join(', ')}`);
console.log(`The following wallets could not be unlocked: ${readyClients.join(', ')}`);
}
};

Expand Down
1 change: 1 addition & 0 deletions lib/grpc/GrpcInitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class GrpcInitService {
const response = new xudrpc.UnlockNodeResponse();
response.setUnlockedLndsList(unlockNodeResult.unlockedLndClients);
response.setLockedLndsList(unlockNodeResult.lockedLndClients);
response.setConnextReady(unlockNodeResult.connextReady);

callback(null, response);
} catch (err) {
Expand Down
5 changes: 5 additions & 0 deletions lib/proto/xudrpc.swagger.json

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

4 changes: 4 additions & 0 deletions lib/proto/xudrpc_pb.d.ts

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

31 changes: 30 additions & 1 deletion lib/proto/xudrpc_pb.js

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

13 changes: 10 additions & 3 deletions lib/swaps/SwapClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class SwapClientManager extends EventEmitter {
const unlockWalletPromises: Promise<any>[] = [];
const unlockedLndClients: string[] = [];
const lockedLndClients: string[] = [];
let connextReady = false;

for (const swapClient of this.swapClients.values()) {
if (isLndClient(swapClient)) {
Expand All @@ -294,18 +295,24 @@ class SwapClientManager extends EventEmitter {
swapClient.logger.debug(`could not unlock wallet: ${err.message}`);
});
unlockWalletPromises.push(unlockWalletPromise);
} else if (swapClient.isConnected()) {
// if the swap client is already unlocked, we add it to the list
unlockedLndClients.push(swapClient.currency);
} else if (swapClient.isDisconnected() || swapClient.isMisconfigured() || swapClient.isNotInitialized()) {
// if the swap client is not connected, we treat it as locked since lnd will likely be locked when it comes online
lockedLndClients.push(swapClient.currency);
}
} else if (isConnextClient(swapClient)) {
// TODO(connext): unlock Connext using connextSeed
if (swapClient.isConnected()) {
connextReady = true;
}
}
}

await Promise.all(unlockWalletPromises);

// TODO(connext): unlock Connext using connextSeed

return { unlockedLndClients, lockedLndClients };
return { unlockedLndClients, lockedLndClients, connextReady };
}

/**
Expand Down
2 changes: 2 additions & 0 deletions proto/xudrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,8 @@ message UnlockNodeResponse {
repeated string unlocked_lnds = 1;
// The list of lnd clients that could not be unlocked.
repeated string locked_lnds = 3;
// Whether the Connext client is connected and ready to accept calls.
bool connext_ready = 4;
}

message WithdrawRequest {
Expand Down
Loading

0 comments on commit 40ffaba

Please sign in to comment.