Skip to content

Commit

Permalink
feat(cli): add getethmnemonic
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl Ranna committed Jan 28, 2021
1 parent b12a01e commit 8007801
Show file tree
Hide file tree
Showing 16 changed files with 1,851 additions and 796 deletions.
19 changes: 19 additions & 0 deletions docs/api.md

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

20 changes: 20 additions & 0 deletions lib/cli/commands/getethmnemonic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Arguments } from 'yargs';
import { GetMnemonicRequest, GetEthMnemonicResponse } from '../../proto/xudrpc_pb';
import { callback, loadXudClient } from '../command';
import { ethers } from 'ethers';

const formatOutput = (response: GetEthMnemonicResponse.AsObject) => {
const { seedMnemonic } = response;
console.log(`Your Ethereum account mnemonic seed is: "${seedMnemonic}"`);
const wallet = ethers.Wallet.fromMnemonic(seedMnemonic);
console.log(`\nAlternatively, you can also use the following private key to import account with MetaMask: "${wallet.privateKey}"`);
console.log('\nHow to import an account: https://metamask.zendesk.com/hc/en-us/articles/360015489331-How-to-import-an-Account');
};

export const command = 'getethmnemonic';

export const describe = 'show the Ethereum seed mnemonic';

export const handler = async (argv: Arguments) => {
(await loadXudClient(argv)).getETHMnemonic(new GetMnemonicRequest(), callback(argv, formatOutput));
};
17 changes: 17 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,23 @@ class GrpcService {
}
}

/**
* See [[Service.getETHMnemonic]]
*/
public getETHMnemonic: grpc.handleUnaryCall<xudrpc.GetMnemonicRequest, xudrpc.GetEthMnemonicResponse> = async (_, callback) => {
if (!this.isReady(this.service, callback)) {
return;
}
try {
const mnemonic = await this.service.getETHMnemonic();
const response = new xudrpc.GetEthMnemonicResponse();
response.setSeedMnemonic(mnemonic);
callback(null, response);
} catch (err) {
callback(getGrpcError(err), null);
}
}

/**
* See [[Service.getNodeInfo]]
*/
Expand Down
25 changes: 25 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.

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.

24 changes: 24 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.

21 changes: 21 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.

Loading

0 comments on commit 8007801

Please sign in to comment.