@@ -69,6 +69,18 @@ pub struct BitcoinCore {
6969impl BitcoinCore {
7070 /// Start a new [`BitcoinCore`] instance with IPC enabled.
7171 pub fn start ( port : u16 , difficulty_level : DifficultyLevel ) -> Self {
72+ Self :: start_with_args ( port, difficulty_level, vec ! [ ] )
73+ }
74+
75+ /// Start a new [`BitcoinCore`] instance with IPC enabled and extra arguments.
76+ ///
77+ /// Set `BITCOIN_NODE_BIN` to override the bitcoin-node binary path
78+ /// (e.g. a custom build with `-testmulticoinbase` support).
79+ pub fn start_with_args (
80+ port : u16 ,
81+ difficulty_level : DifficultyLevel ,
82+ extra_args : Vec < & str > ,
83+ ) -> Self {
7284 let current_dir: PathBuf = std:: env:: current_dir ( ) . expect ( "failed to read current dir" ) ;
7385 let bin_dir = current_dir. join ( "template-provider" ) ;
7486 // Use temp dir for Bitcoin datadir to avoid long Unix socket paths in CI
@@ -110,46 +122,53 @@ impl BitcoinCore {
110122 }
111123 }
112124
113- // Download and setup Bitcoin Core v30.2 with IPC support
114- let os = env:: consts:: OS ;
115- let arch = env:: consts:: ARCH ;
116- let bitcoin_filename = get_bitcoin_core_filename ( os, arch) ;
117- let bitcoin_home = bin_dir. join ( format ! ( "bitcoin-{VERSION_BITCOIN_CORE}" ) ) ;
118- let bitcoin_node_bin = bitcoin_home. join ( "libexec" ) . join ( "bitcoin-node" ) ;
119- let bitcoin_cli_bin = bitcoin_home. join ( "bin" ) . join ( "bitcoin-cli" ) ;
125+ // Use custom bitcoin-node binary if BITCOIN_NODE_BIN is set,
126+ // otherwise download Bitcoin Core v30.2.
127+ let bitcoin_node_bin = if let Ok ( custom_bin) = env:: var ( "BITCOIN_NODE_BIN" ) {
128+ PathBuf :: from ( custom_bin)
129+ } else {
130+ let os = env:: consts:: OS ;
131+ let arch = env:: consts:: ARCH ;
132+ let bitcoin_filename = get_bitcoin_core_filename ( os, arch) ;
133+ let bitcoin_home = bin_dir. join ( format ! ( "bitcoin-{VERSION_BITCOIN_CORE}" ) ) ;
134+ let bitcoin_node_bin = bitcoin_home. join ( "libexec" ) . join ( "bitcoin-node" ) ;
135+ let bitcoin_cli_bin = bitcoin_home. join ( "bin" ) . join ( "bitcoin-cli" ) ;
136+
137+ if !bitcoin_node_bin. exists ( ) {
138+ let tarball_bytes = match env:: var ( "BITCOIN_CORE_TARBALL_FILE" ) {
139+ Ok ( path) => tarball:: read_from_file ( & path) ,
140+ Err ( _) => {
141+ warn ! ( "Downloading Bitcoin Core {} for the testing session. This could take a while..." , VERSION_BITCOIN_CORE ) ;
142+ let download_endpoint = env:: var ( "BITCOIN_CORE_DOWNLOAD_ENDPOINT" )
143+ . unwrap_or_else ( |_| {
144+ "https://bitcoincore.org/bin/bitcoin-core-30.2" . to_owned ( )
145+ } ) ;
146+ let url = format ! ( "{download_endpoint}/{bitcoin_filename}" ) ;
147+ http:: make_get_request ( & url, 5 )
148+ }
149+ } ;
120150
121- if !bitcoin_node_bin. exists ( ) {
122- let tarball_bytes = match env:: var ( "BITCOIN_CORE_TARBALL_FILE" ) {
123- Ok ( path) => tarball:: read_from_file ( & path) ,
124- Err ( _) => {
125- warn ! ( "Downloading Bitcoin Core {} for the testing session. This could take a while..." , VERSION_BITCOIN_CORE ) ;
126- let download_endpoint = env:: var ( "BITCOIN_CORE_DOWNLOAD_ENDPOINT" )
127- . unwrap_or_else ( |_| {
128- "https://bitcoincore.org/bin/bitcoin-core-30.2" . to_owned ( )
129- } ) ;
130- let url = format ! ( "{download_endpoint}/{bitcoin_filename}" ) ;
131- http:: make_get_request ( & url, 5 )
151+ if let Some ( parent) = bitcoin_home. parent ( ) {
152+ create_dir_all ( parent) . unwrap ( ) ;
132153 }
133- } ;
134154
135- if let Some ( parent) = bitcoin_home. parent ( ) {
136- create_dir_all ( parent) . unwrap ( ) ;
137- }
138-
139- tarball:: unpack ( & tarball_bytes, & bin_dir) ;
140-
141- // Sign the binaries on macOS
142- if os == "macos" {
143- for bin in & [ & bitcoin_node_bin, & bitcoin_cli_bin] {
144- std:: process:: Command :: new ( "codesign" )
145- . arg ( "--sign" )
146- . arg ( "-" )
147- . arg ( bin)
148- . output ( )
149- . expect ( "Failed to sign Bitcoin Core binary" ) ;
155+ tarball:: unpack ( & tarball_bytes, & bin_dir) ;
156+
157+ // Sign the binaries on macOS
158+ if os == "macos" {
159+ for bin in & [ & bitcoin_node_bin, & bitcoin_cli_bin] {
160+ std:: process:: Command :: new ( "codesign" )
161+ . arg ( "--sign" )
162+ . arg ( "-" )
163+ . arg ( bin)
164+ . output ( )
165+ . expect ( "Failed to sign Bitcoin Core binary" ) ;
166+ }
150167 }
151168 }
152- }
169+
170+ bitcoin_node_bin
171+ } ;
153172
154173 // Add IPC and basic args
155174 conf. args . extend ( vec ! [
@@ -158,6 +177,7 @@ impl BitcoinCore {
158177 "-debug=rpc" ,
159178 "-logtimemicros=1" ,
160179 ] ) ;
180+ conf. args . extend ( extra_args) ;
161181
162182 // Launch bitcoin-node using corepc-node (which will manage the process for us)
163183 let timeout = std:: time:: Duration :: from_secs ( 10 ) ;
@@ -278,7 +298,17 @@ pub struct TemplateProvider {
278298impl TemplateProvider {
279299 /// Start a new [`TemplateProvider`] instance with Bitcoin Core v30.2+ and standalone sv2-tp.
280300 pub fn start ( port : u16 , sv2_interval : u32 , difficulty_level : DifficultyLevel ) -> Self {
281- let bitcoin_core = BitcoinCore :: start ( port, difficulty_level) ;
301+ Self :: start_with_args ( port, sv2_interval, difficulty_level, vec ! [ ] )
302+ }
303+
304+ /// Start with extra arguments passed to bitcoin-node.
305+ pub fn start_with_args (
306+ port : u16 ,
307+ sv2_interval : u32 ,
308+ difficulty_level : DifficultyLevel ,
309+ extra_bitcoin_args : Vec < & str > ,
310+ ) -> Self {
311+ let bitcoin_core = BitcoinCore :: start_with_args ( port, difficulty_level, extra_bitcoin_args) ;
282312
283313 let current_dir: PathBuf = std:: env:: current_dir ( ) . expect ( "failed to read current dir" ) ;
284314 let bin_dir = current_dir. join ( "template-provider" ) ;
0 commit comments