mirror of https://github.com/certusone/santa.git
update arg parser
This commit is contained in:
parent
1d0ba63c44
commit
713d62e12b
|
@ -4,8 +4,19 @@ const core = require("@terra-money/core");
|
|||
const rest_1 = require("./utils/rest");
|
||||
const big_js_1 = require("big.js");
|
||||
const fs = require("fs");
|
||||
const rest = new rest_1.default("http://127.0.0.1:1317");
|
||||
const outputFile = "./unsignedTx.json";
|
||||
process.argv = process.argv.slice(2);
|
||||
const argv = {};
|
||||
for (let i in process.argv) {
|
||||
const tmp = process.argv[i].split('=');
|
||||
argv[tmp[0]] = tmp[1];
|
||||
}
|
||||
const lcdURL = argv['lcd'] || "http://127.0.0.1:1317";
|
||||
const outputPath = argv['output'] || "./unsignedTx.json";
|
||||
const logLevel = argv['log'] || 'debug';
|
||||
console.log(`lcd path: ${lcdURL}`);
|
||||
console.log(`output file path: ${outputPath}`);
|
||||
console.log(`\n\n`);
|
||||
const rest = new rest_1.default(lcdURL);
|
||||
const foundationAddress = "terra1dp0taj85ruc299rkdvzp4z5pfg6z6swaed74e6";
|
||||
const goliathValAddress = "terravaloper163phlen6dn7sp9khhjar2gqqx6kga0ly8d7h9g";
|
||||
const marineValAddress = "terravaloper1d3hatwcsvkktgwp3elglw9glca0h42yg6xy4lp";
|
||||
|
@ -87,7 +98,10 @@ async function computeDelegatorRewardRatio(rewardRatioMap, validators) {
|
|||
}
|
||||
async function main() {
|
||||
const foundationRewards = await loadFoundationRewards();
|
||||
console.debug("Foundation Rewards:", foundationRewards);
|
||||
if (logLevel == 'debug') {
|
||||
console.debug(`Foundation Rewards:`, foundationRewards);
|
||||
console.debug(`\n\n`);
|
||||
}
|
||||
const validators = await rest.loadValidators();
|
||||
if (!validators) {
|
||||
console.error("no validator found");
|
||||
|
@ -95,9 +109,15 @@ async function main() {
|
|||
}
|
||||
const rewardRatioMap = {};
|
||||
computeValidatorsRewardRatio(rewardRatioMap, validators);
|
||||
console.info("Validator Bonus Rewards: ", rewardRatioMap);
|
||||
if (logLevel == 'debug') {
|
||||
console.debug(`Validator Bonus Rewards:`, rewardRatioMap);
|
||||
console.debug(`\n\n`);
|
||||
}
|
||||
await computeDelegatorRewardRatio(rewardRatioMap, validators);
|
||||
console.info("Total Rewards: ", rewardRatioMap);
|
||||
if (logLevel == 'debug') {
|
||||
console.debug(`Total Rewards:`, rewardRatioMap);
|
||||
console.debug(`\n\n`);
|
||||
}
|
||||
// Rotate reward ratio and build msg input
|
||||
let totalRatio = big_js_1.default(0);
|
||||
const outputs = [];
|
||||
|
@ -137,12 +157,13 @@ async function main() {
|
|||
denom: "ukrw",
|
||||
amount: "1000000"
|
||||
}] }, "reward distribution");
|
||||
fs.writeFile(outputFile, JSON.stringify(unSingedTx, null, 4), function (err) {
|
||||
fs.writeFile(outputPath, JSON.stringify(unSingedTx, null, 4), function (err) {
|
||||
if (err) {
|
||||
console.error("Writing Failed", err);
|
||||
return process.exit(-1);
|
||||
}
|
||||
else {
|
||||
console.info("Writing Succeed", `Please check ${outputFile}`);
|
||||
console.info("Writing Succeed", `Please check ${outputPath}`);
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -15,6 +15,7 @@
|
|||
"@types/axios": "^0.14.0",
|
||||
"@types/big.js": "^4.0.5",
|
||||
"@types/loglevel": "^1.5.4",
|
||||
"@types/minimist": "^1.2.0",
|
||||
"axios": "^0.19.0",
|
||||
"big.js": "^5.2.2",
|
||||
"loglevel": "^1.6.3"
|
||||
|
|
39
src/index.ts
39
src/index.ts
|
@ -3,9 +3,23 @@ import {default as RestInterface, Coin, Validator, ValidatorRewardsInfo} from ".
|
|||
import bn from "big.js"
|
||||
import * as fs from "fs"
|
||||
|
||||
process.argv = process.argv.slice(2)
|
||||
|
||||
const rest = new RestInterface("http://127.0.0.1:1317")
|
||||
const outputFile = "./unsignedTx.json"
|
||||
const argv = {}
|
||||
for (let i in process.argv) {
|
||||
const tmp = process.argv[i].split('=')
|
||||
argv[tmp[0]] = tmp[1]
|
||||
}
|
||||
|
||||
const lcdURL = argv['lcd'] || "http://127.0.0.1:1317"
|
||||
const outputPath = argv['output'] || "./unsignedTx.json"
|
||||
const logLevel = argv['log'] || 'debug'
|
||||
|
||||
console.log(`lcd path: ${lcdURL}`)
|
||||
console.log(`output file path: ${outputPath}`)
|
||||
console.log(`\n`)
|
||||
|
||||
const rest = new RestInterface(lcdURL)
|
||||
|
||||
const foundationAddress = "terra1dp0taj85ruc299rkdvzp4z5pfg6z6swaed74e6"
|
||||
const goliathValAddress = "terravaloper163phlen6dn7sp9khhjar2gqqx6kga0ly8d7h9g"
|
||||
|
@ -101,7 +115,11 @@ async function computeDelegatorRewardRatio(rewardRatioMap: object, validators: A
|
|||
async function main() {
|
||||
|
||||
const foundationRewards = await loadFoundationRewards()
|
||||
console.debug("Foundation Rewards:", foundationRewards)
|
||||
if (logLevel == 'debug') {
|
||||
console.debug(`Foundation Rewards:`, foundationRewards)
|
||||
console.debug(`\n`)
|
||||
}
|
||||
|
||||
|
||||
const validators = await rest.loadValidators()
|
||||
if (!validators) {
|
||||
|
@ -111,10 +129,16 @@ async function main() {
|
|||
|
||||
const rewardRatioMap = {}
|
||||
computeValidatorsRewardRatio(rewardRatioMap, validators)
|
||||
console.info("Validator Bonus Rewards: ", rewardRatioMap)
|
||||
if (logLevel == 'debug') {
|
||||
console.debug(`Validator Bonus Rewards:`, rewardRatioMap)
|
||||
console.debug(`\n`)
|
||||
}
|
||||
|
||||
await computeDelegatorRewardRatio(rewardRatioMap, validators)
|
||||
console.info("Total Rewards: ", rewardRatioMap)
|
||||
if (logLevel == 'debug') {
|
||||
console.debug(`Total Rewards:`, rewardRatioMap)
|
||||
console.debug(`\n`)
|
||||
}
|
||||
|
||||
// Rotate reward ratio and build msg input
|
||||
let totalRatio = bn(0)
|
||||
|
@ -162,11 +186,12 @@ async function main() {
|
|||
amount: "1000000"
|
||||
}]}, "reward distribution")
|
||||
|
||||
fs.writeFile(outputFile, JSON.stringify(unSingedTx, null, 4), function(err) {
|
||||
fs.writeFile(outputPath, JSON.stringify(unSingedTx, null, 4), function(err) {
|
||||
if (err) {
|
||||
console.error("Writing Failed", err);
|
||||
return process.exit(-1)
|
||||
} else {
|
||||
console.info("Writing Succeed", `Please check ${outputFile}`)
|
||||
console.info("Writing Succeed", `Please check ${outputPath}`)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue