Skip to content

Commit

Permalink
Update display of contracts in explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboehm committed Feb 1, 2023
1 parent 922bdc4 commit 50602bc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build/*.deb
.bin-image
.deb-image
\.idea/
__debug*
46 changes: 35 additions & 11 deletions api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions db/rocksdb_ethereumtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions server/public_ethereumtype_test.go

Large diffs are not rendered by default.

48 changes: 40 additions & 8 deletions static/templates/address.html
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -10,6 +10,26 @@ <h3>Confirmed</h3>
<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>
Expand Down Expand Up @@ -158,19 +178,31 @@ <h3>Unconfirmed</h3>
{{- 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>
Expand Down

0 comments on commit 50602bc

Please sign in to comment.