Skip to content
Merged
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: 8 additions & 1 deletion packages/cli/src/commands/governance/view.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { proposalToJSON } from '@celo/contractkit/lib/governance/proposals'
import { flags } from '@oclif/command'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
Expand All @@ -9,20 +10,26 @@ export default class View extends BaseCommand {
static flags = {
...BaseCommand.flags,
proposalID: flags.string({ required: true, description: 'UUID of proposal to view' }),
raw: flags.boolean({ required: false, description: 'Display proposal in raw bytes format' }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaults to false (equivalent to excluding as flag in oclif)

}

static examples = ['view --proposalID 99']
static examples = ['view --proposalID 99', 'view --proposalID 99 --raw']

async run() {
const res = this.parse(View)
const id = res.flags.proposalID
const raw = res.flags.raw

await newCheckBuilder(this)
.proposalExists(id)
.runChecks()

const governance = await this.kit.contracts.getGovernance()
const record = await governance.getProposalRecord(id)
if (!raw) {
const jsonproposal = await proposalToJSON(this.kit, record.proposal)
record.proposal = jsonproposal as any
}
printValueMapRecursive(record)
}
}
2 changes: 2 additions & 0 deletions packages/contractkit/src/governance/proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ProposalTransactionJSON {
contract: CeloContract
function: string
args: any[]
params?: Record<string, any>
value: string
}

Expand All @@ -40,6 +41,7 @@ export const proposalToJSON = async (kit: ContractKit, proposal: Proposal) => {
contract: parsedTx.callDetails.contract as CeloContract,
function: parsedTx.callDetails.function,
args: parsedTx.callDetails.argList,
params: parsedTx.callDetails.paramMap,
value: parsedTx.tx.value,
}
})
Expand Down
18 changes: 11 additions & 7 deletions packages/contractkit/src/wrappers/Governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,13 @@ export class GovernanceWrapper extends BaseWrapper<Governance> {
)

/**
* Returns the proposal dequeue as list of proposal IDs.
* Returns the (existing) proposal dequeue as list of proposal IDs.
*/
getDequeue = proxyCall(this.contract.methods.getDequeue, undefined, (arrayObject) =>
arrayObject.map(valueToBigNumber)
)
async getDequeue() {
const dequeue = await this.contract.methods.getDequeue().call()
// filter non-zero as dequeued indices are reused and `deleteDequeuedProposal` zeroes
return dequeue.map(valueToBigNumber).filter((id) => !id.isZero())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would the IDs be zero?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dequeued indices are reused after proposals are deleted (when expired)
the proposalID is set to zero in deleteDequeuedProposal, I will add a comment

}

/**
* Dequeues any queued proposals if `dequeueFrequency` seconds have elapsed since the last dequeue
Expand Down Expand Up @@ -430,9 +432,11 @@ export class GovernanceWrapper extends BaseWrapper<Governance> {

private async lesserAndGreaterAfterUpvote(upvoter: Address, proposalID: BigNumber.Value) {
const upvoteRecord = await this.getUpvoteRecord(upvoter)
const queue = upvoteRecord.proposalID.isZero()
? await this.getQueue()
: (await this.withUpvoteRevoked(upvoter)).queue
const recordQueued = await this.isQueued(upvoteRecord.proposalID)
// if existing upvote exists in queue, revoke it before applying new upvote
const queue = recordQueued
? (await this.withUpvoteRevoked(upvoter)).queue
: await this.getQueue()
const upvoteQueue = await this.withUpvoteApplied(upvoter, proposalID, queue)
return this.lesserAndGreater(proposalID, upvoteQueue)
}
Expand Down
4 changes: 3 additions & 1 deletion packages/docs/command-line-interface/governance.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ USAGE

OPTIONS
--proposalID=proposalID (required) UUID of proposal to view
--raw Display proposal in raw bytes format

EXAMPLE
EXAMPLES
view --proposalID 99
view --proposalID 99 --raw
```

_See code: [packages/cli/src/commands/governance/view.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/governance/view.ts)_
Expand Down