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

Explorer V2 #202

Merged
merged 3 commits into from
Oct 4, 2017
Merged

Explorer V2 #202

merged 3 commits into from
Oct 4, 2017

Conversation

oluwandabira
Copy link
Member

@oluwandabira oluwandabira commented Sep 26, 2017

Explorer V2

For issue #198 and #138

Current issues being addressed in V2:

  • Explore page blocks always show 0 transactions
  • Not showing Coinbase on Coinbase transaction page
  • Vote transaction page not showing Prevout Address and shows "Pending" in Output block column
  • SIGUSR1 doesn't reload the templates (probably has to do with the directory structure)
  • Properly document the package and remove excess comments

Improvements over V1:

  • Mining fee shown on block page (not sure if it's correct though)
  • Improved code organization
  • Completely separate explorer from the api
  • Use websockets to show current block height on all explorer pages and update some info on each page (mostly just the confirmations)
  • Tests

@gozart1 gozart1 mentioned this pull request Sep 27, 2017
@oluwandabira oluwandabira changed the title [WIP] Explorer V2 Explorer V2 Oct 3, 2017
@oluwandabira
Copy link
Member Author

This is ready for review and merge. The only issue is the upstream vote vin issue, all unchecked items will be added in a later pr.

Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

Not tested, but this really cleans things up. Will test.


getTotalSpent := func(txs []*explorer.TxBasic) (total float64) {
for _, tx := range txs {
total += tx.Fee.ToCoin()
Copy link
Member

Choose a reason for hiding this comment

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

"spent" is the sum of the input values. What's going on here with tx.Fee?

Copy link
Member Author

Choose a reason for hiding this comment

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

I assumed total sent is the sum of the input values and total spent is the sum of the fees

Copy link
Member

Choose a reason for hiding this comment

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

The miner fees for a transaction are sum(inputs) - sum(outputs). Perhaps it's confusing, but I refer to the sum of inputs as spent since it's how much you as the sender spend to make the tx happen, while sent is how much you are sending to the output address(es). The difference is the fees that the miner gets.

The fees for a block could be just that sum total += tx.Fee.ToCoin() over all transactions tx. Or it could be done the way you started it by computing sum of sum of inputs, but then it would need sum of sum of outputs for the difference to get mining fee.

Double check against the Insight explorer to be sure it makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed MiningFee calculation to sum fees in over all tx except votes. I checked and the tx fees are the same on the Insight explorer.


block.TotalSent = getTotalSent(block.Tx) + getTotalSent(block.Revs) + getTotalSent(block.Tickets)
block.TotalSpent = getTotalSpent(block.Tx) + getTotalSpent(block.Revs) + getTotalSpent(block.Tickets)
block.MiningFee = block.TotalSent - block.TotalSpent
Copy link
Member

Choose a reason for hiding this comment

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

for a valid tx, spent >= sent
(inputs - outputs = fee)

log.Errorf("GetRawTransactionVerbose failed for: %v", txhash)
return nil
}
msgTx := txhelpers.MsgTxFromHex(txraw.Hex)
Copy link
Member

Choose a reason for hiding this comment

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

check for nil


inputs := make([]explorer.Vin, 0, len(txraw.Vin))
for i, vin := range txraw.Vin {
coinbase := vin.Coinbase
Copy link
Member

Choose a reason for hiding this comment

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

please make a TODO that when Stakebase becomes a usable vin, we need to handle that too.
I'm OK with reusing explorer.Vin.CoinBase for both stakebase and coinbase, but we need to get the right one from vin depending on the type of tx

type Vin struct {
TxID string
CoinBase string
Address string
Copy link
Member

@chappjc chappjc Oct 3, 2017

Choose a reason for hiding this comment

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

Assuming this is the previous outpoint's address(es)?

A vout, and thus this vin's prevout, may have multiple addresses decoded from their pkScript.

@@ -1,4 +1,7 @@
package main
// Package explorer handles the explorer subsystem for displaying the explorer pages
// Copyright (c) 2017, The Dcrdata developers
Copy link
Member

Choose a reason for hiding this comment

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

👍 Let's update the LICENSE file too.
Although, I'm leaning toward all lowercase as our universal formatting, despite being a proper noun:
The dcrdata.org developers or The dcrdata developers

r.Route("/{blockhash}", func(rd chi.Router) {
rd.Use(exp.app.BlockHashPathOrIndexCtx)
rd.Use(exp.blockHashPathOrIndexCtx)
Copy link
Member

Choose a reason for hiding this comment

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

It looked like the blockPage is only using getBlockHashCtx now, so can't this middleware be a simpler handler that does not try to get the height when it's not needed? Or or is this route intended to handle height's input here instead of a hash?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

OIC.

@@ -0,0 +1,124 @@
package explorer
Copy link
Member

Choose a reason for hiding this comment

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

Prepend license notification stuff


func (exp *explorerUI) blockHashPathOrIndexCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// hash := chi.URLParam(r, "blockhash")
Copy link
Member

Choose a reason for hiding this comment

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

you can nuke all these comments

views/tx.tmpl Outdated
<th class="text-center">DCR</th>
<thead>
<th>Address</th>
<th class="text-center">Type</th>
Copy link
Member

Choose a reason for hiding this comment

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

minor formatting inconsistency

@chappjc
Copy link
Member

chappjc commented Oct 3, 2017

Needs rebase.

func makeExplorerTxBasic(data dcrjson.TxRawResult, msgTx *wire.MsgTx) *explorer.TxBasic {
tx := new(explorer.TxBasic)
tx.TxID = data.Txid
tx.FormattedSize = humanize.Bytes(uint64(len(data.Hex)))
Copy link
Member

Choose a reason for hiding this comment

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

size is double. need data.Hex/2

@chappjc
Copy link
Member

chappjc commented Oct 4, 2017

Cool. I'm also seeing an vote version column header but no vote version. Perhaps because it just needs a rebase still.

@oluwandabira
Copy link
Member Author

Not a rebase, a rework. The vote version stuff was dependent on the explorer V1 system. If @McEdward could take a look and add it in, that'll be great.

@chappjc
Copy link
Member

chappjc commented Oct 4, 2017

Well that's unfortunate. Should not really be your problem that we just put the voteinfo PR in first. Sorry about that.

@McEdward please provide guidance or better yet a commit on top of this branch that @RogueElement can cherry pick

@chappjc
Copy link
Member

chappjc commented Oct 4, 2017

aaaand I just made this infinitely harder on you. sorry. The restyling just went in. With a decent 3-way merge tool this shouldn't be horrible though.

@chappjc
Copy link
Member

chappjc commented Oct 4, 2017

@gozart1 Some pretty hefty conflicts landed here following your redesign PR, which was inevitable, but if there are any non-trivial or non-obvious edits that seem to conflict with dabira's, he could probably use a hand sorting it out.

Thanks and sorry for the complications. Several PRs had to go in at almost the same time.

@gozart1
Copy link
Member

gozart1 commented Oct 4, 2017

I can take a look at this in about 12hrs from now.

The deltas a huge because the layout change a lot. But the actual content that #202 modifies is not that large. So I suggest the following strategy:

Copy and paste these templates

views/address.tmpl
views/block.tmpl
views/explorer.tmpl
views/tx.tmpl

directly from master, then by looking over your existing 13 commits, manually re-apply the changes you made to the tmpl files in this PR to them. One way to easily see all the changes would be to diff this branch with the commit in master before my PR was merged.

You may want to create a 2nd branch to be extra safe and just keep this one around for reference. Once you've copied the templates and applied the changes the diff should be clean and we can double check to make sure all your changes made it in.

Fixed explore and block pages

Added tx page

Added Address page

Fixed Tx and Address pages

Fixed minor errors and started ro remove explorer v1

Removed unnecessary conversion

Removed redundant function

Change IsStakeBase check for now

Added non-redundant function

Updated LICENSE and added minor changes
@oluwandabira
Copy link
Member Author

Squashed and rebased, just needs a review and merge

return nil
}
msgTx := txhelpers.MsgTxFromHex(txraw.Hex)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

oops, you're checking err here instead of msgTx

<a href="/explorer/address/{{.}}">{{.}}</a>
<td>
{{range .Addresses}}
<a class="break-word mono" href="/explorer/address/{{.}}">{{.}}</a><br>
Copy link
Member

Choose a reason for hiding this comment

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

Just want to make sure losing the class="break-word mono" part was intentional since the rebase was pretty epic. a break-word also disappeared way above too so I'm guessing this wasn't a mistake, but I want to be sure.

@chappjc chappjc merged commit 28e42b3 into decred:master Oct 4, 2017
@chappjc chappjc mentioned this pull request Oct 5, 2017
Jujhar pushed a commit to McEdward/dcrdata that referenced this pull request Sep 26, 2018
* Started on Explorer Version 2

Fixed explore and block pages

Added tx page

Added Address page

Fixed Tx and Address pages

Fixed minor errors and started ro remove explorer v1

Removed unnecessary conversion

Removed redundant function

Change IsStakeBase check for now

Added non-redundant function

Updated LICENSE and added minor changes

* Fixed MiningFee calculation and removed unused function

* Corrected msgTx error check
Jujhar pushed a commit to McEdward/dcrdata that referenced this pull request Oct 1, 2018
* Started on Explorer Version 2

Fixed explore and block pages

Added tx page

Added Address page

Fixed Tx and Address pages

Fixed minor errors and started ro remove explorer v1

Removed unnecessary conversion

Removed redundant function

Change IsStakeBase check for now

Added non-redundant function

Updated LICENSE and added minor changes

* Fixed MiningFee calculation and removed unused function

* Corrected msgTx error check
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.

3 participants