-
Notifications
You must be signed in to change notification settings - Fork 98
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
Peng/123 vuex tests #333
Peng/123 vuex tests #333
Changes from 13 commits
8f6e8b0
b55a924
23a6c85
49d79af
fa9edc9
6b833e2
d16a3ae
05e66d8
b2b7673
0a31a82
ad826b9
35aaaf8
d993b82
7ed1de1
7cbd185
753d769
e169eb6
3ccb91c
e9265d8
6fce13a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict' | ||
const RpcClient = require('tendermint') | ||
const RestClient = require('cosmos-sdk') | ||
const axios = require('axios') | ||
|
||
const RELAY_SERVER = 'http://localhost:8999' | ||
|
||
|
@@ -61,6 +62,28 @@ module.exports = function (nodeIP) { | |
|
||
node.rpcConnecting = false | ||
return nodeIP | ||
}, | ||
async sendTx (args, account, password) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this might not be the right module, although I understand why |
||
let tx = await (async function () { | ||
switch (args.type) { | ||
case 'buildDelegate': return axios.post('http://localhost:8998/build/stake/delegate', args) | ||
.then(res => res.data) | ||
case 'buildUnbond': return axios.post('http://localhost:8998/build/stake/unbond', args) | ||
.then(res => res.data) | ||
default: return node[args.type](args) | ||
} | ||
})() | ||
let signedTx = await node.sign({ | ||
name: account, | ||
password: password, | ||
tx | ||
}) | ||
let res = await node.postTx(signedTx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's important that this goes through the same wallet sending code that it was separated from in this PR, to properly process multiple transactions serially and set the correct account sequence number on each transaction. Otherwise, transactions created here will only succeed if it is an account's first transaction. |
||
// check response code | ||
if (res.check_tx.code || res.deliver_tx.code) { | ||
let message = res.check_tx.log || res.deliver_tx.log | ||
throw new Error('Error sending transaction: ' + message) | ||
} | ||
} | ||
}) | ||
// TODO: eventually, get all data from light-client connection instead of RPC | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,14 +66,14 @@ export default ({ commit }) => { | |
await dispatch('walletTx', args) | ||
}, | ||
async submitDelegation ({ state, dispatch }, delegation) { | ||
for (let delegate of delegation.delegates) { | ||
return Promise.all(delegation.delegates.map(delegate => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running these in parallel does not help since we have to sequentially increment the nonce and check that the tx went through. Really this should all happen in an atomic operation, but the LCD does not support that. Will open a ticket. |
||
let candidateId = delegate.delegate.pub_key.data | ||
let currentlyDelegated = state.committedDelegates[candidateId] || 0 | ||
let amountChange = delegate.atoms - currentlyDelegated | ||
let action = amountChange > 0 ? 'walletDelegate' : 'walletUnbond' | ||
|
||
// skip if no change | ||
if (amountChange === 0) continue | ||
if (amountChange === 0) return null | ||
|
||
// bonding takes a 'coin' object, unbond just takes a number | ||
let amount | ||
|
@@ -84,17 +84,11 @@ export default ({ commit }) => { | |
amount = Math.abs(amountChange) | ||
} | ||
|
||
await new Promise((resolve, reject) => { | ||
dispatch(action, { | ||
amount, | ||
pub_key: delegate.delegate.pub_key, | ||
cb: (err, res) => { | ||
if (err) return reject(err) | ||
resolve(res) | ||
} | ||
}) | ||
return dispatch(action, { | ||
amount, | ||
pub_key: delegate.delegate.pub_key | ||
}) | ||
} | ||
}).filter(x => x !== null)) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
err => { ... }
the same as.catch()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the
then(_, onReject)
will get called instead of.catch
if available. See: https://codepen.io/faboweb/pen/WdmRoOThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! thanks for the example. still not sure when to use one vs the other...?