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

Billy/454 tx info #770

Merged
merged 25 commits into from
Jun 5, 2018
Merged

Billy/454 tx info #770

merged 25 commits into from
Jun 5, 2018

Conversation

okwme
Copy link
Contributor

@okwme okwme commented May 30, 2018

Closes #454

Description:
the block explorer doesn't show any details of transactions.

followed the same method of querying txs from the explorer and added an rpc handler to get them.
need help with layout design of how these should look @nylira @jolesbi

screenshot 2018-05-30 17 24 47

will add tests next as this is still WIP

@okwme okwme requested review from faboweb, NodeGuy and nylira as code owners May 30, 2018 15:25
@@ -89,6 +89,8 @@ Object.assign(Client.prototype, {
},
coinTxs: argReq("GET", "/tx/coin"),

txs: argReq("GET", "/txs"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

🥇

@codecov
Copy link

codecov bot commented May 30, 2018

Codecov Report

Merging #770 into develop will decrease coverage by <.01%.
The diff coverage is 95.65%.

@@             Coverage Diff             @@
##           develop     #770      +/-   ##
===========================================
- Coverage    87.56%   87.55%   -0.01%     
===========================================
  Files           94       95       +1     
  Lines         1608     1639      +31     
  Branches        91       94       +3     
===========================================
+ Hits          1408     1435      +27     
- Misses         184      188       +4     
  Partials        16       16
Impacted Files Coverage Δ
app/src/renderer/components/wallet/PageSend.vue 93.33% <ø> (-0.15%) ⬇️
app/src/renderer/vuex/getters.js 100% <ø> (ø) ⬆️
app/src/renderer/connectors/lcdClient.js 95.23% <ø> (ø) ⬆️
app/src/renderer/connectors/rpcWrapperMock.js 100% <100%> (ø) ⬆️
app/src/renderer/vuex/modules/blockchain.js 100% <100%> (+2.32%) ⬆️
app/src/renderer/vuex/modules/wallet.js 88.46% <100%> (ø) ⬆️
app/src/renderer/scripts/tx-utils.js 100% <100%> (ø)
app/src/renderer/components/monitor/PageBlock.vue 81.25% <75%> (-18.75%) ⬇️
... and 2 more

@jbibla
Copy link
Collaborator

jbibla commented May 30, 2018

i'm not sure about what data is actually available - but if it could match the tx history component that might be nice.

@faboweb faboweb changed the title WIP: Billy/454 tx info Billy/454 tx info Jun 4, 2018
@@ -44,13 +44,23 @@ page(:title="pageBlockTitle")
part(title='Transactions')
data-loading(v-if="blockchain.blockLoading")
data-empty(v-else-if="block.header.num_txs === 0" title="Empty Block" subtitle="There were no transactions in this block.")
list-item(v-else v-for="tx in block.data.txs" :key="tx.id" dt="Transaction" :dd="TODO")
template(
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jolesbi this is what you were looking for, right?

@@ -68,12 +79,15 @@ export default {
Page
},
computed: {
...mapGetters(["blockchain"]),
...mapGetters(["blockchain", "blocTxInfo", "config"]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at least it was consistently misspelled 😜

@@ -61,6 +81,66 @@ export default ({ commit, node }) => {
})
})
},
async queryTxInfo({ state, dispatch }, height) {
let blockTxInfo = state.blockTxs.find(
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not store them per height?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was following method used by queryBlockInfo() but you're right keying the height is smart i'll update both of em

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually just updating the blockchain one for sake of PR scope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually i think both of these need to stay as arrays as they are used in for loops

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you point me to where they are used in loops? What I have found, there is always a selection by height happening when blockTxs appear in code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops i totally misinterpreted the unit test error relating to should disable the next block button if last block. thought that info was counting an array length for looping and failed when it became an obj (as per a similar error in blockchain.spec.js). i've gone back and updated to a keyed storage method for blockTxs as well as blockMetas

blockTxInfo && state.blockTxs.push(blockTxInfo)
return blockTxInfo
} catch (error) {
return Promise.reject(error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't that the default for async functions rejecting on error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was having trouble getting the error reporting come out correctly in the tests so went through and made each error very explicit until i found the culprit, i'll walk it back

},
getTxs({ state, commit, dispatch }, { key, len, txs }) {
return new Promise(async (resolve, reject) => {
if (key >= len) return resolve(txs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a comment stating what this statement accomplishes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

return Promise.reject(error)
}
},
convertTx({ state }, txstring) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't do any manipulation on the store and should therefor maybe be in a script or someplace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there a clever place to put it in or just make a new file under /src/scripts?

@@ -84,9 +85,9 @@ export default ({ commit, node }) => {
},
async queryWalletHistory({ state, commit, dispatch }) {
commit("setHistoryLoading", true)
// let res = await node.coinTxs(state.address)
let res = await node.coinTxs(state.address)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does history work again?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh i uncommented this to see what NiLiTx looked like and it seemed to work with mock network. i'll remove tho since that's not the point of this pr

import varint from "varint"
import b64 from "base64-js"

export default function(txstring) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The script is called utils and exports a function that converts tx strings into json? I think this is not really understandable.
How about a script called tx-utils.js that exports a function named parseTx?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree it should be named, could be something like getTxHash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, i think getTxHash is an accurate name

])
.then(() => {
state.blockLoading = false
dispatch("queryTxInfo", height)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you return this, I think you save yourself the inner .catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored all the promises to be more concise

Copy link
Contributor

@mappum mappum left a comment

Choose a reason for hiding this comment

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

Left some comments but nice work overall, I know it can be a pain figuring out how to derive the same hash as the golang code. 😋

import b64 from "base64-js"

export default function(txstring) {
let txbytes = b64.toByteArray(txstring)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add a dependency instead of doing Buffer.from(base64string, 'base64')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

didn't realize it was that ez!

let txstring = atob(txs[key])
let hash = await convertTx(txs[key])
node
.txs(hash)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why mix await and .then syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored all the promises to be more concise

blockTxInfo = await dispatch("getTxs", {
key: 0,
len:
state.block && state.block.data && state.block.data.txs
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of these chains of &&'s? Seems like it makes things harder to debug because if the format changes or data is missing, it will silently pass this call and have undefined behavior inside getTxs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was to allow the tests that had very minimal dummy blocks to pass. but you're right if the block is malformed it should throw an error. i've updated the other tests to use a well formed block dummy

@@ -0,0 +1,14 @@
import createHash from "create-hash"
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't we just get this from the Node crypto module to avoid adding a dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice, didn't realize it was also that ez

import varint from "varint"
import b64 from "base64-js"

export default function(txstring) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree it should be named, could be something like getTxHash

@okwme okwme merged commit 604b15f into develop Jun 5, 2018
@okwme okwme deleted the billy/454-tx-info branch June 5, 2018 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PageBlock isn't displaying Tx data (when there is supposed to be data)
5 participants