Skip to content

Commit

Permalink
(BIDS-2535) added default methods based on contract state (#2830)
Browse files Browse the repository at this point in the history
* (BIDS-2535) added default methods based on contract state

* (BIDS-2535) fixed method name in cache
  • Loading branch information
remoterami authored Feb 6, 2024
1 parent 9d21f02 commit d8389ee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 47 deletions.
48 changes: 22 additions & 26 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -2238,10 +2238,6 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, pageTo
if err != nil {
return nil, fmt.Errorf("error parsing Eth1InternalTransactionIndexed tx index: %v", err)
}
if tx_idx == TX_PER_BLOCK_LIMIT {
// handle "reversePaddedIndex 0"-issue
tx_idx = 0
}
tx_idx = TX_PER_BLOCK_LIMIT - tx_idx
if tx_idx < 0 {
return nil, fmt.Errorf("invalid Eth1InternalTransactionIndexed tx index: %d", tx_idx)
Expand Down Expand Up @@ -2273,11 +2269,10 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, pageTo
if len(contractInteractionTypes) > i {
contractInteraction = contractInteractionTypes[i]
}
method := bigtable.GetMethodLabel(t.MethodId, contractInteraction != types.CONTRACT_NONE)

tableData[i] = []interface{}{
utils.FormatTransactionHash(t.Hash, t.ErrorMsg == ""),
utils.FormatMethod(method),
utils.FormatMethod(bigtable.GetMethodLabel(t.MethodId, contractInteraction)),
utils.FormatBlockNumber(t.BlockNumber),
utils.FormatTimestamp(t.Time.AsTime().Unix()),
utils.FormatAddressWithLimitsInAddressPageTable(address, t.From, fromName, false, digitLimitInAddressPagesTable, nameLimitInAddressPagesTable, true),
Expand Down Expand Up @@ -2666,7 +2661,6 @@ func (bigtable *Bigtable) GetEth1ItxsForAddress(prefix string, limit int64) ([]*
}
}

indexes[len(indexes)-1] = skipBlockIfLastTxIndex(indexes[len(indexes)-1])
return data, indexes, nil
}

Expand Down Expand Up @@ -2706,10 +2700,6 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, pageToken
if err != nil {
return nil, fmt.Errorf("error parsing Eth1InternalTransactionIndexed tx index: %v", err)
}
if tx_idx == TX_PER_BLOCK_LIMIT {
// handle "reversePaddedIndex 0"-issue
tx_idx = 0
}
tx_idx = TX_PER_BLOCK_LIMIT - tx_idx
if tx_idx < 0 {
return nil, fmt.Errorf("invalid Eth1InternalTransactionIndexed tx index: %d", tx_idx)
Expand All @@ -2719,10 +2709,6 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, pageToken
if err != nil {
return nil, fmt.Errorf("error parsing Eth1InternalTransactionIndexed trace index: %v", err)
}
if trace_idx == ITX_PER_TX_LIMIT {
// handle "reversePaddedIndex 0"-issue
trace_idx = 0
}
trace_idx = ITX_PER_TX_LIMIT - trace_idx
if tx_idx < 0 {
return nil, fmt.Errorf("invalid Eth1InternalTransactionIndexed trace index: %d", trace_idx)
Expand Down Expand Up @@ -2817,13 +2803,13 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
}

fromName := BigtableClient.GetAddressLabel(names[string(from)], from_contractInteraction)
toName := BigtableClient.GetAddressLabel(names[string(to)], from_contractInteraction)
toName := BigtableClient.GetAddressLabel(names[string(to)], to_contractInteraction)

itx := types.ITransaction{
From: utils.FormatAddress(from, nil, fromName, false, from_contractInteraction != types.CONTRACT_NONE, true),
To: utils.FormatAddress(to, nil, toName, false, to_contractInteraction != types.CONTRACT_NONE, true),
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)),
TracePath: utils.FormatTracePath(tx_type, parityTrace[i].TraceAddress, parityTrace[i].Error == "", bigtable.GetMethodLabel(input, from_contractInteraction)),
Advanced: tx_type == "delegatecall" || string(value) == "\x00",
}

Expand Down Expand Up @@ -4593,24 +4579,34 @@ 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)
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)

switch interaction {
case types.CONTRACT_NONE:
return "Transfer"
case types.CONTRACT_CREATION:
return "Constructor"
case types.CONTRACT_DESTRUCTION:
return "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 {
sig, err := bigtable.GetSignature(method, types.MethodSignature)
if err == nil {
if sig, err := bigtable.GetSignature(method, types.MethodSignature); err == nil {
if sig != nil {
method = utils.RemoveRoundBracketsIncludingContent(*sig)
}
cache.TieredCache.Set(cacheKey, method, time.Hour)
}
}
} else {
method = "Transfer*"
}
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 @@ -183,16 +183,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 contractInteraction types.ContractInteractionType
if len(contractInteractionTypes) > i {
contractInteraction = contractInteractionTypes[i]
Expand All @@ -208,7 +198,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(), contractInteraction),
})
}

Expand Down
11 changes: 1 addition & 10 deletions handlers/eth1Transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ func getTransactionDataStartingWithPageToken(pageToken string) *types.DataTableR
for i := len(t) - 1; i >= 0; i-- {
v := t[i]
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
}
Expand All @@ -108,7 +99,7 @@ func getTransactionDataStartingWithPageToken(pageToken string) *types.DataTableR
}
tableData = append(tableData, []interface{}{
utils.FormatAddressWithLimits(v.GetHash(), "", false, "tx", visibleDigitsForHash+5, 18, true),
utils.FormatMethod(method),
utils.FormatMethod(db.BigtableClient.GetMethodLabel(v.GetData(), contractInteraction)),
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 d8389ee

Please sign in to comment.