@@ -108,6 +108,7 @@ impl MultiSolMacroGen {
108
108
bindings_path : & Path ,
109
109
single_file : bool ,
110
110
alloy_version : Option < String > ,
111
+ alloy_rev : Option < String > ,
111
112
) -> Result < ( ) > {
112
113
self . generate_bindings ( ) ?;
113
114
@@ -127,13 +128,7 @@ edition = "2021"
127
128
"#
128
129
) ;
129
130
130
- let alloy_dep = if let Some ( alloy_version) = alloy_version {
131
- format ! (
132
- r#"alloy = {{ git = "https://github.com/alloy-rs/alloy", rev = "{alloy_version}", features = ["sol-types", "contract"] }}"#
133
- )
134
- } else {
135
- r#"alloy = { git = "https://github.com/alloy-rs/alloy", features = ["sol-types", "contract"] }"# . to_string ( )
136
- } ;
131
+ let alloy_dep = Self :: get_alloy_dep ( alloy_version, alloy_rev) ;
137
132
write ! ( toml_contents, "{alloy_dep}" ) ?;
138
133
139
134
fs:: write ( cargo_toml_path, toml_contents) . wrap_err ( "Failed to write Cargo.toml" ) ?;
@@ -235,9 +230,10 @@ edition = "2021"
235
230
check_cargo_toml : bool ,
236
231
is_mod : bool ,
237
232
alloy_version : Option < String > ,
233
+ alloy_rev : Option < String > ,
238
234
) -> Result < ( ) > {
239
235
if check_cargo_toml {
240
- self . check_cargo_toml ( name, version, crate_path, alloy_version) ?;
236
+ self . check_cargo_toml ( name, version, crate_path, alloy_version, alloy_rev ) ?;
241
237
}
242
238
243
239
let mut super_contents = String :: new ( ) ;
@@ -304,6 +300,7 @@ edition = "2021"
304
300
version : & str ,
305
301
crate_path : & Path ,
306
302
alloy_version : Option < String > ,
303
+ alloy_rev : Option < String > ,
307
304
) -> Result < ( ) > {
308
305
eyre:: ensure!( crate_path. is_dir( ) , "Crate path must be a directory" ) ;
309
306
@@ -315,13 +312,7 @@ edition = "2021"
315
312
316
313
let name_check = format ! ( "name = \" {name}\" " ) ;
317
314
let version_check = format ! ( "version = \" {version}\" " ) ;
318
- let alloy_dep_check = if let Some ( version) = alloy_version {
319
- format ! (
320
- r#"alloy = {{ git = "https://github.com/alloy-rs/alloy", rev = "{version}", features = ["sol-types", "contract"] }}"# ,
321
- )
322
- } else {
323
- r#"alloy = { git = "https://github.com/alloy-rs/alloy", features = ["sol-types", "contract"] }"# . to_string ( )
324
- } ;
315
+ let alloy_dep_check = Self :: get_alloy_dep ( alloy_version, alloy_rev) ;
325
316
let toml_consistent = cargo_toml_contents. contains ( & name_check) &&
326
317
cargo_toml_contents. contains ( & version_check) &&
327
318
cargo_toml_contents. contains ( & alloy_dep_check) ;
@@ -333,6 +324,23 @@ edition = "2021"
333
324
334
325
Ok ( ( ) )
335
326
}
327
+
328
+ /// Returns the `alloy` dependency string for the Cargo.toml file.
329
+ /// If `alloy_version` is provided, it will use that version from crates.io.
330
+ /// If `alloy_rev` is provided, it will use that revision from the GitHub repository.
331
+ fn get_alloy_dep ( alloy_version : Option < String > , alloy_rev : Option < String > ) -> String {
332
+ if let Some ( alloy_version) = alloy_version {
333
+ format ! (
334
+ r#"alloy = {{ version = "{alloy_version}", features = ["sol-types", "contract"] }}"# ,
335
+ )
336
+ } else if let Some ( alloy_rev) = alloy_rev {
337
+ format ! (
338
+ r#"alloy = {{ git = "https://github.com/alloy-rs/alloy", rev = "{alloy_rev}", features = ["sol-types", "contract"] }}"# ,
339
+ )
340
+ } else {
341
+ r#"alloy = { git = "https://github.com/alloy-rs/alloy", features = ["sol-types", "contract"] }"# . to_string ( )
342
+ }
343
+ }
336
344
}
337
345
338
346
fn write_mod_name ( contents : & mut String , name : & str ) -> Result < ( ) > {
0 commit comments