Show first seen date of mempool transaction in explorer

This commit is contained in:
Martin Boehm 2019-04-03 14:08:36 +02:00
parent 47f798dbaa
commit b64d76d8f9
6 changed files with 27 additions and 16 deletions

View File

@ -294,6 +294,10 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
return nil, err return nil, err
} }
} }
// for mempool transaction get first seen time
if bchainTx.Confirmations == 0 {
bchainTx.Blocktime = int64(w.mempool.GetTransactionTime(bchainTx.Txid))
}
r := &Tx{ r := &Tx{
Blockhash: blockhash, Blockhash: blockhash,
Blockheight: int(height), Blockheight: int(height),

View File

@ -383,13 +383,13 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
return nil, err return nil, err
} }
// setup filtering of txids // setup filtering of txids
var useTxids func(txid *xpubTxid, ad *xpubAddress) bool var txidFilter func(txid *xpubTxid, ad *xpubAddress) bool
if !(filter.FromHeight == 0 && filter.ToHeight == 0 && filter.Vout == AddressFilterVoutOff) { if !(filter.FromHeight == 0 && filter.ToHeight == 0 && filter.Vout == AddressFilterVoutOff) {
toHeight := maxUint32 toHeight := maxUint32
if filter.ToHeight != 0 { if filter.ToHeight != 0 {
toHeight = filter.ToHeight toHeight = filter.ToHeight
} }
useTxids = func(txid *xpubTxid, ad *xpubAddress) bool { txidFilter = func(txid *xpubTxid, ad *xpubAddress) bool {
if txid.height < filter.FromHeight || txid.height > toHeight { if txid.height < filter.FromHeight || txid.height > toHeight {
return false return false
} }
@ -406,6 +406,7 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
// process mempool, only if ToHeight is not specified // process mempool, only if ToHeight is not specified
if filter.ToHeight == 0 && !filter.OnlyConfirmed { if filter.ToHeight == 0 && !filter.OnlyConfirmed {
txmMap = make(map[string]*Tx) txmMap = make(map[string]*Tx)
mempoolEntries := make(bchain.MempoolTxidEntries, 0)
for _, da := range [][]xpubAddress{data.addresses, data.changeAddresses} { for _, da := range [][]xpubAddress{data.addresses, data.changeAddresses} {
for i := range da { for i := range da {
ad := &da[i] ad := &da[i]
@ -432,18 +433,23 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
} }
uBalSat.Add(&uBalSat, tx.getAddrVoutValue(ad.addrDesc)) uBalSat.Add(&uBalSat, tx.getAddrVoutValue(ad.addrDesc))
uBalSat.Sub(&uBalSat, tx.getAddrVinValue(ad.addrDesc)) uBalSat.Sub(&uBalSat, tx.getAddrVinValue(ad.addrDesc))
if page == 0 && !foundTx && (useTxids == nil || useTxids(&txid, ad)) { // mempool txs are returned only on the first page, uniquely and filtered
if option == AccountDetailsTxidHistory { if page == 0 && !foundTx && (txidFilter == nil || txidFilter(&txid, ad)) {
txids = append(txids, tx.Txid) mempoolEntries = append(mempoolEntries, bchain.MempoolTxidEntry{Txid: txid.txid, Time: uint32(tx.Blocktime)})
} else if option >= AccountDetailsTxHistoryLight {
txs = append(txs, tx)
}
} }
} }
} }
} }
} }
// sort the entries by time descending
sort.Sort(mempoolEntries)
for _, entry := range mempoolEntries {
if option == AccountDetailsTxidHistory {
txids = append(txids, entry.Txid)
} else if option >= AccountDetailsTxHistoryLight {
txs = append(txs, txmMap[entry.Txid])
}
}
} }
if option >= AccountDetailsTxidHistory { if option >= AccountDetailsTxidHistory {
txcMap := make(map[string]bool) txcMap := make(map[string]bool)
@ -459,7 +465,7 @@ func (w *Worker) GetXpubAddress(xpub string, page int, txsOnPage int, option Acc
} }
// add tx only once // add tx only once
if !added { if !added {
add := useTxids == nil || useTxids(&txid, ad) add := txidFilter == nil || txidFilter(&txid, ad)
txcMap[txid.txid] = add txcMap[txid.txid] = add
if add { if add {
txc = append(txc, txid) txc = append(txc, txid)

View File

@ -316,3 +316,7 @@ func (c *mempoolWithMetrics) GetAllEntries() (v bchain.MempoolTxidEntries) {
defer func(s time.Time) { c.observeRPCLatency("GetAllEntries", s, nil) }(time.Now()) defer func(s time.Time) { c.observeRPCLatency("GetAllEntries", s, nil) }(time.Now())
return c.mempool.GetAllEntries() return c.mempool.GetAllEntries()
} }
func (c *mempoolWithMetrics) GetTransactionTime(txid string) uint32 {
return c.mempool.GetTransactionTime(txid)
}

View File

@ -291,4 +291,5 @@ type Mempool interface {
GetTransactions(address string) ([]Outpoint, error) GetTransactions(address string) ([]Outpoint, error)
GetAddrDescTransactions(addrDesc AddressDescriptor) ([]Outpoint, error) GetAddrDescTransactions(addrDesc AddressDescriptor) ([]Outpoint, error)
GetAllEntries() MempoolTxidEntries GetAllEntries() MempoolTxidEntries
GetTransactionTime(txid string) uint32
} }

View File

@ -4,9 +4,7 @@
<div class="col-xs-7 col-md-8 ellipsis"> <div class="col-xs-7 col-md-8 ellipsis">
<a href="/tx/{{$tx.Txid}}">{{$tx.Txid}}</a> <a href="/tx/{{$tx.Txid}}">{{$tx.Txid}}</a>
</div> </div>
{{- if $tx.Confirmations -}} <div class="col-xs-5 col-md-4 text-muted text-right">{{if $tx.Confirmations}}mined{{else}}first seen{{end}} {{formatUnixTime $tx.Blocktime}}</div>
<div class="col-xs-5 col-md-4 text-muted text-right">mined {{formatUnixTime $tx.Blocktime}}</div>
{{- end -}}
</div> </div>
<div class="row line-mid"> <div class="row line-mid">
<div class="col-md-5"> <div class="col-md-5">

View File

@ -5,9 +5,7 @@
<a href="/tx/{{$tx.Txid}}">{{$tx.Txid}}</a> <a href="/tx/{{$tx.Txid}}">{{$tx.Txid}}</a>
{{if eq $tx.EthereumSpecific.Status 1}}<span class="text-success"></span>{{end}}{{if eq $tx.EthereumSpecific.Status 0}}<span class="text-danger"></span>{{end}} {{if eq $tx.EthereumSpecific.Status 1}}<span class="text-success"></span>{{end}}{{if eq $tx.EthereumSpecific.Status 0}}<span class="text-danger"></span>{{end}}
</div> </div>
{{- if $tx.Confirmations -}} <div class="col-xs-5 col-md-4 text-muted text-right">{{if $tx.Confirmations}}mined{{else}}first seen{{end}} {{formatUnixTime $tx.Blocktime}}</div>
<div class="col-xs-5 col-md-4 text-muted text-right">mined {{formatUnixTime $tx.Blocktime}}</div>
{{- end -}}
</div> </div>
<div class="row line-mid"> <div class="row line-mid">
<div class="col-md-4"> <div class="col-md-4">