refactor in preparation to add contract event subscriptions
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 30s Details

This commit is contained in:
Ladd Hoffman 2024-04-23 15:57:15 -05:00
parent 59f511f51d
commit 2e53252fc7
3 changed files with 41 additions and 27 deletions

34
backend/src/contracts.js Normal file
View File

@ -0,0 +1,34 @@
const ethers = require('ethers');
const { getContractAddressByNetworkName } = require('./contract-config');
const DAOArtifact = require('../contractArtifacts/DAO.json');
const network = process.env.ETH_NETWORK;
console.log('network:', network);
const getProvider = () => {
switch (network) {
case 'localhost':
return ethers.getDefaultProvider('http://localhost:8545');
case 'sepolia':
return new ethers.InfuraProvider(
network,
process.env.INFURA_API_KEY,
);
default:
throw new Error('Unknown network');
}
};
const wallet = new ethers.Wallet(process.env.ETH_PRIVATE_KEY, getProvider());
const getContract = (name) => new ethers.Contract(
getContractAddressByNetworkName(process.env.ETH_NETWORK, name),
DAOArtifact.abi,
wallet,
);
module.exports = {
dao: getContract('DAO'),
};

View File

@ -4,39 +4,13 @@ const crypto = require('crypto');
const objectHash = require('object-hash');
const Promise = require('bluebird');
require('dotenv').config();
const verifySignature = require('./verify-signature');
const { getContractAddressByNetworkName } = require('./contract-config');
const { authorAddresses, authorPrivKeys, forum } = require('./db');
const DAOArtifact = require('../contractArtifacts/DAO.json');
const { dao } = require('./contracts');
// Each post allocates 30% of its reputation to citations
const PPM_TO_CITATIONS = 300000;
const network = process.env.ETH_NETWORK;
console.log('network:', network);
const getProvider = () => {
switch (network) {
case 'localhost':
return ethers.getDefaultProvider('http://localhost:8545');
case 'sepolia':
return new ethers.InfuraProvider(
network,
process.env.INFURA_API_KEY,
);
default:
throw new Error('Unknown network');
}
};
const signer = new ethers.Wallet(process.env.ETH_PRIVATE_KEY, getProvider());
const getContract = (name) => new ethers.Contract(
getContractAddressByNetworkName(process.env.ETH_NETWORK, name),
DAOArtifact.abi,
signer,
);
const dao = getContract('DAO');
const fetchWithRetry = async (url, retryDelay = 5000) => {
let retry = false;
let responseData;

View File

@ -32,3 +32,9 @@ app.use((err, req, res, next) => {
app.listen(port, () => {
console.log(`Listening on port ${port}`);
});
// TODO: Subscribe to contract events
// TODO: Send matrix room events for proposal events
// TODO: Send matrix room event on SS import