1
1
use anyhow:: { anyhow, Error } ;
2
2
use anyhow:: { ensure, Context } ;
3
+ use graph:: abi;
4
+ use graph:: abi:: EventExt ;
5
+ use graph:: abi:: FunctionExt ;
3
6
use graph:: blockchain:: { BlockPtr , TriggerWithHandler } ;
4
7
use graph:: components:: metrics:: subgraph:: SubgraphInstanceMetrics ;
5
8
use graph:: components:: store:: { EthereumCallCache , StoredDynamicDataSource } ;
@@ -13,8 +16,8 @@ use graph::env::ENV_VARS;
13
16
use graph:: futures03:: future:: try_join;
14
17
use graph:: futures03:: stream:: FuturesOrdered ;
15
18
use graph:: futures03:: TryStreamExt ;
16
- use graph:: prelude:: ethabi :: ethereum_types :: H160 ;
17
- use graph:: prelude:: ethabi :: StateMutability ;
19
+ use graph:: prelude:: web3 :: types :: Address ;
20
+ use graph:: prelude:: web3 :: types :: H160 ;
18
21
use graph:: prelude:: { Link , SubgraphManifestValidationError } ;
19
22
use graph:: slog:: { debug, error, o, trace} ;
20
23
use itertools:: Itertools ;
@@ -30,9 +33,7 @@ use tiny_keccak::{keccak256, Keccak};
30
33
use graph:: {
31
34
blockchain:: { self , Blockchain } ,
32
35
prelude:: {
33
- async_trait,
34
- ethabi:: { Address , Event , Function , LogParam , ParamType , RawLog } ,
35
- serde_json, warn,
36
+ async_trait, serde_json, warn,
36
37
web3:: types:: { Log , Transaction , H256 } ,
37
38
BlockNumber , CheapClone , EthereumCall , LightEthereumBlock , LightEthereumBlockExt ,
38
39
LinkResolver , Logger ,
@@ -525,28 +526,28 @@ impl DataSource {
525
526
}
526
527
}
527
528
528
- /// Returns the contract event with the given signature, if it exists. A an event from the ABI
529
+ /// Returns the contract event with the given signature, if it exists. An event from the ABI
529
530
/// will be matched if:
530
531
/// 1. An event signature is equal to `signature`.
531
532
/// 2. There are no equal matches, but there is exactly one event that equals `signature` if all
532
533
/// `indexed` modifiers are removed from the parameters.
533
- fn contract_event_with_signature ( & self , signature : & str ) -> Option < & Event > {
534
+ fn contract_event_with_signature ( & self , signature : & str ) -> Option < & abi :: Event > {
534
535
// Returns an `Event(uint256,address)` signature for an event, without `indexed` hints.
535
- fn ambiguous_event_signature ( event : & Event ) -> String {
536
+ fn ambiguous_event_signature ( event : & abi :: Event ) -> String {
536
537
format ! (
537
538
"{}({})" ,
538
539
event. name,
539
540
event
540
541
. inputs
541
542
. iter( )
542
- . map( |input| event_param_type_signature ( & input. kind ) )
543
+ . map( |input| input. selector_type ( ) . into_owned ( ) )
543
544
. collect:: <Vec <_>>( )
544
545
. join( "," )
545
546
)
546
547
}
547
548
548
549
// Returns an `Event(indexed uint256,address)` type signature for an event.
549
- fn event_signature ( event : & Event ) -> String {
550
+ fn event_signature ( event : & abi :: Event ) -> String {
550
551
format ! (
551
552
"{}({})" ,
552
553
event. name,
@@ -556,40 +557,13 @@ impl DataSource {
556
557
. map( |input| format!(
557
558
"{}{}" ,
558
559
if input. indexed { "indexed " } else { "" } ,
559
- event_param_type_signature ( & input. kind )
560
+ input. selector_type ( )
560
561
) )
561
562
. collect:: <Vec <_>>( )
562
563
. join( "," )
563
564
)
564
565
}
565
566
566
- // Returns the signature of an event parameter type (e.g. `uint256`).
567
- fn event_param_type_signature ( kind : & ParamType ) -> String {
568
- use ParamType :: * ;
569
-
570
- match kind {
571
- Address => "address" . into ( ) ,
572
- Bytes => "bytes" . into ( ) ,
573
- Int ( size) => format ! ( "int{}" , size) ,
574
- Uint ( size) => format ! ( "uint{}" , size) ,
575
- Bool => "bool" . into ( ) ,
576
- String => "string" . into ( ) ,
577
- Array ( inner) => format ! ( "{}[]" , event_param_type_signature( inner) ) ,
578
- FixedBytes ( size) => format ! ( "bytes{}" , size) ,
579
- FixedArray ( inner, size) => {
580
- format ! ( "{}[{}]" , event_param_type_signature( inner) , size)
581
- }
582
- Tuple ( components) => format ! (
583
- "({})" ,
584
- components
585
- . iter( )
586
- . map( event_param_type_signature)
587
- . collect:: <Vec <_>>( )
588
- . join( "," )
589
- ) ,
590
- }
591
- }
592
-
593
567
self . contract_abi
594
568
. contract
595
569
. events ( )
@@ -628,7 +602,9 @@ impl DataSource {
628
602
} )
629
603
}
630
604
631
- fn contract_function_with_signature ( & self , target_signature : & str ) -> Option < & Function > {
605
+ fn contract_function_with_signature ( & self , target_signature : & str ) -> Option < & abi:: Function > {
606
+ use abi:: StateMutability ;
607
+
632
608
self . contract_abi
633
609
. contract
634
610
. functions ( )
@@ -642,7 +618,7 @@ impl DataSource {
642
618
let mut arguments = function
643
619
. inputs
644
620
. iter ( )
645
- . map ( |input| format ! ( "{}" , input. kind ) )
621
+ . map ( |input| input. selector_type ( ) . into_owned ( ) )
646
622
. collect :: < Vec < String > > ( )
647
623
. join ( "," ) ;
648
624
// `address,uint256,bool)
@@ -732,11 +708,7 @@ impl DataSource {
732
708
. into_iter ( )
733
709
. filter_map ( |( event_handler, event_abi) | {
734
710
event_abi
735
- . parse_log ( RawLog {
736
- topics : log. topics . clone ( ) ,
737
- data : log. data . clone ( ) . 0 ,
738
- } )
739
- . map ( |log| log. params )
711
+ . decode_log ( & log)
740
712
. map_err ( |e| {
741
713
trace ! (
742
714
logger,
@@ -841,20 +813,15 @@ impl DataSource {
841
813
)
842
814
} ) ?;
843
815
844
- // Parse the inputs
845
- //
846
- // Take the input for the call, chop off the first 4 bytes, then call
847
- // `function.decode_input` to get a vector of `Token`s. Match the `Token`s
848
- // with the `Param`s in `function.inputs` to create a `Vec<LogParam>`.
849
- let tokens = match function_abi. decode_input ( & call. input . 0 [ 4 ..] ) . with_context (
850
- || {
816
+ let values = match function_abi
817
+ . abi_decode_input ( & call. input . 0 [ 4 ..] )
818
+ . with_context ( || {
851
819
format ! (
852
820
"Generating function inputs for the call {:?} failed, raw input: {}" ,
853
821
& function_abi,
854
822
hex:: encode( & call. input. 0 )
855
823
)
856
- } ,
857
- ) {
824
+ } ) {
858
825
Ok ( val) => val,
859
826
// See also 280b0108-a96e-4738-bb37-60ce11eeb5bf
860
827
Err ( err) => {
@@ -864,27 +831,22 @@ impl DataSource {
864
831
} ;
865
832
866
833
ensure ! (
867
- tokens . len( ) == function_abi. inputs. len( ) ,
834
+ values . len( ) == function_abi. inputs. len( ) ,
868
835
"Number of arguments in call does not match \
869
836
number of inputs in function signature."
870
837
) ;
871
838
872
- let inputs = tokens
839
+ let inputs = values
873
840
. into_iter ( )
874
841
. enumerate ( )
875
- . map ( |( i, token ) | LogParam {
842
+ . map ( |( i, value ) | abi :: DynSolParam {
876
843
name : function_abi. inputs [ i] . name . clone ( ) ,
877
- value : token ,
844
+ value,
878
845
} )
879
846
. collect :: < Vec < _ > > ( ) ;
880
847
881
- // Parse the outputs
882
- //
883
- // Take the output for the call, then call `function.decode_output` to
884
- // get a vector of `Token`s. Match the `Token`s with the `Param`s in
885
- // `function.outputs` to create a `Vec<LogParam>`.
886
- let tokens = function_abi
887
- . decode_output ( & call. output . 0 )
848
+ let values = function_abi
849
+ . abi_decode_output ( & call. output . 0 )
888
850
. with_context ( || {
889
851
format ! (
890
852
"Decoding function outputs for the call {:?} failed, raw output: {}" ,
@@ -894,17 +856,17 @@ impl DataSource {
894
856
} ) ?;
895
857
896
858
ensure ! (
897
- tokens . len( ) == function_abi. outputs. len( ) ,
859
+ values . len( ) == function_abi. outputs. len( ) ,
898
860
"Number of parameters in the call output does not match \
899
861
number of outputs in the function signature."
900
862
) ;
901
863
902
- let outputs = tokens
864
+ let outputs = values
903
865
. into_iter ( )
904
866
. enumerate ( )
905
- . map ( |( i, token ) | LogParam {
867
+ . map ( |( i, value ) | abi :: DynSolParam {
906
868
name : function_abi. outputs [ i] . name . clone ( ) ,
907
- value : token ,
869
+ value,
908
870
} )
909
871
. collect :: < Vec < _ > > ( ) ;
910
872
0 commit comments