@@ -25,7 +25,12 @@ use clarinet_deployments::{
2525use clarinet_files:: {
2626 get_manifest_location, FileLocation , ProjectManifest , ProjectManifestFile , RequirementConfig ,
2727} ;
28+ use clarinet_utils:: get_bip39_seed_from_mnemonic;
2829use clarity_repl:: analysis:: call_checker:: ContractAnalysis ;
30+ use clarity_repl:: clarity:: address:: AddressHashMode ;
31+ use clarity_repl:: clarity:: stacks_common:: types:: chainstate:: StacksAddress ;
32+ use clarity_repl:: clarity:: util:: hash:: bytes_to_hex;
33+ use clarity_repl:: clarity:: util:: secp256k1:: Secp256k1PublicKey ;
2934use clarity_repl:: clarity:: vm:: analysis:: AnalysisDatabase ;
3035use clarity_repl:: clarity:: vm:: costs:: LimitedCostTracker ;
3136use clarity_repl:: clarity:: vm:: diagnostic:: { Diagnostic , Level } ;
@@ -34,13 +39,15 @@ use clarity_repl::clarity::ClarityVersion;
3439use clarity_repl:: repl:: diagnostic:: { output_code, output_diagnostic} ;
3540use clarity_repl:: repl:: { ClarityCodeSource , ClarityContract , ContractDeployer , DEFAULT_EPOCH } ;
3641use clarity_repl:: { analysis, repl, Terminal } ;
42+ use libsecp256k1:: { PublicKey , SecretKey } ;
3743use stacks_network:: chainhook_event_observer:: chainhooks:: types:: ChainhookSpecification ;
3844use stacks_network:: chainhook_event_observer:: utils:: Context ;
3945use stacks_network:: { self , DevnetOrchestrator } ;
4046use std:: collections:: HashMap ;
4147use std:: fs:: { self , File } ;
4248use std:: io:: prelude:: * ;
4349use std:: { env, process} ;
50+ use tiny_hderive:: bip32:: ExtendedPrivKey ;
4451
4552use clap:: { IntoApp , Parser , Subcommand } ;
4653use clap_generate:: { Generator , Shell } ;
@@ -1302,7 +1309,11 @@ pub fn main() {
13021309 }
13031310 }
13041311 . issuer ;
1305-
1312+ let subnet_leader = compute_stx_address (
1313+ & devnet_config. subnet_leader_mnemonic ,
1314+ & devnet_config. subnet_leader_derivation_path ,
1315+ & StacksNetwork :: Devnet ,
1316+ ) ;
13061317 let _ = fs:: create_dir ( format ! ( "{}/requirements" , cache_location. display( ) ) ) ;
13071318
13081319 let ctx = Context {
@@ -1314,6 +1325,7 @@ pub fn main() {
13141325 & ctx,
13151326 cache_location,
13161327 & subnet_deployer,
1328+ & subnet_leader. into ( ) ,
13171329 ) ) {
13181330 Ok ( _) => { }
13191331 Err ( e) => {
@@ -1951,6 +1963,40 @@ impl DiagnosticsDigest {
19511963 }
19521964}
19531965
1966+ pub fn compute_stx_address (
1967+ mnemonic : & str ,
1968+ derivation_path : & str ,
1969+ network : & StacksNetwork ,
1970+ ) -> StacksAddress {
1971+ let bip39_seed = match get_bip39_seed_from_mnemonic ( & mnemonic, "" ) {
1972+ Ok ( bip39_seed) => bip39_seed,
1973+ Err ( _) => panic ! ( ) ,
1974+ } ;
1975+
1976+ let ext = ExtendedPrivKey :: derive ( & bip39_seed[ ..] , derivation_path) . unwrap ( ) ;
1977+
1978+ let secret_key = SecretKey :: parse_slice ( & ext. secret ( ) ) . unwrap ( ) ;
1979+
1980+ // Enforce a 33 bytes secret key format, expected by Stacks
1981+ let mut secret_key_bytes = secret_key. serialize ( ) . to_vec ( ) ;
1982+ secret_key_bytes. push ( 1 ) ;
1983+ let miner_secret_key_hex = bytes_to_hex ( & secret_key_bytes) ;
1984+
1985+ let public_key = PublicKey :: from_secret_key ( & secret_key) ;
1986+ let pub_key = Secp256k1PublicKey :: from_slice ( & public_key. serialize_compressed ( ) ) . unwrap ( ) ;
1987+ let version = clarity_repl:: clarity:: address:: C32_ADDRESS_VERSION_TESTNET_SINGLESIG ;
1988+
1989+ let stx_address = StacksAddress :: from_public_keys (
1990+ version,
1991+ & AddressHashMode :: SerializeP2PKH ,
1992+ 1 ,
1993+ & vec ! [ pub_key] ,
1994+ )
1995+ . unwrap ( ) ;
1996+
1997+ stx_address
1998+ }
1999+
19542000fn display_separator ( ) {
19552001 println ! ( "{}" , yellow!( "----------------------------" ) ) ;
19562002}
0 commit comments