Skip to content

Commit ce003b0

Browse files
committed
api address
1 parent 77821a0 commit ce003b0

3 files changed

Lines changed: 115 additions & 4 deletions

File tree

src/commands/api/AddressCommand.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
}

src/commands/api/ApiCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Command, CommandRunner } from 'nest-commander';
22
import { CandidateCommand } from './CandidateCommand';
3+
import {AddressCommand} from "./AddressCommand";
34

45
@Command({
56
name: 'api',
6-
subCommands: [CandidateCommand],
7+
subCommands: [CandidateCommand, AddressCommand],
78
description: 'Api v2 for Minter Node',
89
// options: { isDefault: true }
910
})

src/commands/api/CandidateCommand.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ContentExporter } from '../../services/ContentExporter';
99
description: 'Candidate returns candidate’s info by provided public key',
1010
})
1111
export class CandidateCommand extends CommandRunner {
12-
private skip_pip2bip = false;
12+
private skipPip2Bip = false;
1313

1414
constructor(private contentExporter: ContentExporter) {
1515
super();
@@ -35,7 +35,7 @@ export class CandidateCommand extends CommandRunner {
3535
.getCandidateGrpc(candidate, options.not_show_stakes, options.height)
3636
.then((r) => {
3737
const result = r.toObject();
38-
this.contentExporter.print(result, this.skip_pip2bip, options);
38+
this.contentExporter.print(result, this.skipPip2Bip, options);
3939
})
4040
.catch(console.log);
4141
return Promise.resolve(undefined);
@@ -104,7 +104,7 @@ export class CandidateCommand extends CommandRunner {
104104
defaultValue: false,
105105
})
106106
parseSkipPip2Bip(val: string): boolean {
107-
this.skip_pip2bip = true;
107+
this.skipPip2Bip = true;
108108
return JSON.parse(val);
109109
}
110110
}

0 commit comments

Comments
 (0)