Skip to content

Commit

Permalink
Allow vote end constraint to be ignored (#45)
Browse files Browse the repository at this point in the history
* allow hot reloading in development

* vote: allow for vote end constrain to be ignored

* adds `IGNORE_VOTE_END_CONSTRAINT: "true"` to `docker-compose.yml`
  • Loading branch information
jtrein authored Jun 25, 2021
1 parent 4dcfea6 commit 1a70807
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
31 changes: 31 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Node version matching the version declared in the package.json
FROM node:14.0-slim

# Update O.S.
RUN apt-get update && apt-get upgrade -y

# Install required O.S. packages
RUN apt-get install -y git python make g++

# Create the application workdir
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app

# Set current user
USER node

# Copy app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./

# Install app dependencies
RUN npm ci --only=production

# Bundle app source
COPY --chown=node:node . .

# Set the container port
EXPOSE 8080

# Start the aplication
CMD ["npm", "run", "express"]
8 changes: 7 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ services:

# Snapshot hub
snapshot-hub:
build: .
build:
# Use the development `Dockerfile.dev`
context: .
dockerfile: Dockerfile.dev
container_name: snapshot-hub
env_file:
- ./.env.local
Expand All @@ -12,10 +15,13 @@ services:
ENV: "local" # local | dev | prod
JAWSDB_URL: "postgres://admin:admin@snapshot-postgres:5432/snapshot-db"
USE_IPFS: "false"
IGNORE_VOTE_END_CONSTRAINT: "true"
depends_on:
- snapshot-postgres
ports:
- 8081:8080
volumes:
- .:/home/node/app

# Snapshot Postgres instance
snapshot-postgres:
Expand Down
13 changes: 11 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ const network = process.env.NETWORK || 'testnet';
*/
const useIPFSPinnig = process.env.USE_IPFS === 'true';

/**
* If true, the proposal's voting end time constraint will not be enforced.
* This allows an external time period to be used (i.e. DAO's on-chain proposal's voting period).
*/
const ignoreVoteEndConstraint: boolean =
process.env.IGNORE_VOTE_END_CONSTRAINT === 'true';

/**
* The upstream implementation relies on @snapshot-labs/snapshot-spaces npm lib to fetch all the available spaces.
* Since this implementation is used by OpenLaw only, that dependency was removed and the spaces are loaded from the
Expand Down Expand Up @@ -425,8 +432,10 @@ router.post('/message', async (req, res) => {
return sendError(res, 'unknown proposal');

const payload = jsonParse(proposals[0].payload);
if (ts > payload.end || payload.start > ts)
return sendError(res, 'not in voting window');
const isNotInVotingWindow: boolean = ignoreVoteEndConstraint
? payload.start > ts
: ts > payload.end || payload.start > ts;
if (isNotInVotingWindow) return sendError(res, 'not in voting window');

const votes = await getVoteBySender(
space,
Expand Down

0 comments on commit 1a70807

Please sign in to comment.