Skip to content

Commit

Permalink
(BIDS-2636) applied currency conversion, dynamic itx counter label
Browse files Browse the repository at this point in the history
  • Loading branch information
remoterami committed Jan 17, 2024
1 parent 0dce0f9 commit 0704d04
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
7 changes: 2 additions & 5 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2472,7 +2472,7 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, pageToken
return data, nil
}

func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte, from []byte, parityTrace []*rpc.ParityTraceResult) ([]types.ITransaction, error) {
func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte, from []byte, parityTrace []*rpc.ParityTraceResult, currency string) ([]types.ITransaction, error) {
getTraceInfo := func(trace *rpc.ParityTraceResult) ([]byte, []byte, []byte, string) {
var from, to, value []byte
tx_type := trace.Type
Expand Down Expand Up @@ -2511,9 +2511,6 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
data := make([]types.ITransaction, 0, len(parityTrace)-1)
for i := 1; i < len(parityTrace); i++ {
from, to, value, tx_type := getTraceInfo(parityTrace[i])
if string(value) == "\x00" {
continue
}
if tx_type == "suicide" {
// erigon's "suicide" might be misleading for users
tx_type = "selfdestruct"
Expand All @@ -2530,7 +2527,7 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
itx := types.ITransaction{
From: utils.FormatAddress(from, nil, fromName, false, false, true),
To: utils.FormatAddress(to, nil, toName, false, false, true),
Amount: utils.FormatBytesAmount(value, utils.Config.Frontend.ElCurrency, 8),
Amount: utils.FormatElCurrency(value, currency, 8, true, false, false, true),
TracePath: utils.FormatTracePath(tx_type, parityTrace[i].TraceAddress, parityTrace[i].Error == "", bigtable.GetMethodLabel(input, true)),
Advanced: tx_type == "delegatecall" || string(value) == "\x00",
}
Expand Down
4 changes: 2 additions & 2 deletions eth1data/eth1data.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
var logger = logrus.New().WithField("module", "eth1data")
var ErrTxIsPending = errors.New("error retrieving data for tx: tx is still pending")

func GetEth1Transaction(hash common.Hash) (*types.Eth1TxData, error) {
func GetEth1Transaction(hash common.Hash, currency string) (*types.Eth1TxData, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

Expand Down Expand Up @@ -150,7 +150,7 @@ func GetEth1Transaction(hash common.Hash) (*types.Eth1TxData, error) {
return nil, fmt.Errorf("error loading token transfers from tx: %w", err)
}
}
txPageData.InternalTxns, err = db.BigtableClient.GetInternalTransfersForTransaction(tx.Hash().Bytes(), msg.From.Bytes(), data)
txPageData.InternalTxns, err = db.BigtableClient.GetInternalTransfersForTransaction(tx.Hash().Bytes(), msg.From.Bytes(), data, currency)
if err != nil {
return nil, fmt.Errorf("error loading internal transfers from tx: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions handlers/eth1tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Eth1TransactionTx(w http.ResponseWriter, r *http.Request) {
data = InitPageData(w, r, "blockchain", path, title, txNotFoundTemplateFiles)
txTemplate = txNotFoundTemplate
} else {
txData, err := eth1data.GetEth1Transaction(common.BytesToHash(txHash))
txData, err := eth1data.GetEth1Transaction(common.BytesToHash(txHash), "ETH")
if err != nil {
mempool := services.LatestMempoolTransactions()
mempoolTx := mempool.FindTxByHash(txHashString)
Expand Down Expand Up @@ -130,21 +130,21 @@ func Eth1TransactionTxData(w http.ResponseWriter, r *http.Request) {

vars := mux.Vars(r)
txHashString := vars["hash"]
err := json.NewEncoder(w).Encode(getEth1TransactionTxData(txHashString))
currency := GetCurrency(r)
err := json.NewEncoder(w).Encode(getEth1TransactionTxData(txHashString, currency))
if err != nil {
logger.Errorf("error enconding json response for %v route: %v", r.URL.String(), err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
}

func getEth1TransactionTxData(txhash string) *types.DataTableResponse {
func getEth1TransactionTxData(txhash, currency string) *types.DataTableResponse {
tableData := make([][]interface{}, 0, minimumTransactionsPerUpdate)

txHash, err := hex.DecodeString(strings.ReplaceAll(txhash, "0x", ""))
if err != nil {
logger.Warnf("error parsing tx hash %v: %v", txhash, err)
} else {
txData, err := eth1data.GetEth1Transaction(common.BytesToHash(txHash))
txData, err := eth1data.GetEth1Transaction(common.BytesToHash(txHash), currency)
its := txData.InternalTxns
if err != nil {
fmt.Println("hello")
Expand Down
20 changes: 15 additions & 5 deletions templates/eth1tx.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,24 @@
function filterItransactions(show) {
if (show) {
$('#itransactions').DataTable()
.column(0)
.search("")
.column(3)
.search("")
.draw()
} else {
regExSearch = '^(?!' + `0 ETH` + '$).*$';
// all but exact match would be:
//regExSearch = '^(?!' + `0 ETH` + '$).*$'
noZeroValue = '^(?!' + '0 ' + ')'
noDelegateCall = '^(?!' + 'delegatecall' + ')'
$('#itransactions').DataTable()
.column(0)
.search(noDelegateCall, true, false)
.column(3)
.search(regExSearch, true, false)
.search(noZeroValue, true, false)
.draw()
}
$('#itxCountLabel').text($('#itransactions').DataTable().rows( {search:'applied'} ).count());
}

$("#advanced-itx-toggle").on("click", async () => {
Expand All @@ -66,10 +74,12 @@
ordering: false,
searching: true,
ajax: dataTableLoader('/tx/' + hash + '/data'),
dom: 'lrtip'
dom: 'lrtip',
initComplete: function(settings, json) {
filterItransactions(false)
}
}
$('#itransactions').DataTable(tblOpts)
filterItransactions(false)
})
</script>
{{ end }}
Expand Down Expand Up @@ -118,7 +128,7 @@ <h1 class="h4 mb-1 mb-md-0">
{{ if gt (len .InternalTxns) 0 }}
<li class="nav-item">
<a class="nav-link" id="internal-txns-tab" data-toggle="tab" href="#internal-txns" role="tab" aria-controls="internal-txns" aria-selected="false">
<i class="fas fa-sitemap"></i><span class="tab-text" style="margin-left: 6px;">Internal Transactions <span class="badge badge-dark align-middle text-white">{{ len .InternalTxns }}</span></span>
<i class="fas fa-sitemap"></i><span class="tab-text" style="margin-left: 6px;">Internal Transactions <span class="badge badge-dark align-middle text-white" id="itxCountLabel"></span></span>
</a>
</li>
{{ end }}
Expand Down
3 changes: 3 additions & 0 deletions utils/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ func formatCurrencyString(valIf interface{}, valueCurrency, targetCurrency strin
// add trailing zeros to always have the same amount of digits after the comma
dotIndex := strings.Index(valStr, ".")
if dotIndex >= 0 {
if !strings.HasSuffix(amountStr, ".") {
amountStr += "."
}
missingZeros := digitsAfterComma - (len(amountStr) - dotIndex - 1)
if missingZeros > 0 {
amountStr += strings.Repeat("0", missingZeros)
Expand Down

0 comments on commit 0704d04

Please sign in to comment.