Skip to content

Commit

Permalink
Added delegation tx creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mappum committed Nov 27, 2017
1 parent 649df36 commit 969732b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 15 deletions.
74 changes: 73 additions & 1 deletion app/src/main/mockServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ let randomPubkey = () => ({
module.exports = function (port = 8999) {
let app = express()

// log all requests
app.use((req, res, next) => {
console.log('REST request:', req.method, req.originalUrl, req.body)
next()
})

// delegation mock API
let candidates = new Array(205).fill(0).map(randomPubkey)
let candidates = new Array(50).fill(0).map(randomPubkey)
app.get('/query/stake/candidate', (req, res) => {
res.json({
height: 10000,
Expand All @@ -34,6 +40,72 @@ module.exports = function (port = 8999) {
}
})
})
app.post('/tx/stake/delegate/:pubkey/:amount', (req, res) => {
res.json({
"type": "sigs/one",
"data": {
"tx": {
"type": "chain/tx",
"data": {
"chain_id": "gaia-1",
"expires_at": 0,
"tx": {
"type": "nonce",
"data": {
"sequence": 1,
"signers": [
{
"chain": "",
"app": "sigs",
"addr": "84A057DCE7E1DB8EBE3903FC6B2D912E63EF9BEA"
}
],
"tx": {
"type": "coin/send",
"data": {
"inputs": [
{
"address": {
"chain": "",
"app": "sigs",
"addr": "84A057DCE7E1DB8EBE3903FC6B2D912E63EF9BEA"
},
"coins": [
{
"denom": "atom",
"amount": 1
}
]
}
],
"outputs": [
{
"address": {
"chain": "",
"app": "sigs",
"addr": "84A057DCE7E1DB8EBE3903FC6B2D912E63EF9BEA"
},
"coins": [
{
"denom": "atom",
"amount": 1
}
]
}
]
}
}
}
}
}
},
"signature": {
"Sig": null,
"Pubkey": null
}
}
})
})

// proxy everything else to light client
app.use(proxy('http://localhost:8998'))
Expand Down
4 changes: 2 additions & 2 deletions app/src/renderer/components/staking/CardCandidate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ transition(name='ts-card-candidate'): div(:class='cssClass')
span {{ num.prettyInt(candidate.voting_power) }}
.bar(:style='atomsCss')
.value.atoms.num.bar.delegated(v-if='signedIn')
span {{ num.prettyInt(candidate.computed.delegatedCoins) }}
span {{ num.prettyInt(candidate.delegatedCoins) }}
.bar(:style='delegatedAtomsCss')
.value.shares.num
span
Expand Down Expand Up @@ -66,7 +66,7 @@ export default {
return 0
},
delegatedAtomsCss () {
let percentage = Math.round((this.candidate.computed.delegatedAtoms /
let percentage = Math.round((this.candidate.delegatedAtoms /
this.maxDelegatedAtoms) * 100)
return { width: percentage + '%' }
},
Expand Down
25 changes: 13 additions & 12 deletions app/src/renderer/vuex/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export default ({ commit, node }) => {
}

const emptyUser = {
atoms: 0,
atoms: 10000,
nominationActive: false,
nomination: JSON.parse(JSON.stringify(emptyNomination)),
delegationActive: false,
delegation: [],
pubkey: '',
privkey: null,
signedIn: false
signedIn: true
}

const state = JSON.parse(JSON.stringify(emptyUser))
Expand All @@ -50,13 +50,6 @@ export default ({ commit, node }) => {
state.ownCoinsBonded = 0
node.wallet = null
},
activateNomination (state) {
state.nominationActive = true
},
saveNomination (state, value) {
state.nomination = value
console.log('nomination saved: ', JSON.stringify(state.nomination))
},
activateDelegation (state) {
state.delegationActive = true
}
Expand Down Expand Up @@ -93,11 +86,19 @@ export default ({ commit, node }) => {
async submitDelegation (state, value) {
state.delegation = value
console.log('submitting delegation txs: ', JSON.stringify(state.delegation))

for (let candidate of value.candidates) {
let pubKeyBytes = Buffer.from(candidate.id, 'base64')
let pubKey = PubKey.decode(pubKeyBytes)
await node.delegationGame.delegate(pubKey, node.wallet, candidate.atoms)
let tx = await node.buildDelegate([ candidate.id, candidate.atoms ])
let signedTx = await node.sign({
name: 'default',
password: '1234567890',
tx
})
let res = await node.postTx(signedTx)
console.log(res)
}

commit('activateDelegation', true)
}
}

Expand Down

0 comments on commit 969732b

Please sign in to comment.