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

fedekunze/1436 gov endpoints and modules #1463

Merged
merged 29 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7790f80
Added gov endpoints to LCDClient
Oct 10, 2018
6216593
vuex state governance
Oct 15, 2018
89005d2
updated modules
Oct 16, 2018
3da3597
modules done, missing unit tests
Oct 16, 2018
1bd5179
use proposal_id and proposalID
Oct 16, 2018
25fa5c2
add deposits endpoint
Oct 16, 2018
5403390
vuex updates on store
Oct 16, 2018
39990c9
Implement overview
Oct 16, 2018
783f248
Merge branch 'develop' of https://github.com/cosmos/voyager into fede…
Oct 17, 2018
2990855
update chart and mock lcd
Oct 17, 2018
4b7a2ad
fixed tests for proposal module
Oct 17, 2018
7d8de29
changelog
Oct 17, 2018
8445ba6
added first steps on votes
Oct 17, 2018
b8303c0
get and set unit tests votes
Oct 17, 2018
664f05f
Added deposits module tests
Oct 17, 2018
917ff57
update getters and store
Oct 17, 2018
1aceeac
Merge branch 'develop' of https://github.com/cosmos/voyager into fede…
Oct 18, 2018
516ab54
leave the original governance components
Oct 18, 2018
b2cf4a8
submit gov actions
Oct 19, 2018
c05882a
lcdClient unit test
Oct 19, 2018
766d56c
lcdClientMock unit tests
Oct 19, 2018
6880876
Test getProposal dispatch
Oct 19, 2018
f1f217e
Add proposals deposit dispatch test
Oct 19, 2018
b2100cf
reconnection test
Oct 19, 2018
079d1fe
Merge branch 'develop' into fedekunze/1436-gov-endpoints
fedekunze Oct 19, 2018
e85c4d6
Merge branch 'develop' into fedekunze/1436-gov-endpoints
fedekunze Oct 19, 2018
6a35542
Test timers
Oct 19, 2018
26acb37
Merge branch 'fedekunze/1436-gov-endpoints' of https://github.com/cos…
Oct 19, 2018
c47460d
deposits timeout test
Oct 19, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* Protected Gaia Lite process with a mutex to prevent locking error. @NodeGuy
* catching errors on cache encryption. @faboweb
* #1436 governance endpoints and vuex module @fedekunze

### Changed

Expand Down
42 changes: 42 additions & 0 deletions app/src/renderer/connectors/lcdClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,48 @@ Object.assign(Client.prototype, {

queryValidatorSigningInfo: function(pubKey) {
return req(`GET`, `/slashing/signing_info/${pubKey}`, true).call(this)
},

/* ============ Governance ============ */

queryProposals: req(`GET`, `/gov/proposals`, true),
queryProposal: function(proposalId) {
return req(`GET`, `/gov/proposals/${proposalId}`, true).call(this)
},
queryProposalVotes: function(proposalId) {
return req(`GET`, `/gov/proposals/${proposalId}/votes`, true).call(this)
},
queryProposalVote: function(proposalId, address) {
return req(
`GET`,
`/gov/proposals/${proposalId}/votes/${address}`,
true
).call(this)
},
queryProposalDeposits: function(proposalId) {
return req(`GET`, `/gov/proposals/${proposalId}/deposits`, true).call(this)
},
queryProposalDeposit: function(proposalId, address) {
return req(
`GET`,
`/gov/proposals/${proposalId}/deposits/${address}`,
true
).call(this)
},
submitProposal: function(data) {
return req(`POST`, `/gov/proposals`, true).call(this, data)
},
submitVote: function(proposalId, data) {
return req(`POST`, `/gov/proposals/${proposalId}/votes`, true).call(
this,
data
)
},
submitDeposit: function(proposalId, data) {
return req(`POST`, `/gov/proposals/${proposalId}/deposits`, true).call(
this,
data
)
}
})

Expand Down
142 changes: 142 additions & 0 deletions app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,126 @@ let state = {
index_offset: 1,
jailed_until: `1970-01-01T00:00:00Z`,
signed_blocks_counter: 1
},
proposals: [
{
proposal_id: `1`,
proposal_type: `Text`,
title: `Proposal Title`,
description: `Proposal description`,
initial_deposit: [
{
denom: `stake`,
amount: `100`
}
],
total_deposit: [
{
denom: `stake`,
amount: `100`
}
],
submit_block: `120`,
voting_start_block: `135`,
proposal_status: `Passed`,
tally_result: {
yes: `500`,
no: `25`,
no_with_veto: `10`,
abstain: `56`
}
},
{
proposal_id: `5`,
proposal_type: `Text`,
title: `Custom text proposal`,
description: `custom text proposal description`,
initial_deposit: [
{
denom: `stake`,
amount: `15`
}
],
total_deposit: [
{
denom: `stake`,
amount: `15`
}
],
submit_block: `10`,
voting_start_block: `-1`,
proposal_status: `DepositPeriod`,
tally_result: {
yes: `0`,
no: `0`,
no_with_veto: `0`,
abstain: `0`
}
}
],
votes: {
1: [
{
proposal_id: `1`,
voter: validators[0],
option: `yes`
},
{
proposal_id: `1`,
voter: validators[1],
option: `no_with_veto`
}
],
5: [
{
proposal_id: `5`,
voter: validators[0],
option: `no`
},
{
proposal_id: `5`,
voter: validators[1],
option: `abstain`
}
]
},
deposits: {
1: [
{
proposal_id: `1`,
depositer: validators[0],
amount: {
denom: `stake`,
amount: `15`
}
},
{
proposal_id: `1`,
depositer: validators[1],
amount: {
denom: `stake`,
amount: `5`
}
}
],
5: [
{
proposal_id: `5`,
depositer: validators[0],
amount: {
denom: `stake`,
amount: `11`
}
},
{
proposal_id: `5`,
depositer: validators[1],
amount: {
denom: `stake`,
amount: `150`
}
}
]
}
}

