Skip to content

Commit

Permalink
(BIDS-2535) adjusted to new contract detection
Browse files Browse the repository at this point in the history
  • Loading branch information
remoterami committed Nov 6, 2023
1 parent 2a50a61 commit 726cc0e
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 269 deletions.
37 changes: 20 additions & 17 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, search

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

// get a method label for its byte signature with defaults
func (bigtable *Bigtable) GetMethodLabel(data []byte, invokesContract bool, createsContract bool) string {
if createsContract {
return "Constructor"
}
if !invokesContract {
return "Transfer"
}

func (bigtable *Bigtable) GetMethodLabel(data []byte, interaction types.ContractInteractionType) string {
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)

switch interaction {
case types.CONTRACT_NONE:
return "Transfer"
case types.CONTRACT_CREATION:
return "Constructor"
case types.CONTRACT_DESTRUCTION:
case types.CONTRACT_PRESENT:
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)
}
}
}
}
default:
utils.LogError(nil, "unknown contract interaction type", 0, map[string]interface{}{"type": interaction})
}
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 @@ -178,16 +178,6 @@ func GetExecutionBlockPageData(number uint64, limit int) (*types.Eth1BlockPageDa
tx.To = tx.ContractAddress
}

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)
}
}

var isContractInteraction types.ContractInteractionType
if len(txIsContractList) > i {
isContractInteraction = txIsContractList[i]
Expand All @@ -203,7 +193,7 @@ func GetExecutionBlockPageData(number uint64, limit int) (*types.Eth1BlockPageDa
Value: new(big.Int).SetBytes(tx.Value),
Fee: txFee,
GasPrice: effectiveGasPrice,
Method: db.BigtableClient.GetMethodLabel(tx.GetData(), tx.InvokesContract, contractCreation),
Method: db.BigtableClient.GetMethodLabel(tx.GetData(), isContractInteraction),
})
}

Expand Down
2 changes: 1 addition & 1 deletion handlers/eth1Transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func getTransactionDataStartingWithPageToken(pageToken string) *types.DataTableR
}
tableData = append(tableData, []interface{}{
utils.FormatAddressWithLimits(v.GetHash(), "", false, "tx", visibleDigitsForHash+5, 18, true),
utils.FormatMethod(db.BigtableClient.GetMethodLabel(v.GetData(), v.GetInvokesContract(), v.GetTo() == nil)),
utils.FormatMethod(db.BigtableClient.GetMethodLabel(v.GetData(), isContractInteraction)),
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
Loading

0 comments on commit 726cc0e

Please sign in to comment.