|
| 1 | +import { Option, CommandRunner, SubCommand } from 'nest-commander'; |
| 2 | +import { MinterApiService } from '../../services/minter-api/minter-api.service'; |
| 3 | +import { ContentExporter } from '../../services/ContentExporter'; |
| 4 | + |
| 5 | +@SubCommand({ |
| 6 | + name: 'address', |
| 7 | + arguments: '<address>', |
| 8 | + argsDescription: { public_key: 'address: Mx...' }, |
| 9 | + description: 'Address returns coins list, balance and transaction count of an address', |
| 10 | +}) |
| 11 | +export class AddressCommand extends CommandRunner { |
| 12 | + private skipPip2Bip = false; |
| 13 | + |
| 14 | + constructor(private contentExporter: ContentExporter) { |
| 15 | + super(); |
| 16 | + } |
| 17 | + |
| 18 | + async run( |
| 19 | + inputs: string[], |
| 20 | + options: { |
| 21 | + height?: number; |
| 22 | + delegated?: boolean; |
| 23 | + config: string; |
| 24 | + patch?: string; |
| 25 | + patches: boolean; |
| 26 | + pretty: boolean; |
| 27 | + }, |
| 28 | + ): Promise<void> { |
| 29 | + // const {patch, config} = options; |
| 30 | + const candidate = inputs[0]; |
| 31 | + const minterApi = new MinterApiService(options.config); |
| 32 | + |
| 33 | + minterApi |
| 34 | + .api() |
| 35 | + .getAddressGrpc(candidate, options.delegated, options.height) |
| 36 | + .then((r) => { |
| 37 | + const result = r.toObject(); |
| 38 | + this.contentExporter.print(result, this.skipPip2Bip, options); |
| 39 | + }) |
| 40 | + .catch(console.log); |
| 41 | + return Promise.resolve(undefined); |
| 42 | + } |
| 43 | + |
| 44 | + @Option({ |
| 45 | + flags: '--height [number]', |
| 46 | + name: 'Height', |
| 47 | + description: |
| 48 | + 'Blockchain state height for the current request. Optional, the last default state of the node is used', |
| 49 | + }) |
| 50 | + parseNumber(val: string): number { |
| 51 | + return Number(val); |
| 52 | + } |
| 53 | + |
| 54 | + @Option({ |
| 55 | + flags: '-d, --delegated [boolean]', |
| 56 | + description: |
| 57 | + 'delegated', |
| 58 | + defaultValue: false, |
| 59 | + }) |
| 60 | + parseBoolean(val: string): boolean { |
| 61 | + return JSON.parse(val); |
| 62 | + } |
| 63 | + |
| 64 | + @Option({ |
| 65 | + flags: '-c, --config [string]', |
| 66 | + description: 'path to config file', |
| 67 | + defaultValue: 'config.yml', |
| 68 | + }) |
| 69 | + parseConfig(val: string): string { |
| 70 | + return val; |
| 71 | + } |
| 72 | + |
| 73 | + @Option({ |
| 74 | + flags: '-p, --patch [string]', |
| 75 | + description: 'path JMESPath format', |
| 76 | + // defaultValue: 'status', |
| 77 | + }) |
| 78 | + parsePatch(val: string): string { |
| 79 | + return val; |
| 80 | + } |
| 81 | + |
| 82 | + @Option({ |
| 83 | + flags: '-pl, --patches [boolean]', |
| 84 | + description: 'list of patches', |
| 85 | + // defaultValue: false, |
| 86 | + }) |
| 87 | + parsePatches(val: string): boolean { |
| 88 | + return JSON.parse(val); |
| 89 | + } |
| 90 | + |
| 91 | + @Option({ |
| 92 | + flags: '--pretty [boolean]', |
| 93 | + description: 'Pretty', |
| 94 | + defaultValue: true, |
| 95 | + }) |
| 96 | + parsePretty(val: string): boolean { |
| 97 | + return JSON.parse(val); |
| 98 | + } |
| 99 | + |
| 100 | + @Option({ |
| 101 | + flags: '--skip_pip2bip', |
| 102 | + name: 'skip_pip2bip', |
| 103 | + description: 'Skip convert PIP to BIP', |
| 104 | + defaultValue: false, |
| 105 | + }) |
| 106 | + parseSkipPip2Bip(val: string): boolean { |
| 107 | + this.skipPip2Bip = true; |
| 108 | + return JSON.parse(val); |
| 109 | + } |
| 110 | +} |
0 commit comments