Expand Down Expand Up @@ -526,6 +646,28 @@ module.exports = {
async getParameters() {
return state.parameters
},
async getProposals() {
return state.proposals
},
async getProposal(proposalId) {
return state.proposals.find(
proposal => proposal.proposal_id === String(proposalId)
)
},
async getProposalDeposits(proposalId) {
return state.deposits[proposalId]
},
async getProposalDeposit(proposalId, address) {
return state.deposits[proposalId].find(
deposit => deposit.depositer === address
)
},
async getProposalVotes(proposalId) {
return state.votes[proposalId]
},
async getProposalVote(proposalId, address) {
return state.votes[proposalId].find(vote => vote.voter === address)
},
// exports to be used in tests
state,
addresses,
Expand Down
6 changes: 4 additions & 2 deletions app/src/renderer/vuex/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ export const keybase = state => state.keybase.identities
export const pool = state => state.pool
export const parameters = state => state.parameters

// govern
export const proposals = state => state.proposals
// governance
export const proposals = state => state.proposals.proposals
export const votes = state => state.votes.votes
export const deposits = state => state.deposits.deposits

// status
export const approvalRequired = state => state.node.approvalRequired
Expand Down
51 changes: 51 additions & 0 deletions app/src/renderer/vuex/modules/governance/deposits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict"

export default ({ node }) => {
const state = {
loading: false,
deposits: {}
}

const mutations = {
setProposalDeposits(state, proposalId, deposits) {
state.deposits[proposalId] = deposits
}
}
let actions = {
async getProposalDeposits({ state, commit }, proposalId) {
state.loading = true
let deposits = await node.queryProposalDeposits(proposalId)
commit(`setProposalDeposits`, proposalId, deposits)
state.loading = false
},
async submitDeposit(
{
rootState: { config, wallet },
dispatch
},
proposalId,
depositAmount
) {
const denom = config.bondingDenom.toLowerCase()
await dispatch(`sendTx`, {
type: `submitDeposit`,
proposal_id: proposalId,
depositer: wallet.address,
amount: [
{
denom: denom,
amount: depositAmount
}
]
})
setTimeout(async () => {
dispatch(`getProposalDeposits`, proposalId)
}, 5000)
}
}
return {
state,
actions,
mutations
}
}
65 changes: 65 additions & 0 deletions app/src/renderer/vuex/modules/governance/proposals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use strict"

export default ({ node }) => {
let emptyState = {
loading: false,
proposals: {}
}
const state = JSON.parse(JSON.stringify(emptyState))

const mutations = {
setProposal(state, proposal) {
state.proposals[proposal.proposal_id] = proposal
}
}
let actions = {
async reconnected({ state, dispatch }) {
if (state.loading) {
await dispatch(`getProposals`)
}
},
resetSessionData({ rootState }) {
// clear previous account state
rootState.proposals = JSON.parse(JSON.stringify(emptyState))
},
async getProposals({ state, commit, dispatch }) {
state.loading = true
let proposals = await node.queryProposals()
if (proposals.length > 0) {
proposals.forEach(proposal => {
let proposalId = Number(proposal.value.proposal_id)
commit(`setProposal`, proposal.value)
if (proposal.value.proposal_status !== `DepositPeriod`) {
dispatch(`getProposalVotes`, proposalId)
}
dispatch(`getProposalDeposits`, proposalId)
})
}
state.loading = false
},
async submitProposal(
{
rootState: { wallet },
dispatch
},
proposal
) {
await dispatch(`sendTx`, {
type: `submitProposal`,
proposer: wallet.address,
proposal_type: proposal.proposal_type,
title: proposal.title,
description: proposal.description,
initial_deposit: proposal.initial_deposit
})
setTimeout(async () => {
dispatch(`getProposals`)
}, 5000)
}
}
return {
state,
actions,
mutations
}
}
45 changes: 45 additions & 0 deletions app/src/renderer/vuex/modules/governance/votes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict"

export default ({ node }) => {
const state = {
loading: false,
votes: {}
}

const mutations = {
setProposalVotes(state, proposalId, votes) {
state.votes[proposalId] = votes
}
}
let actions = {
async getProposalVotes({ state, commit }, proposalId) {
state.loading = true
let votes = await node.queryProposalVotes(proposalId)
commit(`setProposalVotes`, proposalId, votes)
state.loading = false
},
async submitVote(
{
rootState: { wallet },
dispatch
},
proposalId,
option
) {
await dispatch(`sendTx`, {
type: `submitVote`,
proposal_id: proposalId,
voter: wallet.address,
option
})
setTimeout(async () => {
dispatch(`getProposalVotes`, proposalId)
}, 5000)
}
}
return {
state,
actions,
mutations
}
}
Loading