Skip to content

Commit

Permalink
Code clean and fix some issues (#34)
Browse files Browse the repository at this point in the history
* clearful test mode

* update tips

* tips

* improve logs

* update publisher log

---------

Co-authored-by: Guantong <[email protected]>
  • Loading branch information
fewensa and jiguantong authored Nov 1, 2024
1 parent 1efcca6 commit 7c3656d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/publisher-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"reflect-metadata": "^0.2.2",
"typedi": "^0.10.0",
"viem": "^2.21.28",
"web3": "^4.13.0"
"web3": "^4.13.0",
"chalk": "^4"
}
}
6 changes: 3 additions & 3 deletions packages/publisher-client/src/command/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class PublisherStarter {
private nearEthereumMap: Record<string, NearEthereum> = {};

async start(options: StartOptions) {
this._nearGraphqlEndpoint = XAPIConfig.graphql.endpoint(options.testnet ? "near-testnet" : "near");
this._nearGraphqlEndpoint = XAPIConfig.graphql.endpoint(options.testnet ? "near-testnet" : "near");

const publisherCache = new PublisherStorage(`${homedir}/.xapi-publisher/`);
while (true) {
Expand Down Expand Up @@ -534,12 +534,12 @@ export class PublisherStarter {
const balance = await aggregatorAccount.getAccountBalance();
const availableBalance = new Decimal(balance.available).div(new Decimal('1000000000000000000000000'));
if (availableBalance.comparedTo(MINIMUM_AGGREGATOR_NEAR.add(new Decimal(signerDepositRequired))) < 0) {
logger.warn(`==== ❌ Avaliable Balance of ${aggregator}: ${availableBalance.toFixed(4)} NEAR < ${MINIMUM_AGGREGATOR_NEAR} NEAR + ${signerDepositRequired} NEAR, break ====`, {
logger.warn(`==== ❌ Avaliable Balance of ${aggregator}: ${availableBalance.toFixed(4)} NEAR < (${MINIMUM_AGGREGATOR_NEAR} + ${signerDepositRequired}) NEAR, break ====`, {
target: "check-aggregator-balance"
});
return false;
} else {
logger.info(`==== ✅ Avaliable Balance of ${aggregator}: ${availableBalance.toFixed(4)} NEAR >= ${MINIMUM_AGGREGATOR_NEAR} NEAR + ${signerDepositRequired} NEAR ====`, {
logger.info(`==== ✅ Avaliable Balance of ${aggregator}: ${availableBalance.toFixed(4)} NEAR >= (${MINIMUM_AGGREGATOR_NEAR} + ${signerDepositRequired}) NEAR ====`, {
target: "check-aggregator-balance"
});
return true;
Expand Down
9 changes: 6 additions & 3 deletions packages/publisher-client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Command, Option } from 'commander';
import { Container } from 'typedi';
import { PublisherStarter } from './command/start';
import { logger } from "@ringdao/xapi-common";
import chalk from 'chalk';

const program = new Command();

Expand All @@ -18,17 +19,19 @@ program
.addOption(new Option("--near-account <string>", "near account").env("XAPI_NEAR_ACCOUNT"))
.addOption(new Option("--near-private-key <string>", "near private key").env("XAPI_NEAR_PRIVATE_KEY"))
.option(
"-t, --testnet <bool>",
"-t, --testnet",
"enable testnet mode",
false,
)
.action(async (options) => {
logger.warn(`YOUR ARE RUNNING ${chalk.green(options.testnet ? 'TESTNET' : 'MAINNET')} MODE`, { target: "main" });

if (!options.nearAccount) {
logger.error('missing near account, please add --near-account or set env.XAPI_NEAR_ACCOUNT');
logger.error('missing near account, please add --near-account or set env.XAPI_NEAR_ACCOUNT', { target: "main" });
process.exit(1);
}
if (!options.nearPrivateKey) {
logger.error('missing near private key, please add --near-private-key or set env.XAPI_NEAR_PRIVATE_KEY');
logger.error('missing near private key, please add --near-private-key or set env.XAPI_NEAR_PRIVATE_KEY', { target: "main" });
process.exit(1);
}
const c = Container.get(PublisherStarter);
Expand Down
35 changes: 26 additions & 9 deletions packages/reporter-client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ program.name("xapi-reporter").description("xapi reporter").version("0.0.1");
program
.command("start")
.description("start reporter program")
.addOption(new Option("--reward-address <string>", "reward address (target chain address)").env("XAPI_REWARD_ADDRESS"))
.addOption(new Option("--near-account <string>", "near account").env("XAPI_NEAR_ACCOUNT"))
.addOption(new Option("--near-private-key <string>", "near private key").env("XAPI_NEAR_PRIVATE_KEY"))
.option(
"-t, --testnet <bool>",
"enable testnet mode",
false,
.addOption(
new Option(
"--reward-address <string>",
"reward address (target chain address)",
).env("XAPI_REWARD_ADDRESS"),
)
.addOption(
new Option("--near-account <string>", "near account").env(
"XAPI_NEAR_ACCOUNT",
),
)
.addOption(
new Option("--near-private-key <string>", "near private key").env(
"XAPI_NEAR_PRIVATE_KEY",
),
)
.option("-t, --testnet", "enable testnet mode", false)
.option(
"-m, --minimum-rewards <string>",
"minimum rewards, e.g. --minimum-rewards=darwinia:100,crab:100",
Expand All @@ -34,12 +43,20 @@ program
[],
)
.action(async (options) => {
logger.warn(`YOUR ARE RUNNING ${chalk.green(options.testnet ? 'TESTNET' : 'MAINNET')} MODE`, { target: "reporter" });

if (!options.nearAccount) {
logger.error('missing near account, please add --near-account or set env.XAPI_NEAR_ACCOUNT');
logger.error(
"missing near account, please add --near-account or set env.XAPI_NEAR_ACCOUNT",
{ target: "reporter" },
);
process.exit(1);
}
if (!options.nearPrivateKey) {
logger.error('missing near private key, please add --near-private-key or set env.XAPI_NEAR_PRIVATE_KEY');
logger.error(
"missing near private key, please add --near-private-key or set env.XAPI_NEAR_PRIVATE_KEY",
{ target: "reporter" },
);
process.exit(1);
}
logger.info(`=== start reporter client ===`, {
Expand Down

0 comments on commit 7c3656d

Please sign in to comment.