Skip to content

Commit

Permalink
(BIDS-2535) unified method name determination
Browse files Browse the repository at this point in the history
  • Loading branch information
remoterami committed Oct 18, 2023
1 parent 22b055c commit 929fbe8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
40 changes: 22 additions & 18 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2149,11 +2149,9 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, search
from := utils.FormatAddress(t.From, nil, fromName, false, false, !bytes.Equal(t.From, address))
to := utils.FormatAddress(t.To, nil, toName, false, t.IsContractCreation || t.InvokesContract, !bytes.Equal(t.To, address))

method := bigtable.GetMethodLabel(t.MethodId, t.InvokesContract)

tableData[i] = []interface{}{
utils.FormatTransactionHash(t.Hash),
utils.FormatMethod(method),
utils.FormatMethod(bigtable.GetMethodLabel(t.MethodId, t.InvokesContract, t.IsContractCreation)),
utils.FormatBlockNumber(t.BlockNumber),
utils.FormatTimestamp(t.Time.AsTime().Unix()),
from,
Expand Down Expand Up @@ -4169,23 +4167,29 @@ func (bigtable *Bigtable) GetSignature(hex string, st types.SignatureType) (*str
}

// get a method label for its byte signature with defaults
func (bigtable *Bigtable) GetMethodLabel(id []byte, invokesContract bool) string {
method := "Transfer"
if len(id) > 0 {
if invokesContract {
method = fmt.Sprintf("0x%x", id)
cacheKey := fmt.Sprintf("M:H2L:%s", method)
if _, err := cache.TieredCache.GetWithLocalTimeout(cacheKey, time.Hour, &method); err != nil {
sig, err := bigtable.GetSignature(method, types.MethodSignature)
if err == nil {
if sig != nil {
method = utils.RemoveRoundBracketsIncludingContent(*sig)
}
cache.TieredCache.Set(cacheKey, method, time.Hour)
func (bigtable *Bigtable) GetMethodLabel(data []byte, invokesContract bool, createsContract bool) string {
if createsContract {
return "Constructor"
}
if !invokesContract {
return "Transfer"
}

id := data
if len(data) > 3 {
id = data[:4]
}

method := fmt.Sprintf("0x%x", id)
if len(id) == 4 {
cacheKey := fmt.Sprintf("M:H2L:%s", method)
if _, err := cache.TieredCache.GetWithLocalTimeout(cacheKey, time.Hour, &method); err != nil {
if sig, err := bigtable.GetSignature(method, types.MethodSignature); err == nil {
cache.TieredCache.Set(cacheKey, method, time.Hour)
if sig != nil {
return utils.RemoveRoundBracketsIncludingContent(*sig)
}
}
} else {
method = "Transfer*"
}
}
return method
Expand Down
12 changes: 1 addition & 11 deletions handlers/eth1Block.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,6 @@ func GetExecutionBlockPageData(number uint64, limit int) (*types.Eth1BlockPageDa
names[string(tx.To)] = "Contract Creation"
}

method := "Transfer"
{
d := tx.GetData()
if len(d) > 3 {
m := d[:4]
invokesContract := len(tx.GetItx()) > 0 || tx.GetGasUsed() > 21000 || tx.GetErrorMsg() != ""
method = db.BigtableClient.GetMethodLabel(m, invokesContract)
}
}

txs = append(txs, types.Eth1BlockPageTransaction{
Hash: fmt.Sprintf("%#x", tx.Hash),
HashFormatted: utils.FormatAddressWithLimits(tx.Hash, "", false, "tx", 15, 18, true),
Expand All @@ -193,7 +183,7 @@ func GetExecutionBlockPageData(number uint64, limit int) (*types.Eth1BlockPageDa
Value: new(big.Int).SetBytes(tx.Value),
Fee: txFee,
GasPrice: effectiveGasPrice,
Method: method,
Method: db.BigtableClient.GetMethodLabel(tx.GetData(), tx.InvokesContract, contractCreation),
})
}

Expand Down
11 changes: 1 addition & 10 deletions handlers/eth1Transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,13 @@ func getTransactionDataStartingWithPageToken(pageToken string) *types.DataTableR
var wg errgroup.Group
for _, v := range t {
wg.Go(func() error {
method := "Transfer"
{
d := v.GetData()
if len(d) > 3 {
m := d[:4]
invokesContract := len(v.GetItx()) > 0 || v.GetGasUsed() > 21000 || v.GetErrorMsg() != ""
method = db.BigtableClient.GetMethodLabel(m, invokesContract)
}
}
if v.GetTo() == nil {
v.To = v.ContractAddress
names[string(v.To)] = "Contract Creation"
}
tableData = append(tableData, []interface{}{
utils.FormatAddressWithLimits(v.GetHash(), "", false, "tx", visibleDigitsForHash+5, 18, true),
utils.FormatMethod(method),
utils.FormatMethod(db.BigtableClient.GetMethodLabel(v.GetData(), v.GetInvokesContract(), v.GetTo() == nil)),
template.HTML(fmt.Sprintf(`<A href="block/%d">%v</A>`, b.GetNumber(), utils.FormatAddCommas(b.GetNumber()))),
utils.FormatTimestamp(b.GetTime().AsTime().Unix()),
utils.FormatAddressWithLimits(v.GetFrom(), names[string(v.GetFrom())], false, "address", visibleDigitsForHash+5, 18, true),
Expand Down

0 comments on commit 929fbe8

Please sign in to comment.