1
+ //! This module contains the logic for resolving signatures from
2
+ //! 4-byte function selector or a 32-byte event selector.
3
+
1
4
use std:: path:: PathBuf ;
2
5
3
6
use alloy_dyn_abi:: { DynSolType , DynSolValue } ;
@@ -19,16 +22,23 @@ use tracing::{debug, trace};
19
22
20
23
use super :: types:: DynSolValueExt ;
21
24
25
+ /// A resolved function signature. May contain decoded inputs.
22
26
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
23
27
pub struct ResolvedFunction {
28
+ /// The name of the function. For example, `transfer`.
24
29
pub name : String ,
30
+ /// The function signature. For example, `transfer(address,uint256)`.
25
31
pub signature : String ,
32
+ /// The inputs of the function. For example, `["address", "uint256"]`.
26
33
pub inputs : Vec < String > ,
34
+ /// The decoded inputs of the function. For example, `[DynSolValue::Address("0x1234"),
35
+ /// DynSolValue::Uint(123)]`.
27
36
#[ serde( skip) ]
28
37
pub decoded_inputs : Option < Vec < DynSolValue > > ,
29
38
}
30
39
31
40
impl ResolvedFunction {
41
+ /// Returns the inputs of the function as a vector of [`DynSolType`]s.
32
42
pub fn inputs ( & self ) -> Vec < DynSolType > {
33
43
parse_function_parameters ( & self . signature ) . expect ( "invalid signature" )
34
44
}
@@ -59,34 +69,45 @@ impl ResolvedFunction {
59
69
}
60
70
}
61
71
62
- #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
72
+ /// A resolved error signature.
73
+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
63
74
pub struct ResolvedError {
75
+ /// The name of the error. For example, `revert`.
64
76
pub name : String ,
77
+ /// The error signature. For example, `revert(string)`.
65
78
pub signature : String ,
79
+ /// The inputs of the error. For example, `["string"]`.
66
80
pub inputs : Vec < String > ,
67
81
}
68
82
69
83
impl ResolvedError {
84
+ /// Returns the inputs of the error as a vector of [`DynSolType`]s.
70
85
pub fn inputs ( & self ) -> Vec < DynSolType > {
71
86
parse_function_parameters ( & self . signature ) . expect ( "invalid signature" )
72
87
}
73
88
}
74
-
75
- #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
89
+ /// A resolved log signature.
90
+ #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
76
91
pub struct ResolvedLog {
92
+ /// The name of the log. For example, `Transfer`.
77
93
pub name : String ,
94
+ /// The log signature. For example, `Transfer(address,address,uint256)`.
78
95
pub signature : String ,
96
+ /// The inputs of the log. For example, `["address", "address", "uint256"]`.
79
97
pub inputs : Vec < String > ,
80
98
}
81
99
82
100
impl ResolvedLog {
101
+ /// Returns the inputs of the log as a vector of [`DynSolType`]s.
83
102
pub fn inputs ( & self ) -> Vec < DynSolType > {
84
103
parse_function_parameters ( & self . signature ) . expect ( "invalid signature" )
85
104
}
86
105
}
87
-
106
+ /// A trait for resolving a selector into a vector of [`ResolvedFunction`]s, [`ResolvedError`]s, or
88
107
#[ async_trait]
89
108
pub trait ResolveSelector {
109
+ /// Resolves a selector into a vector of [`ResolvedFunction`]s, [`ResolvedError`]s, or
110
+ /// [`ResolvedLog`]s.
90
111
async fn resolve ( selector : & str ) -> Result < Option < Vec < Self > > >
91
112
where
92
113
Self : Sized ;
@@ -356,6 +377,7 @@ pub fn cache_signatures_from_abi(path: PathBuf) -> Result<()> {
356
377
Ok ( ( ) )
357
378
}
358
379
380
+ /// Heuristic to score a function signature based on its spamminess.
359
381
pub fn score_signature ( signature : & str , num_words : Option < usize > ) -> u32 {
360
382
// the score starts at 1000
361
383
let mut score = 1000 ;
0 commit comments