@@ -2018,7 +2018,7 @@ func (bigtable *Bigtable) TransformWithdrawals(block *types.Eth1Block, cache *fr
2018
2018
return bulkData , bulkMetadataUpdates , nil
2019
2019
}
2020
2020
2021
- func (bigtable * Bigtable ) GetEth1TxForAddress (prefix string , limit int64 ) ([]* types.Eth1TransactionIndexed , string , error ) {
2021
+ func (bigtable * Bigtable ) GetEth1TxForAddress (prefix string , limit int64 ) ([]* types.Eth1TransactionIndexed , [] string , error ) {
2022
2022
2023
2023
tmr := time .AfterFunc (REPORT_TIMEOUT , func () {
2024
2024
logger .WithFields (logrus.Fields {
@@ -2044,11 +2044,11 @@ func (bigtable *Bigtable) GetEth1TxForAddress(prefix string, limit int64) ([]*ty
2044
2044
return true
2045
2045
}, gcp_bigtable .LimitRows (limit ))
2046
2046
if err != nil {
2047
- return nil , "" , err
2047
+ return nil , nil , err
2048
2048
}
2049
2049
2050
2050
if len (keys ) == 0 {
2051
- return data , "" , nil
2051
+ return data , nil , nil
2052
2052
}
2053
2053
2054
2054
err = bigtable .tableData .ReadRows (ctx , gcp_bigtable .RowList (keys ), func (row gcp_bigtable.Row ) bool {
@@ -2064,7 +2064,7 @@ func (bigtable *Bigtable) GetEth1TxForAddress(prefix string, limit int64) ([]*ty
2064
2064
})
2065
2065
if err != nil {
2066
2066
logger .WithError (err ).WithField ("prefix" , prefix ).WithField ("limit" , limit ).Errorf ("error reading rows in bigtable_eth1 / GetEth1TxForAddress" )
2067
- return nil , "" , err
2067
+ return nil , nil , err
2068
2068
}
2069
2069
2070
2070
for _ , key := range keys {
@@ -2073,7 +2073,7 @@ func (bigtable *Bigtable) GetEth1TxForAddress(prefix string, limit int64) ([]*ty
2073
2073
}
2074
2074
}
2075
2075
2076
- return data , indexes [ len ( indexes ) - 1 ] , nil
2076
+ return data , indexes , nil
2077
2077
}
2078
2078
2079
2079
func (bigtable * Bigtable ) GetAddressesNamesArMetadata (names * map [string ]string , inputMetadata * map [string ]* types.ERC20Metadata ) (map [string ]string , map [string ]* types.ERC20Metadata , error ) {
@@ -2171,12 +2171,26 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, search
2171
2171
pageToken = fmt .Sprintf ("%s:I:TX:%x:%s:" , bigtable .chainId , address , FILTER_TIME )
2172
2172
}
2173
2173
2174
- transactions , lastKey , err := BigtableClient .GetEth1TxForAddress (pageToken , 25 )
2174
+ transactions , keys , err := BigtableClient .GetEth1TxForAddress (pageToken , 25 )
2175
2175
if err != nil {
2176
2176
return nil , err
2177
2177
}
2178
2178
2179
- txIsContractList , err := BigtableClient .GetAddressIsContractAtTransactions (transactions )
2179
+ idxs := make ([]int64 , len (keys ))
2180
+ for i , k := range keys {
2181
+ tx_idx , err := strconv .Atoi (strings .Split (k , ":" )[6 ])
2182
+ if err != nil {
2183
+ return nil , fmt .Errorf ("error parsing Eth1InternalTransactionIndexed tx index: %v" , err )
2184
+ }
2185
+ tx_idx = 10000 - tx_idx
2186
+ if tx_idx < 0 {
2187
+ return nil , fmt .Errorf ("invalid Eth1InternalTransactionIndexed tx index: %d" , tx_idx )
2188
+ }
2189
+
2190
+ idxs [i ] = int64 (tx_idx )
2191
+ }
2192
+
2193
+ txIsContractList , err := BigtableClient .GetAddressIsContractAtTransactions (transactions , idxs )
2180
2194
if err != nil {
2181
2195
utils .LogError (err , "error getting contract states" , 0 )
2182
2196
}
@@ -2195,17 +2209,13 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, search
2195
2209
tableData := make ([][]interface {}, len (transactions ))
2196
2210
for i , t := range transactions {
2197
2211
fromName := names [string (t .From )]
2198
- toName := names [string (t .To )]
2199
- if t .IsContractCreation {
2200
- toName = "Contract Creation"
2201
- }
2202
2212
var isContractInteraction types.ContractInteractionType
2203
2213
if len (txIsContractList ) > i {
2204
2214
isContractInteraction = txIsContractList [i ]
2205
2215
}
2206
2216
2207
2217
from := utils .FormatAddress (t .From , nil , fromName , false , false , ! bytes .Equal (t .From , address ))
2208
- to := utils .FormatAddress (t .To , nil , toName , false , isContractInteraction != types .CONTRACT_NONE , ! bytes .Equal (t .To , address ))
2218
+ to := utils .FormatAddress (t .To , nil , BigtableClient . GetAddressLabel ( names [ string ( t . To )], isContractInteraction ) , false , isContractInteraction != types .CONTRACT_NONE , ! bytes .Equal (t .To , address ))
2209
2219
2210
2220
method := bigtable .GetMethodLabel (t .MethodId , isContractInteraction != types .CONTRACT_NONE )
2211
2221
@@ -2221,9 +2231,14 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, search
2221
2231
}
2222
2232
}
2223
2233
2234
+ token := ""
2235
+ if len (keys ) > 0 {
2236
+ token = keys [len (keys )- 1 ]
2237
+ }
2238
+
2224
2239
data := & types.DataTableResponse {
2225
2240
Data : tableData ,
2226
- PagingToken : lastKey ,
2241
+ PagingToken : token ,
2227
2242
}
2228
2243
2229
2244
return data , nil
@@ -2529,7 +2544,7 @@ func (bigtable *Bigtable) GetAddressBlobTableData(address []byte, search string,
2529
2544
return data , nil
2530
2545
}
2531
2546
2532
- func (bigtable * Bigtable ) GetEth1ItxForAddress (prefix string , limit int64 ) ([]* types.Eth1InternalTransactionIndexed , string , error ) {
2547
+ func (bigtable * Bigtable ) GetEth1ItxForAddress (prefix string , limit int64 ) ([]* types.Eth1InternalTransactionIndexed , [] string , error ) {
2533
2548
2534
2549
tmr := time .AfterFunc (REPORT_TIMEOUT , func () {
2535
2550
logger .WithFields (logrus.Fields {
@@ -2556,10 +2571,10 @@ func (bigtable *Bigtable) GetEth1ItxForAddress(prefix string, limit int64) ([]*t
2556
2571
return true
2557
2572
}, gcp_bigtable .LimitRows (limit ))
2558
2573
if err != nil {
2559
- return nil , "" , err
2574
+ return nil , nil , err
2560
2575
}
2561
2576
if len (keys ) == 0 {
2562
- return data , "" , nil
2577
+ return data , nil , nil
2563
2578
}
2564
2579
2565
2580
err = bigtable .tableData .ReadRows (ctx , gcp_bigtable .RowList (keys ), func (row gcp_bigtable.Row ) bool {
@@ -2579,7 +2594,7 @@ func (bigtable *Bigtable) GetEth1ItxForAddress(prefix string, limit int64) ([]*t
2579
2594
})
2580
2595
if err != nil {
2581
2596
logger .WithError (err ).WithField ("prefix" , prefix ).WithField ("limit" , limit ).Errorf ("error reading rows in bigtable_eth1 / GetEth1ItxForAddress" )
2582
- return nil , "" , err
2597
+ return nil , nil , err
2583
2598
}
2584
2599
2585
2600
for _ , key := range keys {
@@ -2588,7 +2603,7 @@ func (bigtable *Bigtable) GetEth1ItxForAddress(prefix string, limit int64) ([]*t
2588
2603
}
2589
2604
}
2590
2605
2591
- return data , indexes [ len ( indexes ) - 1 ] , nil
2606
+ return data , indexes , nil
2592
2607
}
2593
2608
2594
2609
func (bigtable * Bigtable ) GetAddressInternalTableData (address []byte , search string , pageToken string ) (* types.DataTableResponse , error ) {
@@ -2607,7 +2622,7 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, search str
2607
2622
pageToken = fmt .Sprintf ("%s:I:ITX:%x:%s:" , bigtable .chainId , address , FILTER_TIME )
2608
2623
}
2609
2624
2610
- transactions , lastKey , err := bigtable .GetEth1ItxForAddress (pageToken , 25 )
2625
+ transactions , keys , err := bigtable .GetEth1ItxForAddress (pageToken , 25 )
2611
2626
if err != nil {
2612
2627
return nil , err
2613
2628
}
@@ -2622,14 +2637,46 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, search str
2622
2637
return nil , err
2623
2638
}
2624
2639
2640
+ idxs := make ([][2 ]int64 , len (keys ))
2641
+ for i , k := range keys {
2642
+ tx_idx , err := strconv .Atoi (strings .Split (k , ":" )[6 ])
2643
+ if err != nil {
2644
+ return nil , fmt .Errorf ("error parsing Eth1InternalTransactionIndexed tx index: %v" , err )
2645
+ }
2646
+ tx_idx = 10000 - tx_idx
2647
+ if tx_idx < 0 {
2648
+ return nil , fmt .Errorf ("invalid Eth1InternalTransactionIndexed tx index: %d" , tx_idx )
2649
+ }
2650
+
2651
+ trace_idx , err := strconv .Atoi (strings .Split (k , ":" )[7 ])
2652
+ if err != nil {
2653
+ return nil , fmt .Errorf ("error parsing Eth1InternalTransactionIndexed trace index: %v" , err )
2654
+ }
2655
+ trace_idx = 100000 - trace_idx
2656
+ if tx_idx < 0 {
2657
+ return nil , fmt .Errorf ("invalid Eth1InternalTransactionIndexed trace index: %d" , trace_idx )
2658
+ }
2659
+ idxs [i ] = [2 ]int64 {int64 (tx_idx ), int64 (trace_idx )}
2660
+ }
2661
+ txIsContractList , err := BigtableClient .GetAddressIsContractAtTransaction (transactions , idxs )
2662
+ if err != nil {
2663
+ utils .LogError (err , "error getting contract states" , 0 )
2664
+ }
2665
+
2625
2666
tableData := make ([][]interface {}, len (transactions ))
2626
2667
for i , t := range transactions {
2627
2668
2628
2669
fromName := names [string (t .From )]
2629
2670
toName := names [string (t .To )]
2630
2671
2631
- from := utils .FormatAddress (t .From , nil , fromName , false , false , ! bytes .Equal (t .From , address ))
2632
- to := utils .FormatAddress (t .To , nil , toName , false , false , ! bytes .Equal (t .To , address ))
2672
+ var from_invokesContract , to_invokesContract types.ContractInteractionType
2673
+ if len (txIsContractList ) > i {
2674
+ from_invokesContract = txIsContractList [i ][0 ]
2675
+ to_invokesContract = txIsContractList [i ][1 ]
2676
+ }
2677
+
2678
+ from := utils .FormatAddress (t .From , nil , BigtableClient .GetAddressLabel (fromName , from_invokesContract ), false , from_invokesContract != types .CONTRACT_NONE , ! bytes .Equal (t .From , address ))
2679
+ to := utils .FormatAddress (t .To , nil , BigtableClient .GetAddressLabel (toName , to_invokesContract ), false , to_invokesContract != types .CONTRACT_NONE , ! bytes .Equal (t .To , address ))
2633
2680
2634
2681
tableData [i ] = []interface {}{
2635
2682
utils .FormatTransactionHash (t .ParentHash ),
@@ -2643,9 +2690,14 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, search str
2643
2690
}
2644
2691
}
2645
2692
2693
+ token := ""
2694
+ if len (keys ) > 0 {
2695
+ token = keys [len (keys )- 1 ]
2696
+ }
2697
+
2646
2698
data := & types.DataTableResponse {
2647
2699
Data : tableData ,
2648
- PagingToken : lastKey ,
2700
+ PagingToken : token ,
2649
2701
}
2650
2702
2651
2703
return data , nil
@@ -2713,12 +2765,16 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
2713
2765
2714
2766
// sort by event id
2715
2767
keys := make ([]int , 0 , len (transfers ))
2716
- for k := range transfers {
2768
+ itransactions := make ([]* types.Eth1InternalTransactionIndexed , 0 , len (transfers ))
2769
+ idxs := make ([][2 ]int64 , 0 , len (transfers ))
2770
+ for k , v := range transfers {
2717
2771
keys = append (keys , k )
2772
+ itransactions = append (itransactions , v )
2773
+ idxs = append (idxs , [2 ]int64 {int64 (txIdx ), int64 (k )})
2718
2774
}
2719
2775
sort .Ints (keys )
2720
2776
2721
- txIsContractList , err := BigtableClient .GetAddressIsContractAtTransaction (transfers , txIdx )
2777
+ txIsContractList , err := BigtableClient .GetAddressIsContractAtTransaction (itransactions , idxs )
2722
2778
if err != nil {
2723
2779
utils .LogError (err , "error getting contract states" , 0 )
2724
2780
}
@@ -2727,15 +2783,13 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
2727
2783
t := transfers [k ]
2728
2784
2729
2785
var from_invokesContract , to_invokesContract types.ContractInteractionType
2730
- if val , ok := txIsContractList [ k ]; ok {
2731
- from_invokesContract = val [0 ]
2732
- to_invokesContract = val [1 ]
2786
+ if len ( txIsContractList ) > 0 {
2787
+ from_invokesContract = txIsContractList [ i ] [0 ]
2788
+ to_invokesContract = txIsContractList [ i ] [1 ]
2733
2789
}
2734
2790
2735
- fromName := names [string (t .From )]
2736
- toName := names [string (t .To )]
2737
- from := utils .FormatAddress (t .From , nil , fromName , false , from_invokesContract != types .CONTRACT_NONE , true )
2738
- to := utils .FormatAddress (t .To , nil , toName , false , to_invokesContract != types .CONTRACT_NONE , true )
2791
+ from := utils .FormatAddress (t .From , nil , BigtableClient .GetAddressLabel (names [string (t .From )], from_invokesContract ), false , from_invokesContract != types .CONTRACT_NONE , true )
2792
+ to := utils .FormatAddress (t .To , nil , BigtableClient .GetAddressLabel (names [string (t .To )], to_invokesContract ), false , to_invokesContract != types .CONTRACT_NONE , true )
2739
2793
2740
2794
data [i ] = types.Transfer {
2741
2795
From : from ,
@@ -3802,45 +3856,44 @@ func (bigtable *Bigtable) GetAddressIsContractAtBlock(block *types.Eth1Block) ([
3802
3856
}
3803
3857
3804
3858
// convenience function to get contract interaction status per subtransaction of a transaction
3805
- // assumes all internal transactions belong to the same tx
3806
- func (bigtable * Bigtable ) GetAddressIsContractAtTransaction (itransactions map [ int ]* types.Eth1InternalTransactionIndexed , tx_idx uint ) (map [ int ][2 ]types.ContractInteractionType , error ) {
3859
+ // 2nd parameter specifies [tx_idx, trace_idx] for each internal tx
3860
+ func (bigtable * Bigtable ) GetAddressIsContractAtTransaction (itransactions [ ]* types.Eth1InternalTransactionIndexed , idxs [][ 2 ] int64 ) ([ ][2 ]types.ContractInteractionType , error ) {
3807
3861
requests := make ([]isContractAtRequest , 0 , len (itransactions )* 2 )
3808
3862
for i , tx := range itransactions {
3809
3863
requests = append (requests , isContractAtRequest {
3810
3864
address : fmt .Sprintf ("%x" , tx .GetFrom ()),
3811
3865
block : int64 (tx .GetBlockNumber ()),
3812
- txIdx : int64 ( tx_idx ) ,
3813
- traceIdx : int64 ( i ) ,
3866
+ txIdx : idxs [ i ][ 0 ] ,
3867
+ traceIdx : idxs [ i ][ 1 ] ,
3814
3868
})
3815
3869
requests = append (requests , isContractAtRequest {
3816
3870
address : fmt .Sprintf ("%x" , tx .GetTo ()),
3817
3871
block : int64 (tx .GetBlockNumber ()),
3818
- txIdx : int64 ( tx_idx ) ,
3819
- traceIdx : int64 ( i ) ,
3872
+ txIdx : idxs [ i ][ 0 ] ,
3873
+ traceIdx : idxs [ i ][ 1 ] ,
3820
3874
})
3821
3875
}
3822
3876
results , err := bigtable .GetAddressIsContractAt (requests )
3823
3877
if err != nil {
3824
3878
return nil , err
3825
3879
}
3826
- resultMap := make (map [int ][2 ]types.ContractInteractionType )
3827
- i := 0
3828
- for key := range itransactions {
3829
- resultMap [key ] = [2 ]types.ContractInteractionType {results [i * 2 ], results [i * 2 + 1 ]}
3830
- i ++
3880
+
3881
+ resultPairs := make ([][2 ]types.ContractInteractionType , len (itransactions ))
3882
+ for i , v := range results {
3883
+ resultPairs [i / 2 ][i % 2 ] = v
3831
3884
}
3832
- return resultMap , nil
3885
+ return resultPairs , nil
3833
3886
}
3834
3887
3835
3888
// convenience function to get contract interaction status per transaction
3836
- func (bigtable * Bigtable ) GetAddressIsContractAtTransactions (transactions []* types.Eth1TransactionIndexed ) ([]types.ContractInteractionType , error ) {
3889
+ func (bigtable * Bigtable ) GetAddressIsContractAtTransactions (transactions []* types.Eth1TransactionIndexed , idxs [] int64 ) ([]types.ContractInteractionType , error ) {
3837
3890
requests := make ([]isContractAtRequest , len (transactions ))
3838
3891
for i , tx := range transactions {
3839
3892
requests [i ] = isContractAtRequest {
3840
- address : fmt .Sprintf ("%x" , tx .GetTo ()),
3841
- block : int64 (tx .GetBlockNumber ()),
3842
- // unfortunately we don't know the tx index (without querying it for each tx first)
3843
- txIdx : int64 ( - 1 ) ,
3893
+ address : fmt .Sprintf ("%x" , tx .GetTo ()),
3894
+ block : int64 (tx .GetBlockNumber ()),
3895
+ txIdx : idxs [ i ],
3896
+ traceIdx : - 1 ,
3844
3897
}
3845
3898
}
3846
3899
return bigtable .GetAddressIsContractAt (requests )
@@ -4423,6 +4476,18 @@ func (bigtable *Bigtable) GetMethodLabel(id []byte, invokesContract bool) string
4423
4476
return method
4424
4477
}
4425
4478
4479
+ // get a method label for its byte signature with defaults
4480
+ func (bigtable * Bigtable ) GetAddressLabel (id string , invoke_overwrite types.ContractInteractionType ) string {
4481
+ switch invoke_overwrite {
4482
+ case types .CONTRACT_CREATION :
4483
+ return "Contract Creation"
4484
+ case types .CONTRACT_DESTRUCTION :
4485
+ return "Contract Destruction"
4486
+ default :
4487
+ return id
4488
+ }
4489
+ }
4490
+
4426
4491
// get an event label for its byte signature with defaults
4427
4492
func (bigtable * Bigtable ) GetEventLabel (id []byte ) string {
4428
4493
label := ""
0 commit comments