@@ -26,6 +26,12 @@ pub(crate) struct Env {
2626 help = "Proxy `/content/INSCRIPTION_ID` and other recursive endpoints to `<PROXY>` if the inscription is not present on current chain."
2727 ) ]
2828 pub ( crate ) proxy : Option < Url > ,
29+ #[ arg(
30+ long,
31+ help = "Path to ord binary to run." ,
32+ value_name = "PATH"
33+ ) ]
34+ ord_bin : Option < PathBuf > ,
2935}
3036
3137#[ derive( Serialize ) ]
@@ -38,6 +44,8 @@ struct Info {
3844
3945impl Env {
4046 pub ( crate ) fn run ( self ) -> SubcommandResult {
47+ let ord = self . resolve_ord_bin ( ) ?;
48+
4149 let bitcoind_port = TcpListener :: bind ( "127.0.0.1:9000" )
4250 . ok ( )
4351 . map ( |listener| listener. local_addr ( ) . unwrap ( ) . port ( ) ) ;
@@ -134,8 +142,6 @@ rpcport={bitcoind_port}
134142 ) ?;
135143 }
136144
137- let ord = std:: env:: current_exe ( ) ?;
138-
139145 let decompress = self . decompress ;
140146 let proxy = self . proxy . map ( |url| url. to_string ( ) ) ;
141147
@@ -209,7 +215,7 @@ rpcport={bitcoind_port}
209215 ord_port,
210216 bitcoin_cli_command : vec ! [ "bitcoin-cli" . into( ) , format!( "-datadir={relative}" ) ] ,
211217 ord_wallet_command : vec ! [
212- ord. to_str ( ) . unwrap ( ) . into( ) ,
218+ ord. to_string_lossy ( ) . into( ) ,
213219 "--datadir" . into( ) ,
214220 absolute. to_str( ) . unwrap( ) . into( ) ,
215221 "wallet" . into( ) ,
@@ -247,4 +253,48 @@ bitcoin-cli -datadir={datadir} getblockchaininfo
247253 thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
248254 }
249255 }
256+
257+ fn resolve_ord_bin ( & self ) -> Result < PathBuf > {
258+ let Some ( path) = & self . ord_bin else {
259+ bail ! ( "ord binary must be provided with --ord-bin" ) ;
260+ } ;
261+
262+ Self :: validate_ord_bin ( path)
263+ }
264+
265+ fn validate_ord_bin ( path : & Path ) -> Result < PathBuf > {
266+ let canonical = fs:: canonicalize ( path)
267+ . with_context ( || format ! ( "ord binary `{}` does not exist" , path. display( ) ) ) ?;
268+
269+ let metadata = fs:: metadata ( & canonical)
270+ . with_context ( || format ! ( "failed to read ord binary `{}`" , canonical. display( ) ) ) ?;
271+
272+ ensure ! (
273+ metadata. is_file( ) ,
274+ "ord binary `{}` is not a file" ,
275+ canonical. display( )
276+ ) ;
277+
278+ #[ cfg( unix) ]
279+ {
280+ use std:: os:: unix:: fs:: PermissionsExt ;
281+
282+ let mode = metadata. permissions ( ) . mode ( ) ;
283+
284+ ensure ! (
285+ mode & 0o111 != 0 ,
286+ "ord binary `{}` is not executable" ,
287+ canonical. display( )
288+ ) ;
289+
290+ ensure ! (
291+ mode & 0o022 == 0 ,
292+ "ord binary `{}` is writable by group or others" ,
293+ canonical. display( )
294+ ) ;
295+ }
296+
297+ Ok ( canonical)
298+ }
299+
250300}
0 commit comments