Skip to content

Commit c8f6400

Browse files
committed
force replace PIP to BIP
1 parent d3569de commit c8f6400

4 files changed

Lines changed: 51 additions & 9 deletions

File tree

src/commands/api/CandidateCommand.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {MinterApiService} from '../../services/minter-api/minter-api.service';
33
import {JsonPatches} from "../../utils/JsonPatches";
44

55
import {search} from 'jmespath'
6+
import {MagicPipConvert} from "../../questions/MagicPipConvert";
7+
68
// import * as jmespath from 'jmespath'
79

810
@SubCommand({
@@ -19,27 +21,38 @@ export class CandidateCommand extends CommandRunner {
1921

2022
async run(
2123
inputs: string[],
22-
options: { height?: number; not_show_stakes?: boolean; config: string; patch?: string; patches: boolean; pretty: boolean },
24+
options: {
25+
height?: number;
26+
not_show_stakes?: boolean;
27+
config: string;
28+
patch?: string;
29+
patches: boolean;
30+
pretty: boolean
31+
},
2332
): Promise<void> {
2433
// const {patch, config} = options;
2534
const candidate = inputs[0];
2635
const minterApi = new MinterApiService(options.config);
2736

2837
minterApi.api().getCandidateGrpc(candidate, options.not_show_stakes, options.height).then((r) => {
2938
const result = r.toObject()
30-
let out: any;
39+
let out: any;
40+
// const mpc = new MagicPipConvert()
3141
if (options.patches) {
3242
new JsonPatches().printPropertyNames(result)
3343
} else if (options.patch && options.patch.length > 0) {
3444
// out=result[options.patch]
35-
out=search(result,options.patch)
45+
out = search(result, options.patch)
46+
} else {
47+
out = result
48+
}
49+
out = new MagicPipConvert().replaceLongNumericStrings(out)
50+
if (!options.pretty) {
51+
process.stdout.write(JSON.stringify(out));
3652
} else {
37-
out=result
53+
console.warn((out))
54+
// console.warn(out)
3855
}
39-
if (!options.pretty)
40-
process.stdout.write(JSON.stringify(out));
41-
else
42-
console.warn(out)
4356
}
4457
)
4558
.catch(console.log);
@@ -92,6 +105,7 @@ export class CandidateCommand extends CommandRunner {
92105
parsePatches(val: string): boolean {
93106
return JSON.parse(val);
94107
}
108+
95109
@Option({
96110
flags: '--pretty [boolean]',
97111
description: 'Pretty',

src/commands/wallet/WalletSendCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "minter-js-sdk/src/utils";
88
import {ConfigMinterService} from "../../services/config/minter/config-minter.service";
99
import {parseNumber} from "../../utils/parseNumber";
10-
import {Wallet} from "../../utils/Wallet";
10+
import {Wallet} from "../../core/Wallet";
1111
import {CANCEL_MESSAGE, ConfirmQuestion} from "../../questions/ConfirmQuestion";
1212

1313

File renamed without changes.

src/questions/MagicPipConvert.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {ConvertAmount} from "minter-typescript-sdk";
2+
3+
export class MagicPipConvert {
4+
private minLength = 12;
5+
6+
private convertAmount = new ConvertAmount()
7+
8+
replaceLongNumericStrings(input: any): any {
9+
if (Array.isArray(input)) {
10+
return input.map(item => this.replaceLongNumericStrings(item));
11+
} else if (typeof input === 'object' && input !== null) {
12+
const result: { [key: string]: any } = {};
13+
for (const key in input) {
14+
if (input.hasOwnProperty(key)) {
15+
result[key] = this.replaceLongNumericStrings(input[key]);
16+
}
17+
}
18+
return result;
19+
} else if (typeof input === 'string') {
20+
21+
if (/^\d+$/.test(input) && input.length >= this.minLength) {
22+
return this.convertAmount.toBip(input);
23+
}
24+
}
25+
return input;
26+
27+
}
28+
}

0 commit comments

Comments
 (0)