Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new proposal schema #3

Open
wants to merge 6 commits into
base: feat/mainnet-governance
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ type Proposal implements Action @entity {
lastUpdateTimestamp: Int!
lastUpdateBlock: BigInt!
title: String!
description: String!
summary: String!
simpleSummary: String!
abstract: String!
motivation: String!
specification: String!
references: String!
rationale: String!
testCases: String!
copyrightWaiver: String!
govContract: Bytes!
totalPropositionSupply: BigInt!
totalVotingSupply: BigInt!
createdBlockNumber: BigInt!
totalCurrentVoters: Int!
author: String!
discussions: String!
txHash: String!
}

type Vote implements Action @entity {
Expand Down
9 changes: 6 additions & 3 deletions src/helpers/initializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,21 @@ export function getOrInitProposal(proposalId: string): Proposal {
proposal.lastUpdateTimestamp = zeroBI().toI32();
proposal.lastUpdateBlock = zeroBI();
proposal.title = NA;
proposal.description = NA;
proposal.summary = NA;
proposal.simpleSummary = NA;
proposal.abstract = NA;
proposal.motivation = NA;
proposal.specification = NA;
proposal.references = NA;
proposal.rationale = NA;
proposal.testCases = NA;
proposal.copyrightWaiver = NA;
proposal.govContract = zeroAddress();
proposal.totalPropositionSupply = zeroBI();
proposal.totalVotingSupply = zeroBI();
proposal.createdBlockNumber = zeroBI();
proposal.totalCurrentVoters = 0;
proposal.author = NA;
proposal.discussions = NA;
proposal.txHash = NA;
proposal.save();
}

Expand Down
46 changes: 29 additions & 17 deletions src/mapping/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ function getProposal(proposalId: string, fn: string): Proposal | null {

export function handleProposalCreated(event: ProposalCreated): void {
let hash = Bytes.fromHexString('1220' + event.params.ipfsHash.toHexString().slice(2)).toBase58();
let txHash = event.transaction.hash.toHexString();
let data = ipfs.cat(hash);
if (data === null) {
log.warning('Missing proposal data for {}', [hash]);
let proposal = getOrInitProposal(event.params.id.toString());
// TODO: @dillon - delete this later
proposal.author = '';
proposal.discussions = '';
proposal.title = '';
proposal.summary = '';
proposal.simpleSummary = '';
proposal.abstract = '';
proposal.motivation = '';
proposal.specification = '';
proposal.references = '';
proposal.author = '';
proposal.discussions = '';
proposal.description = '';
proposal.rationale = '';
proposal.testCases = '';
proposal.copyrightWaiver = '';
proposal.txHash = txHash;
let govStrategyInst = GovernanceStrategy.bind(event.params.strategy);
proposal.totalPropositionSupply = govStrategyInst.getTotalPropositionSupplyAt(
event.block.number >= proposal.startBlock ? proposal.startBlock : event.block.number
Expand Down Expand Up @@ -75,10 +78,13 @@ export function handleProposalCreated(event: ProposalCreated): void {

let proposalData = json.try_fromBytes(data as Bytes);
let title: JSONValue | null = null;
let summary: JSONValue | null = null;
let simpleSummary: JSONValue | null = null;
let abstract: JSONValue | null = null;
let motivation: JSONValue | null = null;
let specification: JSONValue | null = null;
let references: JSONValue | null = null;
let rationale: JSONValue | null = null;
let testCases: JSONValue | null = null;
let copyrightWaiver: JSONValue | null = null;
let description: JSONValue | null = null;
let author: JSONValue | null = null;
let discussions: JSONValue | null = null;
Expand All @@ -87,10 +93,12 @@ export function handleProposalCreated(event: ProposalCreated): void {
let data = proposalData.value.toObject();
title = data.get('title');
description = data.get('description');
summary = data.get('summary');
simpleSummary = data.get('simpleSummary');
motivation = data.get('motivation');
specification = data.get('specification');
references = data.get('references');
rationale = data.get('rationale');
testCases = data.get('testCases');
copyrightWaiver = data.get('copyrightWaiver');
author = data.get('author');
discussions = data.get('discussions');
}
Expand All @@ -99,27 +107,30 @@ export function handleProposalCreated(event: ProposalCreated): void {
if (title) {
proposal.title = title.toString();
}
if (summary) {
proposal.summary = summary.toString();
if (simpleSummary) {
proposal.simpleSummary = simpleSummary.toString();
}
if (abstract) {
proposal.abstract = abstract.toString();
}
if (motivation) {
proposal.motivation = motivation.toString();
}
if (specification) {
proposal.specification = specification.toString();
}
if (references) {
proposal.references = references.toString();
if (rationale) {
proposal.rationale = rationale.toString();
}
if (testCases) {
proposal.testCases = testCases.toString();
}
if (author) {
proposal.author = author.toString();
}
if (discussions) {
proposal.discussions = discussions.toString();
}
if (description) {
proposal.description = description.toString();
}

let govStrategyInst = GovernanceStrategy.bind(event.params.strategy);
proposal.totalPropositionSupply = govStrategyInst.getTotalPropositionSupplyAt(
Expand Down Expand Up @@ -147,6 +158,7 @@ export function handleProposalCreated(event: ProposalCreated): void {
proposal.timestamp = event.block.timestamp.toI32();
proposal.createdBlockNumber = event.block.number;
proposal.lastUpdateTimestamp = event.block.timestamp.toI32();
proposal.txHash = txHash;
proposal.save();
}

Expand Down