From 4e9ebfa7c3dac77be78454fba7ba3f6781cbfe33 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Tue, 30 Apr 2024 17:32:55 -0500 Subject: [PATCH] fixup backend --- backend/src/api/index.js | 3 +-- backend/src/topics/proposals-notifier.js | 7 ++++++- backend/src/util/gate-by-proposal.js | 6 +++--- backend/src/util/verify-signature.js | 1 - 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/backend/src/api/index.js b/backend/src/api/index.js index 536b7df..c2b3b25 100644 --- a/backend/src/api/index.js +++ b/backend/src/api/index.js @@ -13,9 +13,8 @@ const port = process.env.API_LISTEN_PORT || 3000; app.use(express.json()); app.post('/write', async (req, res) => { - const { hash, data } = await write(req.body); + const { hash } = await write(req.body); console.log('write', hash); - console.log(data); res.send(hash); }); diff --git a/backend/src/topics/proposals-notifier.js b/backend/src/topics/proposals-notifier.js index 5f623f5..fa1e5a1 100644 --- a/backend/src/topics/proposals-notifier.js +++ b/backend/src/topics/proposals-notifier.js @@ -4,7 +4,7 @@ const { sendNewProposalEvent } = require('../matrix-bot/outbound-queue'); // Subscribe to proposal events const start = () => { - console.log('registering proposal listener'); + console.log('registering proposal listener for proposal notifier'); proposals.on('NewProposal', async (proposalIndex) => { console.log('New Proposal, index', proposalIndex); @@ -32,6 +32,11 @@ const start = () => { // The outbound queue handles deduplication sendNewProposalEvent(proposalIndex, message); }); + + proposals.on('ProposalAccepted', async (proposalIndex) => { + console.log('Proposal Accepted, index:', proposalIndex); + // TODO: Send notification as a reply to the new proposal message + }); }; module.exports = { diff --git a/backend/src/util/gate-by-proposal.js b/backend/src/util/gate-by-proposal.js index 15d108d..aef1e60 100644 --- a/backend/src/util/gate-by-proposal.js +++ b/backend/src/util/gate-by-proposal.js @@ -23,7 +23,7 @@ const gateByProposal = async (enable) => { // Register a ProposalAccepted event handler. console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is stage ${proposal.stage.toString()}. Registering listener.`); const proposalAcceptedHandler = (proposalIndex) => { - if (proposalIndex === STOP_PROPOSAL_ID) { + if (proposalIndex.toString() === STOP_PROPOSAL_ID) { console.log(`STOP_PROPOSAL_ID ${STOP_PROPOSAL_ID} proposal is accepted. Disabling staking.`); enable(false); proposals.off('ProposalAccepted', proposalAcceptedHandler); @@ -47,7 +47,7 @@ const gateByProposal = async (enable) => { // Register a ProposalAccepted event handler. console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is stage ${proposal.stage.toString()}. Registering listener.`); const proposalAcceptedHandler = (proposalIndex) => { - if (proposalIndex === START_PROPOSAL_ID) { + if (proposalIndex.toString() === START_PROPOSAL_ID) { console.log(`START_PROPOSAL_ID ${START_PROPOSAL_ID} proposal is accepted. Enabling staking.`); enable(true); proposals.off('ProposalAccepted', proposalAcceptedHandler); @@ -58,4 +58,4 @@ const gateByProposal = async (enable) => { } }; -export default gateByProposal; +module.exports = gateByProposal; diff --git a/backend/src/util/verify-signature.js b/backend/src/util/verify-signature.js index f54203b..d724dc9 100644 --- a/backend/src/util/verify-signature.js +++ b/backend/src/util/verify-signature.js @@ -9,7 +9,6 @@ const verifySignature = ({ } try { const account = recoverPersonalSignature({ data: contentToVerify, signature }); - console.log({ sender, account, authors }); const addresses = authors .map((author) => author.authorAddress) .concat(sender ? [sender] : [])