Skip to content

Commit

Permalink
Delete unnused code from the earlier PR decred#535
Browse files Browse the repository at this point in the history
  • Loading branch information
dmigwi committed Sep 7, 2018
1 parent 28fbfff commit 375558d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 250 deletions.
46 changes: 0 additions & 46 deletions api/types/apitypes.go
Expand Up @@ -5,7 +5,6 @@ package types

import (
"github.com/decred/dcrd/dcrjson"
"github.com/decred/dcrd/dcrutil"
"github.com/decred/dcrdata/txhelpers"
)

Expand Down Expand Up @@ -297,51 +296,6 @@ type BlockExplorerBasic struct {
BlockExplorerExtraInfo
}

// BlockDataInfo models detailed information about block at height Height
// for the block explorer.
type BlockDataInfo struct {
*BlockExplorerBasic
Hash string
Version int32
Confirmations int64
StakeRoot string
MerkleRoot string
TxAvailable bool
Tx []*TxBasic
Tickets []*TxBasic
Revs []*TxBasic
Votes []*TxBasic
Misses []string
Nonce uint32
VoteBits uint16
FinalState string
PoolSize uint32
Bits string
SBits float64
Difficulty float64
ExtraData string
StakeVersion uint32
PreviousHash string
NextHash string
TotalSent float64
MiningFee dcrutil.Amount
StakeValidationHeight int64
}

// TxBasic models data for transactions on the block page
type TxBasic struct {
TxID string
FormattedSize string
ByteSize string
TxAmount string
FeeRateSize string
Total float64
Fee dcrutil.Amount
FeeRate dcrutil.Amount
VoteInfo *VoteInfo
Coinbase bool
}

