Skip to content

Commit f65fed1

Browse files
committed
deploy and exploreDeploy commands
1 parent dc8950d commit f65fed1

2 files changed

Lines changed: 64 additions & 3 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,13 @@ To transfer:
1111
To check balance:
1212
```
1313
./rpub-cli --balance --revAddress <string> --readOnlyHost <url> --decimals <number> --ticker <string>
14+
```
15+
16+
To deploy:
17+
```
18+
./rpub-cli --deploy --privateKey <string> --files <string> --validatorHost <url>
19+
```
20+
To deploy:
21+
```
22+
./rpub-cli --exploreDeploy --privateKey <string> --files <string> --readOnlyHost <url>
1423
```

src/index.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import commandLineArgs from "command-line-args";
77
const optionDefinitions = [
88
{ name: 'transfer', alias: 's', type: Boolean },
99
{ name: 'balance', alias: 'c', type: Boolean },
10+
{ name: 'exploreDeploy', alias: 'e', type: Boolean },
11+
{ name: 'deploy', alias: 'x', type: Boolean },
12+
{ name: 'files', alias: 'f', type: String, multiple: true},
1013
{ name: 'decimals', alias: 'd', type: Number, multiple: false},
1114
{ name: 'ticker', alias: 't', type: String, multiple: false},
1215
{ name: 'revAddressTo', alias: 'r', type: String, multiple: false},
@@ -25,6 +28,7 @@ const privateKey = options.privateKey;
2528
const revAddressTo = options.revAddressTo;
2629
const revAddress = options.revAddress;
2730
const revAmount = options.amount;
31+
const files = options.files;
2832

2933

3034
var logStream = fs.createWriteStream(process.argv[0] + ".log");
@@ -63,7 +67,7 @@ const runFunction = async function () {
6367
process.exit(0);
6468
});
6569

66-
if (options.transfer && revAmount && revAddressTo) {
70+
if (options.transfer && revAmount && revAddressTo && privateKey) {
6771
const pubKeyFromPrivKey = rchainToolkit.utils.publicKeyFromPrivateKey(privateKey);
6872
const revAddressFrom = rchainToolkit.utils.revAddressFromPublicKey(pubKeyFromPrivKey);
6973

@@ -122,7 +126,7 @@ const runFunction = async function () {
122126

123127
const parsedResult = JSON.parse(result);
124128
if (parsedResult.expr && parsedResult.expr.length) {
125-
const balance = rchainToolkit.utils.rhoValToJs(JSON.parse(result).expr[0]);
129+
const balance = rchainToolkit.utils.rhoValToJs(parsedResult.expr[0]);
126130

127131
const revBalance = showTokenDecimal(balance, DECIMALS);
128132

@@ -133,11 +137,59 @@ const runFunction = async function () {
133137
console.log(err);
134138
}
135139
}
140+
else if ((options.exploreDeploy || options.deploy && privateKey) && files && files.length > 0) {
141+
const filesDeployed: Array<Promise<String>> = files.map(file => {
142+
const term = fs.readFileSync(file, 'utf8');
143+
if (options.deploy) {
144+
return new Promise<string>((resolve, reject) => {
145+
resolve(rchainToolkit.http.easyDeploy(
146+
VALIDATOR_HOST,
147+
term,
148+
privateKey,
149+
'auto',
150+
100000000,
151+
240000
152+
));
153+
});
154+
} else {
155+
return new Promise<string>((resolve, reject) => {
156+
resolve(rchainToolkit.http.exploreDeploy(READ_ONLY_HOST, {
157+
term: term,
158+
}));
159+
});
160+
}
161+
});
162+
163+
let ret = [];
164+
if (filesDeployed.length > 0) {
165+
ret = await Promise.all(filesDeployed);
166+
}
167+
168+
ret.forEach((dataAtNameResponse) => {
169+
const parsedResult = JSON.parse(dataAtNameResponse);
170+
if (options.deploy && parsedResult.exprs && parsedResult.exprs.length) {
171+
const data = rchainToolkit.utils.rhoValToJs(
172+
parsedResult.exprs[0].expr
173+
);
174+
console.info(data);
175+
}
176+
177+
if (options.exploreDeploy && parsedResult.expr && parsedResult.expr.length) {
178+
const data = rchainToolkit.utils.rhoValToJs(
179+
parsedResult.expr[0]
180+
);
181+
console.info(data);
182+
}
183+
});
184+
185+
}
136186
else {
137-
console.log("Usage: rpub-cli [--transfer|--balance] [--privateKey|--revAddress] [--amount] [--revAddressTo] [--validatorHost] [--readOnlyHost] [--decimals] [--ticker]");
187+
console.log("Usage: rpub-cli [--transfer|--balance|--deploy|--exploreDeploy] [--files] [--privateKey|--revAddress] [--amount] [--revAddressTo] [--validatorHost] [--readOnlyHost] [--decimals] [--ticker]");
138188
console.log("");
139189
console.log("To transfer: ./rpub-cli --transfer --privateKey <string> --amount <number> --revAddressTo <string> --validatorHost <url>");
140190
console.log("To check balance: ./rpub-cli --balance --revAddress <string> --readOnlyHost <url> --decimals <number> --ticker <string>");
191+
console.log("To deploy: ./rpub-cli --deploy --privateKey <string> --files <string> --validatorHost <url>");
192+
console.log("To deploy: ./rpub-cli --exploreDeploy --files <string> --readOnlyHost <url>");
141193
}
142194
}
143195

0 commit comments

Comments
 (0)