Skip to content

Commit

Permalink
adding blocknumber arg for vote result
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiacodes committed Sep 15, 2021
1 parent d2789b6 commit e90b55c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@

> Graph definition for the Tribute DAO Framework
## Subgraph Setup
## Installation Setup

To get started install the dependencies and compile the contracts:
You need to install Graph CLI with either npm or yarn.

> Note: You need version 0.21.0 or above
NPM Install:

```
npm ci && npm run compile
npm install -g @graphprotocol/graph-cli
```

Then, you'll need to generate and build the source files:
Yarn Install:

```
graph codegen && graph build
yarn global add @graphprotocol/graph-cli
```

You need to install Graph CLI with either npm or yarn.

> Note: You need version 0.21.0 or above
## Subgraph Setup

NPM Install:
To get started install the dependencies and compile the contracts:

```
npm install -g @graphprotocol/graph-cli
npm ci && npm run compile
```

Yarn Install:
Then, you'll need to generate and build the source files:

```
yarn global add @graphprotocol/graph-cli
graph codegen && graph build
```

### Multiple Ethereum Networks Setup
Expand Down
4 changes: 3 additions & 1 deletion mappings/core/dao-registry-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ export function handleSponsoredProposal(event: SponsoredProposal): void {

export function handleProcessedProposal(event: ProcessedProposal): void {
let processedAt = event.block.timestamp.toString();
let blockNumber = event.block.number;

log.info("=============== ProcessedProposal event fired. proposalId: {}", [
event.params.proposalId.toHexString(),
]);

let proposal = loadProposalAndSaveVoteResults(
event.address,
event.params.proposalId
event.params.proposalId,
blockNumber
);

if (proposal) {
Expand Down
20 changes: 14 additions & 6 deletions mappings/helpers/vote-results.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address, Bytes, log } from "@graphprotocol/graph-ts";
import { Address, BigInt, Bytes, log } from "@graphprotocol/graph-ts";

import { OffchainVotingContract } from "../../generated/templates/DaoRegistry/OffchainVotingContract";
import { VotingContract } from "../../generated/templates/DaoRegistry/VotingContract";
Expand All @@ -8,7 +8,8 @@ import { Proposal, Vote } from "../../generated/schema";

export function loadProposalAndSaveVoteResults(
daoAddress: Address,
proposalId: Bytes
proposalId: Bytes,
blockNumber: BigInt
): Proposal | null {
// load the existing proposal
let maybeProposalId = daoAddress
Expand All @@ -18,9 +19,16 @@ export function loadProposalAndSaveVoteResults(
let proposal = Proposal.load(maybeProposalId);

if (proposal) {
let voteId = daoAddress.toHex().concat("-vote-").concat(proposalId.toHex());
let voteId = daoAddress
.toHex()
.concat("-vote-")
.concat(proposalId.toHex());
let vote = new Vote(voteId);

// set initial vote values - to prevent this breaking during sync
vote.nbNo = BigInt.fromI32(0);
vote.nbYes = BigInt.fromI32(0);

// get the voting adapter address from the proposal
let votingAdapterAddress: Bytes = proposal.votingAdapter as Bytes;

Expand Down Expand Up @@ -85,11 +93,11 @@ export function loadProposalAndSaveVoteResults(
proposal.startingTime = voteResults.value5;
proposal.gracePeriodStartingTime = voteResults.value6;
proposal.isChallenged = voteResults.value7;
proposal.stepRequested = voteResults.value8;
// proposal.stepRequested = voteResults.value.value8;
// @todo its a mapping, not generated in schema
// proposal.fallbackVotes = voteResults.value10;
proposal.forceFailed = voteResults.value9;
proposal.fallbackVotesCount = voteResults.value10;
// proposal.forceFailed = voteResults.value.value9;
// proposal.fallbackVotesCount = voteResults.value.value10;

proposal.votingState = voteState.toString();
proposal.votingResult = voteId;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ganache-cli": "^6.12.1",
"hardhat-typechain": "^0.3.5",
"keccak256": "^1.0.0",
"tribute-contracts": "^2.1.1",
"tribute-contracts": "^2.0.0",
"truffle": "^5.2.6",
"ts-generator": "^0.1.1",
"typechain": "^4.0.3",
Expand Down
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ type Proposal @entity {
type Vote @entity {
"Unique identifier and primary key of the `Vote` entity"
id: ID! # Set to `${tribute.id}-vote-${proposal.id}`
nbNo: BigInt!
nbYes: BigInt!
nbNo: BigInt
nbYes: BigInt
adapterName: VotingAdapterName!
adapterAddress: Bytes!
proposal: Proposal
Expand Down

0 comments on commit e90b55c

Please sign in to comment.