@@ -15,6 +15,7 @@ use eyre::{Context, OptionExt, Result};
15
15
use foundry_common:: fs;
16
16
use proc_macro2:: { Span , TokenStream } ;
17
17
use std:: {
18
+ env:: temp_dir,
18
19
fmt:: Write ,
19
20
path:: { Path , PathBuf } ,
20
21
str:: FromStr ,
@@ -82,7 +83,37 @@ impl MultiSolMacroGen {
82
83
}
83
84
84
85
fn generate_binding ( instance : & mut SolMacroGen , all_derives : bool ) -> Result < ( ) > {
85
- let input = instance. get_sol_input ( ) ?. normalize_json ( ) ?;
86
+ // TODO: in `get_sol_input` we currently can't handle unlinked bytecode: <https://github.com/alloy-rs/core/issues/926>
87
+ let input = match instance. get_sol_input ( ) {
88
+ Ok ( input) => input. normalize_json ( ) ?,
89
+ Err ( error) => {
90
+ // TODO(mattsse): remove after <https://github.com/alloy-rs/core/issues/926>
91
+ if error. to_string ( ) . contains ( "expected bytecode, found unlinked bytecode" ) {
92
+ // we attempt to do a little hack here until we have this properly supported by
93
+ // removing the bytecode objects from the json file and using a tmpfile (very
94
+ // hacky)
95
+ let content = std:: fs:: read_to_string ( & instance. path ) ?;
96
+ let mut value = serde_json:: from_str :: < serde_json:: Value > ( & content) ?;
97
+ let obj = value. as_object_mut ( ) . expect ( "valid abi" ) ;
98
+
99
+ // clear unlinked bytecode
100
+ obj. remove ( "bytecode" ) ;
101
+ obj. remove ( "deployedBytecode" ) ;
102
+
103
+ let tmpdir = temp_dir ( ) ;
104
+ let mut tmp_file = tmpdir. join ( instance. path . file_name ( ) . unwrap ( ) ) ;
105
+ std:: fs:: write ( & tmp_file, serde_json:: to_string ( & value) ?) ?;
106
+
107
+ // try again
108
+ std:: mem:: swap ( & mut tmp_file, & mut instance. path ) ;
109
+ let input = instance. get_sol_input ( ) ?. normalize_json ( ) ?;
110
+ std:: mem:: swap ( & mut tmp_file, & mut instance. path ) ;
111
+ input. normalize_json ( ) ?
112
+ } else {
113
+ return Err ( error)
114
+ }
115
+ }
116
+ } ;
86
117
87
118
let SolInput { attrs : _, path : _, kind } = input;
88
119
0 commit comments