@@ -19,6 +19,7 @@ use clarity::vm::representations::CONTRACT_PRINCIPAL_REGEX_STRING;
19
19
use lazy_static:: lazy_static;
20
20
use regex:: { Captures , Regex } ;
21
21
use stacks_common:: types:: net:: PeerHost ;
22
+ use stacks_common:: types:: chainstate:: TrieHash ;
22
23
use stacks_common:: util:: hash:: to_hex;
23
24
24
25
use crate :: net:: http:: {
@@ -31,17 +32,6 @@ use crate::net::httpcore::{
31
32
} ;
32
33
use crate :: net:: { Error as NetError , StacksNodeState , TipRequest } ;
33
34
34
- lazy_static ! {
35
- static ref CLARITY_NAME_NO_BOUNDARIES_REGEX_STRING : String =
36
- "[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*|[-+=/*]|[<>]=?" . into( ) ;
37
- static ref MARF_KEY_FOR_TRIP_REGEX_STRING : String = format!(
38
- r"vm::{}::\d+::({})" ,
39
- * CONTRACT_PRINCIPAL_REGEX_STRING , * CLARITY_NAME_NO_BOUNDARIES_REGEX_STRING ,
40
- ) ;
41
- static ref MARF_KEY_FOR_QUAD_REGEX_STRING : String =
42
- format!( r"{}::[0-9a-fA-F]+" , * MARF_KEY_FOR_TRIP_REGEX_STRING , ) ;
43
- }
44
-
45
35
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
46
36
pub struct ClarityMarfResponse {
47
37
pub data : String ,
@@ -53,12 +43,12 @@ pub struct ClarityMarfResponse {
53
43
54
44
#[ derive( Clone ) ]
55
45
pub struct RPCGetClarityMarfRequestHandler {
56
- pub clarity_marf_key : Option < String > ,
46
+ pub marf_key_hash : Option < TrieHash > ,
57
47
}
58
48
impl RPCGetClarityMarfRequestHandler {
59
49
pub fn new ( ) -> Self {
60
50
Self {
61
- clarity_marf_key : None ,
51
+ marf_key_hash : None ,
62
52
}
63
53
}
64
54
}
@@ -70,15 +60,11 @@ impl HttpRequest for RPCGetClarityMarfRequestHandler {
70
60
}
71
61
72
62
fn path_regex ( & self ) -> Regex {
73
- Regex :: new ( & format ! (
74
- r"^/v2/clarity/marf/(?P<clarity_marf_key>(vm-epoch::epoch-version)|({})|({}))$" ,
75
- * MARF_KEY_FOR_TRIP_REGEX_STRING , * MARF_KEY_FOR_QUAD_REGEX_STRING
76
- ) )
77
- . unwrap ( )
63
+ Regex :: new ( r#"^/v2/clarity/marf/(?P<marf_key_hash>[0-9a-f]{64})$"# ) . unwrap ( )
78
64
}
79
65
80
66
fn metrics_identifier ( & self ) -> & str {
81
- "/v2/clarity/marf/:clarity_marf_key "
67
+ "/v2/clarity/marf/:marf_key_hash "
82
68
}
83
69
84
70
/// Try to decode this request.
@@ -96,13 +82,14 @@ impl HttpRequest for RPCGetClarityMarfRequestHandler {
96
82
) ) ;
97
83
}
98
84
99
- let marf_key = if let Some ( key_str) = captures. name ( "clarity_marf_key" ) {
100
- key_str. as_str ( ) . to_string ( )
85
+ let marf_key = if let Some ( key_str) = captures. name ( "marf_key_hash" ) {
86
+ TrieHash :: from_hex ( key_str. as_str ( ) )
87
+ . map_err ( |e| Error :: Http ( 400 , format ! ( "Invalid hash string: {e:?}" ) ) ) ?
101
88
} else {
102
- return Err ( Error :: Http ( 404 , "Missing `clarity_marf_key `" . to_string ( ) ) ) ;
89
+ return Err ( Error :: Http ( 404 , "Missing `marf_key_hash `" . to_string ( ) ) ) ;
103
90
} ;
104
91
105
- self . clarity_marf_key = Some ( marf_key) ;
92
+ self . marf_key_hash = Some ( marf_key) ;
106
93
107
94
let contents = HttpRequestContents :: new ( ) . query_string ( query) ;
108
95
Ok ( contents)
@@ -113,7 +100,7 @@ impl HttpRequest for RPCGetClarityMarfRequestHandler {
113
100
impl RPCRequestHandler for RPCGetClarityMarfRequestHandler {
114
101
/// Reset internal state
115
102
fn restart ( & mut self ) {
116
- self . clarity_marf_key = None ;
103
+ self . marf_key_hash = None ;
117
104
}
118
105
119
106
/// Make the response
@@ -123,8 +110,8 @@ impl RPCRequestHandler for RPCGetClarityMarfRequestHandler {
123
110
contents : HttpRequestContents ,
124
111
node : & mut StacksNodeState ,
125
112
) -> Result < ( HttpResponsePreamble , HttpResponseContents ) , NetError > {
126
- let clarity_marf_key = self . clarity_marf_key . take ( ) . ok_or ( NetError :: SendError (
127
- "`clarity_marf_key ` not set" . to_string ( ) ,
113
+ let marf_key_hash = self . marf_key_hash . take ( ) . ok_or ( NetError :: SendError (
114
+ "`marf_key_hash ` not set" . to_string ( ) ,
128
115
) ) ?;
129
116
130
117
let tip = match node. load_stacks_chain_tip ( & preamble, & contents) {
@@ -144,13 +131,13 @@ impl RPCRequestHandler for RPCGetClarityMarfRequestHandler {
144
131
clarity_tx. with_clarity_db_readonly ( |clarity_db| {
145
132
let ( value_hex, marf_proof) : ( String , _ ) = if with_proof {
146
133
clarity_db
147
- . get_data_with_proof ( & clarity_marf_key )
134
+ . get_data_with_proof_by_hash ( & marf_key_hash )
148
135
. ok ( )
149
136
. flatten ( )
150
137
. map ( |( a, b) | ( a, Some ( format ! ( "0x{}" , to_hex( & b) ) ) ) ) ?
151
138
} else {
152
139
clarity_db
153
- . get_data ( & clarity_marf_key )
140
+ . get_data_by_hash ( & marf_key_hash )
154
141
. ok ( )
155
142
. flatten ( )
156
143
. map ( |a| ( a, None ) ) ?
@@ -168,7 +155,7 @@ impl RPCRequestHandler for RPCGetClarityMarfRequestHandler {
168
155
Ok ( Some ( None ) ) => {
169
156
return StacksHttpResponse :: new_error (
170
157
& preamble,
171
- & HttpNotFound :: new ( "Marf key not found" . to_string ( ) ) ,
158
+ & HttpNotFound :: new ( "Marf key hash not found" . to_string ( ) ) ,
172
159
)
173
160
. try_into_contents ( )
174
161
. map_err ( NetError :: from) ;
@@ -205,14 +192,14 @@ impl HttpResponse for RPCGetClarityMarfRequestHandler {
205
192
impl StacksHttpRequest {
206
193
pub fn new_getclaritymarf (
207
194
host : PeerHost ,
208
- clarity_marf_key : String ,
195
+ marf_key_hash : TrieHash ,
209
196
tip_req : TipRequest ,
210
197
with_proof : bool ,
211
198
) -> StacksHttpRequest {
212
199
StacksHttpRequest :: new_for_peer (
213
200
host,
214
201
"GET" . into ( ) ,
215
- format ! ( "/v2/clarity/marf/{}" , & clarity_marf_key ) ,
202
+ format ! ( "/v2/clarity/marf/{}" , & marf_key_hash ) ,
216
203
HttpRequestContents :: new ( )
217
204
. for_tip ( tip_req)
218
205
. query_arg ( "proof" . into ( ) , if with_proof { "1" } else { "0" } . into ( ) ) ,
0 commit comments