Skip to content

Commit

Permalink
Merge pull request #25 from noislabs/more-improvements
Browse files Browse the repository at this point in the history
Various improvements to codebase
  • Loading branch information
webmaster128 authored Sep 4, 2023
2 parents f9eaa6d + 86ad9c7 commit 48576d0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
config.json
# main config file used by the app
/config.json

# custom config files you might want to link
/config.*.json
62 changes: 29 additions & 33 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,17 @@ if (import.meta.main) {
const client = await SigningCosmWasmClient.createWithSigner(tmClient, wallet, {
gasPrice: GasPrice.fromString(config.gasPrice),
});

// Bot info
const botAddress = firstAccount.address;
console.log(`Bot address: ${botAddress}`);
console.log(`Group: ${group(botAddress)}`);
try {
const balance = await client.getBalance(botAddress, config.denom);
console.log(`Balance: ${printableCoin(balance)}`);
} catch (error: unknown) {
console.warn(`Error getting bot balance: ${error}`);
}

// Needed in case an error happened to ensure sequence is in sync
// with chain
Expand All @@ -107,7 +115,7 @@ if (import.meta.main) {

const moniker = config.moniker;
if (moniker) {
console.info("Registering this bot ...");
console.info(`Registering bot '${moniker}'...`);
const fee = calculateFee(gasLimitRegister, config.gasPrice);
await client.execute(
botAddress,
Expand All @@ -122,8 +130,12 @@ if (import.meta.main) {
await Promise.all([
sleep(500), // the min waiting time
(async function () {
const listed = await queryIsAllowlisted(client, drandAddress, botAddress);
console.info(`Bot allowlisted for rewards: ${listed}`);
try {
const listed = await queryIsAllowlisted(client, drandAddress, botAddress);
console.info(`Bot allowlisted for rewards: ${listed}`);
} catch (error: unknown) {
console.warn(`Query error: ${error}`);
}
})(),
]);

Expand Down Expand Up @@ -173,38 +185,22 @@ if (import.meta.main) {

const didSubmit = await submitter.handlePublishedBeacon(beacon);

const processJobs = (rounds: number[]): void => {
if (!rounds.length) return;
const past = rounds.filter((r) => r <= n);
const future = rounds.filter((r) => r > n);
console.log(
`Past: %o, Future: %o`,
past,
future,
);
submitter.submitPastRounds(past);
};

// Check jobs every 1.5s, shifted 1200ms from the drand receiving
const shift = 1200;
setTimeout(() =>
jobs.check().then(
(rounds) => {
if (!rounds.length) return;
const past = rounds.filter((r) => r <= n);
const future = rounds.filter((r) => r > n);
console.log(
`Past: %o, Future: %o`,
past,
future,
);
submitter.submitPastRounds(past);
},
(err) => console.error(err),
), shift);
setTimeout(() =>
jobs.check().then(
(rounds) => {
if (!rounds.length) return;
const past = rounds.filter((r) => r <= n);
const future = rounds.filter((r) => r > n);
console.log(
`Past: %o, Future: %o`,
past,
future,
);
submitter.submitPastRounds(past);
},
(err) => console.error(err),
), shift + 1500);
setTimeout(() => jobs.check().then(processJobs, (err) => console.error(err)), shift);
setTimeout(() => jobs.check().then(processJobs, (err) => console.error(err)), shift + 1500);

if (didSubmit) {
// Some seconds after the submission when things are idle, check and log
Expand Down

0 comments on commit 48576d0

Please sign in to comment.