Update display of contracts in explorer
This commit is contained in:
parent
922bdc42e5
commit
50602bcaae
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@ build/*.deb
|
||||
.bin-image
|
||||
.deb-image
|
||||
\.idea/
|
||||
__debug*
|
||||
@ -569,6 +569,27 @@ func (w *Worker) getContractDescriptorInfo(cd bchain.AddressDescriptor, typeFrom
|
||||
glog.Errorf("StoreContractInfo error %v, contract %v", err, cd)
|
||||
}
|
||||
}
|
||||
} else if (len(contractInfo.Name) > 0 && contractInfo.Name[0] == 0) || (len(contractInfo.Symbol) > 0 && contractInfo.Symbol[0] == 0) {
|
||||
// fix contract name/symbol that was parsed as a string consisting of zeroes
|
||||
blockchainContractInfo, err := w.chain.GetContractInfo(cd)
|
||||
if err != nil {
|
||||
glog.Errorf("GetContractInfo from chain error %v, contract %v", err, cd)
|
||||
} else {
|
||||
if len(blockchainContractInfo.Name) > 0 && blockchainContractInfo.Name[0] != 0 {
|
||||
contractInfo.Name = blockchainContractInfo.Name
|
||||
} else {
|
||||
contractInfo.Name = ""
|
||||
}
|
||||
if len(blockchainContractInfo.Symbol) > 0 && blockchainContractInfo.Symbol[0] != 0 {
|
||||
contractInfo.Symbol = blockchainContractInfo.Symbol
|
||||
} else {
|
||||
contractInfo.Symbol = ""
|
||||
}
|
||||
contractInfo.Decimals = blockchainContractInfo.Decimals
|
||||
if err = w.db.StoreContractInfo(contractInfo); err != nil {
|
||||
glog.Errorf("StoreContractInfo error %v, contract %v", err, cd)
|
||||
}
|
||||
}
|
||||
}
|
||||
return contractInfo, validContract, nil
|
||||
}
|
||||
@ -957,8 +978,10 @@ func (w *Worker) getEthereumTypeAddressBalances(addrDesc bchain.AddressDescripto
|
||||
totalResults = int(ca.TotalTxs)
|
||||
} else if filter.Vout == 0 {
|
||||
totalResults = int(ca.NonContractTxs)
|
||||
} else if filter.Vout > 0 && filter.Vout-1 < len(ca.Contracts) {
|
||||
totalResults = int(ca.Contracts[filter.Vout-1].Txs)
|
||||
} else if filter.Vout == db.InternalTxIndexOffset {
|
||||
totalResults = int(ca.InternalTxs)
|
||||
} else if filter.Vout >= db.ContractIndexOffset && filter.Vout-db.ContractIndexOffset < len(ca.Contracts) {
|
||||
totalResults = int(ca.Contracts[filter.Vout-db.ContractIndexOffset].Txs)
|
||||
} else if filter.Vout == AddressFilterVoutQueryNotNecessary {
|
||||
totalResults = 0
|
||||
}
|
||||
@ -972,16 +995,17 @@ func (w *Worker) getEthereumTypeAddressBalances(addrDesc bchain.AddressDescripto
|
||||
BalanceSat: *b,
|
||||
}
|
||||
}
|
||||
// special handling if filtering for a contract, check the ballance of it in the blockchain
|
||||
if len(filterDesc) > 0 && details >= AccountDetailsTokens {
|
||||
t, err := w.getEthereumContractBalanceFromBlockchain(addrDesc, filterDesc, details)
|
||||
if err != nil {
|
||||
return nil, nil, nil, 0, 0, 0, 0, err
|
||||
}
|
||||
tokens = []Token{*t}
|
||||
// switch off query for transactions, there are no transactions
|
||||
filter.Vout = AddressFilterVoutQueryNotNecessary
|
||||
}
|
||||
// special handling if filtering for a contract, return the contract details even though the address had no transactions with it
|
||||
if len(tokens) == 0 && len(filterDesc) > 0 && details >= AccountDetailsTokens {
|
||||
t, err := w.getEthereumContractBalanceFromBlockchain(addrDesc, filterDesc, details)
|
||||
if err != nil {
|
||||
return nil, nil, nil, 0, 0, 0, 0, err
|
||||
}
|
||||
tokens = []Token{*t}
|
||||
// switch off query for transactions, there are no transactions
|
||||
filter.Vout = AddressFilterVoutQueryNotNecessary
|
||||
totalResults = -1
|
||||
}
|
||||
return ba, tokens, ci, n, nonContractTxs, internalTxs, totalResults, nil
|
||||
}
|
||||
|
||||
@ -812,6 +812,10 @@ func (d *RocksDB) storeContractInfo(wb *grocksdb.WriteBatch, contractInfo *bchai
|
||||
contractInfo = storedCI
|
||||
}
|
||||
wb.PutCF(d.cfh[cfContracts], key, packContractInfo(contractInfo))
|
||||
cacheKey := string(key)
|
||||
cachedContractsMux.Lock()
|
||||
delete(cachedContracts, cacheKey)
|
||||
cachedContractsMux.Unlock()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
||||
{{define "specific"}}{{$cs := .CoinShortcut}}{{$addr := .Address}}{{$data := .}}
|
||||
<h1>{{if $addr.ContractInfo}}Contract {{$addr.ContractInfo.Name}} ({{$addr.ContractInfo.Symbol}}){{else}}Address{{end}} <small class="text-muted">{{formatAmount $addr.BalanceSat}} {{$cs}}</small>
|
||||
<h1>{{if $addr.ContractInfo}}Contract {{$addr.ContractInfo.Name}}{{if $addr.ContractInfo.Symbol}} ({{$addr.ContractInfo.Symbol}}){{end}}{{else}}Address{{end}} <small class="text-muted">{{formatAmount $addr.BalanceSat}} {{$cs}}</small>
|
||||
</h1>
|
||||
<div class="alert alert-data ellipsis">
|
||||
<span class="data">{{$addr.AddrStr}}</span>
|
||||
@ -10,6 +10,26 @@
|
||||
<table class="table data-table">
|
||||
<tbody>
|
||||
{{- if eq .ChainType 1 -}}
|
||||
{{if $addr.ContractInfo}}
|
||||
{{if $addr.ContractInfo.Type}}
|
||||
<tr>
|
||||
<td style="width: 25%;">Contract type</td>
|
||||
<td class="data">{{$addr.ContractInfo.Type}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
{{if $addr.ContractInfo.CreatedInBlock}}
|
||||
<tr>
|
||||
<td style="width: 25%;">Created in Block</td>
|
||||
<td class="data"><a href="/block/{{$addr.ContractInfo.CreatedInBlock}}">{{$addr.ContractInfo.CreatedInBlock}}</a></td>
|
||||
</tr>
|
||||
{{end}}
|
||||
{{if $addr.ContractInfo.DestructedInBlock}}
|
||||
<tr>
|
||||
<td style="width: 25%;">Destructed in Block</td>
|
||||
<td class="data"><a href="/block/{{$addr.ContractInfo.DestructedInBlock}}">{{$addr.ContractInfo.DestructedInBlock}}</a></td>
|
||||
</tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<tr>
|
||||
<td style="width: 25%;">Balance</td>
|
||||
<td class="data">{{formatAmount $addr.BalanceSat}} {{$cs}}</td>
|
||||
@ -158,19 +178,31 @@
|
||||
{{- end}}{{if or $addr.Transactions $addr.Filter -}}
|
||||
<div class="row h-container">
|
||||
<h3 class="col-md-3">Transactions</h3>
|
||||
<select class="col-md-2" style="background-color: #eaeaea;" onchange="self.location='?filter='+options[selectedIndex].value">
|
||||
<select class="col-md-3" style="background-color: #eaeaea;" onchange="self.location='?filter='+options[selectedIndex].value">
|
||||
<option>All</option>
|
||||
<option {{if eq $addr.Filter "inputs" -}} selected{{end}} value="inputs">Address on input side</option>
|
||||
<option {{if eq $addr.Filter "outputs" -}} selected{{end}} value="outputs">Address on output side</option>
|
||||
<option {{if eq $addr.Filter "inputs" -}}selected{{end}} value="inputs">Address on input side</option>
|
||||
<option {{if eq $addr.Filter "outputs" -}}selected{{end}} value="outputs">Address on output side</option>
|
||||
{{- if $addr.Tokens -}}
|
||||
<option {{if eq $addr.Filter "0" -}} selected{{end}} value="0">Non-contract</option>
|
||||
<option {{if eq $addr.Filter "0" -}} selected{{end}} value="1">Internal</option>
|
||||
<option {{if eq $addr.Filter "0" -}}selected{{end}} value="0">Non-contract</option>
|
||||
<option {{if eq $addr.Filter "1" -}}selected{{end}} value="1">Internal</option>
|
||||
{{- range $t := $addr.Tokens -}}
|
||||
<option {{if eq $addr.Filter $t.ContractIndex -}} selected{{end}} value="{{$t.ContractIndex}}">{{$t.Name}}</option>
|
||||
{{if eq $t.Type "ERC20"}}
|
||||
<option {{if eq $addr.Filter $t.ContractIndex -}}selected{{end}} value="{{$t.ContractIndex}}">{{if $t.Name}}{{$t.Name}}{{else}}{{$t.Contract}}{{end}} (ERC20)</option>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- range $t := $addr.Tokens -}}
|
||||
{{if eq $t.Type "ERC721"}}
|
||||
<option {{if eq $addr.Filter $t.ContractIndex -}}selected{{end}} value="{{$t.ContractIndex}}">{{if $t.Name}}{{$t.Name}}{{else}}{{$t.Contract}}{{end}} (ERC721)</option>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- range $t := $addr.Tokens -}}
|
||||
{{if eq $t.Type "ERC1155"}}
|
||||
<option {{if eq $addr.Filter $t.ContractIndex -}}selected{{end}} value="{{$t.ContractIndex}}">{{if $t.Name}}{{$t.Name}}{{else}}{{$t.Contract}}{{end}} (ERC1155)</option>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</select>
|
||||
<div class="col-md-7">
|
||||
<div class="col-md-6">
|
||||
<nav>{{template "paging" $data}}</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user