From a08f568353603a0143def4a934270e6f02c7ade4 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Mon, 3 Dec 2018 16:34:38 +0100 Subject: [PATCH] Show block for EthereumType coins --- api/worker.go | 31 ++++++++++++++++++++++--------- bchain/coins/eth/ethparser.go | 1 + bchain/coins/eth/ethrpc.go | 1 + static/templates/block.html | 12 ++++++------ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/api/worker.go b/api/worker.go index c31e4db4..75b3770e 100644 --- a/api/worker.go +++ b/api/worker.go @@ -824,24 +824,37 @@ func (w *Worker) GetBlock(bid string, page int, txsOnPage int) (*Block, error) { return nil, errors.Annotatef(err, "GetBestBlock") } pg, from, to, page := computePaging(txCount, page, txsOnPage) - glog.Info("GetBlock ", bid, ", page ", page, " finished in ", time.Since(start)) txs := make([]*Tx, to-from) txi := 0 for i := from; i < to; i++ { txid := bi.Txids[i] - ta, err := w.db.GetTxAddresses(txid) - if err != nil { - return nil, errors.Annotatef(err, "GetTxAddresses %v", txid) + if w.chainType == bchain.ChainBitcoinType { + ta, err := w.db.GetTxAddresses(txid) + if err != nil { + return nil, errors.Annotatef(err, "GetTxAddresses %v", txid) + } + if ta == nil { + glog.Warning("DB inconsistency: tx ", txid, ": not found in txAddresses") + continue + } + txs[txi] = w.txFromTxAddress(txid, ta, dbi, bestheight) + } else { + txs[txi], err = w.GetTransaction(txid, false, false) + if err != nil { + return nil, err + } } - if ta == nil { - glog.Warning("DB inconsistency: tx ", txid, ": not found in txAddresses") - continue - } - txs[txi] = w.txFromTxAddress(txid, ta, dbi, bestheight) txi++ } + if bi.Prev == "" && bi.Height != 0 { + bi.Prev, _ = w.db.GetBlockHash(bi.Height - 1) + } + if bi.Next == "" && bi.Height != bestheight { + bi.Next, _ = w.db.GetBlockHash(bi.Height + 1) + } txs = txs[:txi] bi.Txids = nil + glog.Info("GetBlock ", bid, ", page ", page, " finished in ", time.Since(start)) return &Block{ Paging: pg, BlockInfo: *bi, diff --git a/bchain/coins/eth/ethparser.go b/bchain/coins/eth/ethparser.go index 391ef2eb..e386d389 100644 --- a/bchain/coins/eth/ethparser.go +++ b/bchain/coins/eth/ethparser.go @@ -33,6 +33,7 @@ func NewEthereumParser(b int) *EthereumParser { type rpcHeader struct { Hash string `json:"hash"` + ParentHash string `json:"parentHash"` Difficulty string `json:"difficulty"` Number string `json:"number"` Time string `json:"timestamp"` diff --git a/bchain/coins/eth/ethrpc.go b/bchain/coins/eth/ethrpc.go index 766a1723..ad079e50 100644 --- a/bchain/coins/eth/ethrpc.go +++ b/bchain/coins/eth/ethrpc.go @@ -370,6 +370,7 @@ func (b *EthereumRPC) ethHeaderToBlockHeader(h *rpcHeader) (*bchain.BlockHeader, } return &bchain.BlockHeader{ Hash: h.Hash, + Prev: h.ParentHash, Height: uint32(height), Confirmations: int(c), Time: time, diff --git a/static/templates/block.html b/static/templates/block.html index fc896425..87d4f2f8 100644 --- a/static/templates/block.html +++ b/static/templates/block.html @@ -3,9 +3,9 @@
{{$b.Hash}}
-
-

Summary

-
{{- if $b.Transactions -}} -
-

Transactions

- +
+

Transactions

+
{{- range $tx := $b.Transactions}}{{$data := setTxToTemplateData $data $tx}}{{template "txdetail" $data}}{{end -}}