From 5aee8c93143fa4a71d2c327c7ec875ca3a0707c7 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Mon, 29 Apr 2024 18:13:24 -0500 Subject: [PATCH] staking enable/diable fixup --- backend/.env.example | 4 +++- .../src/contract-listeners/validation-pools.js | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/backend/.env.example b/backend/.env.example index 8f904ef..9d1ebec 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -13,4 +13,6 @@ BOT_CRYPTO_STORAGE_PATH="./data/bot-crypto" BOT_INSTANCE_ID= ENABLE_API= ENABLE_MATRIX= -ENABLE_STAKING= \ No newline at end of file +ENABLE_STAKING= +START_PROPOSAL_ID= +STOP_PROPOSAL_ID= \ No newline at end of file diff --git a/backend/src/contract-listeners/validation-pools.js b/backend/src/contract-listeners/validation-pools.js index 2aa0f4b..17fce71 100644 --- a/backend/src/contract-listeners/validation-pools.js +++ b/backend/src/contract-listeners/validation-pools.js @@ -12,6 +12,7 @@ let enableStaking = true; // Subscribe to proposal events const start = async () => { if (ENABLE_STAKING === 'false') { + console.log('STAKING DISABLED'); enableStaking = false; } else { if (STOP_PROPOSAL_ID) { @@ -21,16 +22,16 @@ const start = async () => { if (proposal.stage === BigInt(5)) { // Proposal is accepted enableStaking = false; - console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is accepted. Not starting.`); + console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is accepted. Diabling staking.`); } else if (proposal.stage === BigInt(4)) { // Proposal is failed console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is failed. No effect.`); } else { // Register a ProposalAccepted event handler. console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is stage ${proposal.stage.toString()}. Registering listener.`); - const proposalAcceptedHandler = (event) => { - if (event.returnValues.proposalIndex === STOP_PROPOSAL_ID) { - console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is accepted. Stopping.`); + const proposalAcceptedHandler = (proposalIndex) => { + if (proposalIndex === STOP_PROPOSAL_ID) { + console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is accepted. Disabling staking.`); enableStaking = false; proposals.off('ProposalAccepted', proposalAcceptedHandler); } @@ -45,15 +46,16 @@ const start = async () => { if (proposal.stage === BigInt(5)) { // Proposal is accepted enableStaking = true; + console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is accepted. Enabling staking.`); } else if (proposal.stage === BigInt(4)) { // Proposal is failed - console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is failed. Not starting.`); + console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is failed. Disabling staking.`); } else { // Register a ProposalAccepted event handler. console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is stage ${proposal.stage.toString()}. Registering listener.`); - const proposalAcceptedHandler = (event) => { - if (event.returnValues.proposalIndex === START_PROPOSAL_ID) { - console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is accepted. Starting.`); + const proposalAcceptedHandler = (proposalIndex) => { + if (proposalIndex === START_PROPOSAL_ID) { + console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is accepted. Enabling staking.`); enableStaking = true; proposals.off('ProposalAccepted', proposalAcceptedHandler); }