// BlockExplorerExtraInfo contains supplemental block metadata used by the
// explorer.
type BlockExplorerExtraInfo struct {
Expand Down
129 changes: 6 additions & 123 deletions db/dcrsqlite/apisource.go
Expand Up @@ -946,59 +946,12 @@ func makeExplorerTxBasic(data dcrjson.TxRawResult, msgTx *wire.MsgTx, params *ch
tx.TxID = data.Txid
tx.FormattedSize = humanize.Bytes(uint64(len(data.Hex) / 2))
tx.Total = txhelpers.TotalVout(data.Vout).ToCoin()
ByteSize := uint64(len(data.Hex) / 2)

if tx.Total < 50.0 {
tx.TxAmount = "xs"
} else if 50.0 <= tx.Total && tx.Total < 100.0 {
tx.TxAmount = "s"
} else if 100.0 <= tx.Total && tx.Total < 200.0 {
tx.TxAmount = "m"
} else if 200.0 <= tx.Total && tx.Total < 500.0 {
tx.TxAmount = "l"
} else if 500.0 <= tx.Total && tx.Total < 1000.0 {
tx.TxAmount = "xl"
} else if 1000.0 <= tx.Total {
tx.TxAmount = "xxl"
}

if ByteSize < 500 {
tx.ByteSize = "xs-size"
} else if 500 <= ByteSize && ByteSize < 1000 {
tx.ByteSize = "s-size"
} else if 1000 <= ByteSize && ByteSize < 2000 {
tx.ByteSize = "m-size"
} else if 2000 <= ByteSize && ByteSize < 10000 {
tx.ByteSize = "l-size"
} else if 10000 <= ByteSize && ByteSize < 50000 {
tx.ByteSize = "xl-size"
} else if 50000 <= ByteSize {
tx.ByteSize = "xxl-size"
}

tx.Fee, tx.FeeRate = txhelpers.TxFeeRate(msgTx)
for _, i := range data.Vin {
if i.IsCoinBase() {
tx.Coinbase = true
}
}

FeeRate := tx.FeeRate.ToCoin()

if FeeRate < 0.001 {
tx.FeeRateSize = "lowest"
} else if 0.001 <= FeeRate && FeeRate < 0.01 {
tx.FeeRateSize = "low"
} else if 0.01 <= FeeRate && FeeRate < 0.1 {
tx.FeeRateSize = "moderate"
} else if 0.1 <= FeeRate && FeeRate < 0.5 {
tx.FeeRateSize = "moderate-high"
} else if 0.5 <= FeeRate && FeeRate < 1.0 {
tx.FeeRateSize = "high"
} else if 1.0 <= FeeRate {
tx.FeeRateSize = "very-high"
}

if stake.IsSSGen(msgTx) {
validation, version, bits, choices, err := txhelpers.SSGenVoteChoices(msgTx, params)
if err != nil {
Expand Down Expand Up @@ -1062,22 +1015,6 @@ func (db *wiredDB) GetExplorerBlocks(start int, end int) []*explorer.BlockBasic
return summaries
}

func (db *wiredDB) GetExplorerFullBlocks(start int, end int) []*explorer.BlockInfo {
if start < end {
return nil
}
summaries := make([]*explorer.BlockInfo, 0, start-end)
for i := start; i > end; i-- {
data := db.GetBlockVerbose(i, true)
block := new(explorer.BlockInfo)
if data != nil {
block = db.GetExplorerBlock(data.Hash)
}
summaries = append(summaries, block)
}
return summaries
}

func (db *wiredDB) GetExplorerBlock(hash string) *explorer.BlockInfo {
data := db.GetBlockVerboseByHash(hash, true)
if data == nil {
Expand Down Expand Up @@ -1524,57 +1461,6 @@ func (db *wiredDB) GetMempool() []explorer.MempoolTx {
}
var voteInfo *explorer.VoteInfo

_, Fee_Rate := txhelpers.TxFeeRate(msgTx)

FeeRate := Fee_Rate.ToCoin()
var FeeRateSize string

if FeeRate < 0.001 {
FeeRateSize = "lowest"
} else if 0.001 <= FeeRate && FeeRate < 0.01 {
FeeRateSize = "low"
} else if 0.01 <= FeeRate && FeeRate < 0.1 {
FeeRateSize = "moderate"
} else if 0.1 <= FeeRate && FeeRate < 0.5 {
FeeRateSize = "moderate-high"
} else if 0.5 <= FeeRate && FeeRate < 1.0 {
FeeRateSize = "high"
} else if 1.0 <= FeeRate {
FeeRateSize = "very-high"
}

var TxAmount string

if total < 50.0 {
TxAmount = "xs"
} else if 50.0 <= total && total < 100.0 {
TxAmount = "s"
} else if 100.0 <= total && total < 200.0 {
TxAmount = "m"
} else if 200.0 <= total && total < 500.0 {
TxAmount = "l"
} else if 500.0 <= total && total < 1000.0 {
TxAmount = "xl"
} else if 1000.0 <= total {
TxAmount = "xxl"
}

var ByteSize string

if tx.Size < 500 {
ByteSize = "xs-size"
} else if 500 <= tx.Size && tx.Size < 1000 {
ByteSize = "s-size"
} else if 1000 <= tx.Size && tx.Size < 2000 {
ByteSize = "m-size"
} else if 2000 <= tx.Size && tx.Size < 10000 {
ByteSize = "l-size"
} else if 10000 <= tx.Size && tx.Size < 50000 {
ByteSize = "xl-size"
} else if 50000 <= tx.Size {
ByteSize = "xxl-size"
}

if ok := stake.IsSSGen(msgTx); ok {
validation, version, bits, choices, err := txhelpers.SSGenVoteChoices(msgTx, db.params)
if err != nil {
Expand All @@ -1595,15 +1481,12 @@ func (db *wiredDB) GetMempool() []explorer.MempoolTx {
}
}
txs = append(txs, explorer.MempoolTx{
Hash: hash,
Time: tx.Time,
Size: tx.Size,
TotalOut: total,
TxAmount: TxAmount,
FeeRateSize: FeeRateSize,
ByteSize: ByteSize,
Type: txhelpers.DetermineTxTypeString(msgTx),
VoteInfo: voteInfo,
Hash: hash,
Time: tx.Time,
Size: tx.Size,
TotalOut: total,
Type: txhelpers.DetermineTxTypeString(msgTx),
VoteInfo: voteInfo,
})
}

Expand Down
70 changes: 25 additions & 45 deletions explorer/explorer.go
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/decred/dcrdata/blockdata"
"github.com/decred/dcrdata/db/dbtypes"
"github.com/decred/dcrdata/txhelpers"
humanize "github.com/dustin/go-humanize"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/rs/cors"
Expand All @@ -45,7 +46,6 @@ type explorerDataSourceLite interface {
GetBlockHeight(hash string) (int64, error)
GetBlockHash(idx int64) (string, error)
GetBlockVerboseByHash(hash string, verboseTx bool) *dcrjson.GetBlockVerboseResult
GetExplorerFullBlocks(start int, end int) []*BlockInfo
GetExplorerTx(txid string) *TxInfo
GetExplorerAddress(address string, count, offset int64) *AddressInfo
DecodeRawTransaction(txhex string) (*dcrjson.TxRawResult, error)
Expand Down Expand Up @@ -125,20 +125,20 @@ func TicketStatusText(s dbtypes.TicketSpendType, p dbtypes.TicketPoolStatus) str
}

type explorerUI struct {
Mux *chi.Mux
blockData explorerDataSourceLite
explorerSource explorerDataSource
liteMode bool
devPrefetch bool
templates templates
wsHub *WebsocketHub
NewBlockDataMtx sync.RWMutex
NewFullBlockData *BlockInfo
ExtraInfo *HomeInfo
MempoolData *MempoolInfo
ChainParams *chaincfg.Params
Version string
NetName string
Mux *chi.Mux
blockData explorerDataSourceLite
explorerSource explorerDataSource
liteMode bool
devPrefetch bool
templates templates
wsHub *WebsocketHub
NewBlockDataMtx sync.RWMutex
NewBlockData *BlockBasic
ExtraInfo *HomeInfo
MempoolData *MempoolInfo
ChainParams *chaincfg.Params
Version string
NetName string
}

func (exp *explorerUI) reloadTemplates() error {
Expand Down Expand Up @@ -257,7 +257,7 @@ func New(dataSource explorerDataSourceLite, primaryDataSource explorerDataSource
func (exp *explorerUI) Height() int64 {
exp.NewBlockDataMtx.RLock()
defer exp.NewBlockDataMtx.RUnlock()
return exp.NewFullBlockData.Height
return exp.NewBlockData.Height
}

// prePopulateChartsData should run in the background the first time the system
Expand Down Expand Up @@ -305,41 +305,20 @@ func (exp *explorerUI) Store(blockData *blockdata.BlockData, _ *wire.MsgBlock) e
// Lock for explorerUI's NewBlockData and ExtraInfo
exp.NewBlockDataMtx.Lock()

hash, _ := exp.blockData.GetBlockHash(int64(bData.Height))
newBlockData := exp.blockData.GetExplorerBlock(hash)
bdHeight := newBlockData.Height
/**newBlockData := &BlockInfo{
BlockBasic: &BlockBasic{Height: int64(bData.Height),
newBlockData := &BlockBasic{
Height: int64(bData.Height),
Hash: blockData.Header.Hash,
Voters: bData.Voters,
FreshStake: bData.FreshStake,
Size: int32(bData.Size),
Transactions: bData.TxLen,
BlockTime: bData.Time,
FormattedTime: bData.FormattedTime,
FormattedBytes: humanize.Bytes(uint64(bData.Size))
Revocations: uint32(bData.Revocations)},
Hash: bFullData.Hash,
Version: bFullData.Version,
Confirmations: bFullData.Confirmations,
StakeRoot: bFullData.StakeRoot,
MerkleRoot: bFullData.MerkleRoot,
Nonce: bFullData.Nonce,
VoteBits: bFullData.VoteBits,
FinalState: bFullData.FinalState,
PoolSize: bFullData.PoolSize,
Bits: bFullData.Bits,
SBits: bFullData.SBits,
Difficulty: bFullData.Difficulty,
ExtraData: bFullData.ExtraData,
StakeVersion: bFullData.StakeVersion,
PreviousHash: bFullData.PreviousHash,
NextHash: bFullData.NextHash,
StakeValidationHeight: exp.ChainParams.StakeValidationHeight,
}**/
exp.NewFullBlockData = newBlockData
// percentage := func(a float64, b float64) float64 {
// return (a / b) * 100
// }
FormattedBytes: humanize.Bytes(uint64(bData.Size)),
Revocations: uint32(bData.Revocations),
}
exp.NewBlockData = newBlockData
bdHeight := newBlockData.Height

stakePerc := blockData.PoolInfo.Value / dcrutil.Amount(blockData.ExtraInfo.CoinSupply).ToCoin()

Expand Down Expand Up @@ -463,6 +442,7 @@ func (exp *explorerUI) simulateASR(StartingDCRBalance float64, IntegerTicketQty
if exp.ChainParams.Name != "mainnet" {
return 0, ""
}

BlocksPerDay := 86400 / exp.ChainParams.TargetTimePerBlock.Seconds()
BlocksPerYear := 365 * BlocksPerDay
TicketsPurchased := float64(0)
Expand Down
4 changes: 2 additions & 2 deletions explorer/explorerroutes.go
Expand Up @@ -105,15 +105,15 @@ func (exp *explorerUI) SideChains(w http.ResponseWriter, r *http.Request) {
func (exp *explorerUI) NextHome(w http.ResponseWriter, r *http.Request) {
height := exp.blockData.GetHeight()

blocks := exp.blockData.GetExplorerFullBlocks(height, height-11)
blocks := exp.blockData.GetExplorerBlocks(height, height-11)

exp.NewBlockDataMtx.Lock()
exp.MempoolData.RLock()

str, err := exp.templates.execTemplateToString("nexthome", struct {
Info *HomeInfo
Mempool *MempoolInfo
Blocks []*BlockInfo
Blocks []*BlockBasic
Version string
NetName string
}{
Expand Down

0 comments on commit 375558d

Please sign in to comment.