@@ -4,7 +4,7 @@ use std::str::FromStr;
44use std:: sync:: Arc ;
55
66use key_wallet:: {
7- self as kw, address as kw_address , derivation:: HDWallet as KwHDWallet , mnemonic as kw_mnemonic,
7+ self as kw, derivation:: HDWallet as KwHDWallet , mnemonic as kw_mnemonic,
88 DerivationPath as KwDerivationPath , ExtendedPrivKey , ExtendedPubKey , Network as KwNetwork ,
99} ;
1010use secp256k1:: { PublicKey , Secp256k1 } ;
@@ -75,20 +75,20 @@ pub enum AddressType {
7575 P2SH ,
7676}
7777
78- impl From < kw_address :: AddressType > for AddressType {
79- fn from ( t : kw_address :: AddressType ) -> Self {
78+ impl From < dashcore :: AddressType > for AddressType {
79+ fn from ( t : dashcore :: AddressType ) -> Self {
8080 match t {
81- kw_address :: AddressType :: P2PKH => AddressType :: P2PKH ,
82- kw_address :: AddressType :: P2SH => AddressType :: P2SH ,
81+ dashcore :: AddressType :: P2pkh => AddressType :: P2PKH ,
82+ dashcore :: AddressType :: P2sh => AddressType :: P2SH ,
8383 }
8484 }
8585}
8686
87- impl From < AddressType > for kw_address :: AddressType {
87+ impl From < AddressType > for dashcore :: AddressType {
8888 fn from ( t : AddressType ) -> Self {
8989 match t {
90- AddressType :: P2PKH => kw_address :: AddressType :: P2PKH ,
91- AddressType :: P2SH => kw_address :: AddressType :: P2SH ,
90+ AddressType :: P2PKH => dashcore :: AddressType :: P2pkh ,
91+ AddressType :: P2SH => dashcore :: AddressType :: P2sh ,
9292 }
9393 }
9494}
@@ -189,6 +189,15 @@ impl From<kw::Error> for KeyWalletError {
189189 kw:: Error :: KeyError ( msg) => KeyWalletError :: KeyError {
190190 message : msg,
191191 } ,
192+ kw:: Error :: CoinJoinNotEnabled => KeyWalletError :: InvalidMnemonic {
193+ message : "CoinJoin not enabled" . into ( ) ,
194+ } ,
195+ kw:: Error :: Serialization ( msg) => KeyWalletError :: KeyError {
196+ message : msg,
197+ } ,
198+ kw:: Error :: InvalidParameter ( msg) => KeyWalletError :: InvalidDerivationPath {
199+ message : msg,
200+ } ,
192201 }
193202 }
194203}
@@ -439,12 +448,14 @@ impl ExtPubKey {
439448
440449// Address wrapper
441450pub struct Address {
442- inner : kw_address :: Address ,
451+ inner : dashcore :: Address ,
443452}
444453
445454impl Address {
446455 pub fn from_string ( address : String , network : Network ) -> Result < Self , KeyWalletError > {
447- let inner = kw_address:: Address :: from_str ( & address) . map_err ( |e| KeyWalletError :: from ( e) ) ?;
456+ let inner = dashcore:: Address :: from_str ( & address) . map_err ( |e| KeyWalletError :: AddressError {
457+ message : e. to_string ( ) ,
458+ } ) ?;
448459
449460 // Validate that the parsed network matches the expected network
450461 // Note: Testnet, Devnet, and Regtest all share the same address prefixes (140/19)
@@ -485,7 +496,7 @@ impl Address {
485496 PublicKey :: from_slice ( & public_key) . map_err ( |e| KeyWalletError :: Secp256k1Error {
486497 message : e. to_string ( ) ,
487498 } ) ?;
488- let inner = kw_address :: Address :: p2pkh ( & pubkey, network. into ( ) ) ;
499+ let inner = dashcore :: Address :: p2pkh ( & pubkey, network. into ( ) ) ;
489500 Ok ( Self {
490501 inner,
491502 } )
@@ -515,72 +526,75 @@ impl Address {
515526}
516527
517528// Address generator wrapper
518- pub struct AddressGenerator {
519- inner : kw_address:: AddressGenerator ,
520- }
521-
522- impl AddressGenerator {
523- pub fn new ( network : Network ) -> Self {
524- Self {
525- inner : kw_address:: AddressGenerator :: new ( network. into ( ) ) ,
526- }
527- }
528-
529- pub fn generate (
530- & self ,
531- account_xpub : AccountXPub ,
532- external : bool ,
533- index : u32 ,
534- ) -> Result < Arc < Address > , KeyWalletError > {
535- // Parse the extended public key from string
536- let xpub =
537- ExtendedPubKey :: from_str ( & account_xpub. xpub ) . map_err ( |e| KeyWalletError :: KeyError {
538- message : e. to_string ( ) ,
539- } ) ?;
540-
541- // Generate addresses for a single index
542- let addrs = self
543- . inner
544- . generate_range ( & xpub, external, index, 1 )
545- . map_err ( |e| KeyWalletError :: from ( e) ) ?;
546-
547- let addr = addrs. into_iter ( ) . next ( ) . ok_or_else ( || KeyWalletError :: KeyError {
548- message : "Failed to generate address" . into ( ) ,
549- } ) ?;
550-
551- Ok ( Arc :: new ( Address {
552- inner : addr,
553- } ) )
554- }
555-
556- pub fn generate_range (
557- & self ,
558- account_xpub : AccountXPub ,
559- external : bool ,
560- start : u32 ,
561- count : u32 ,
562- ) -> Result < Vec < Arc < Address > > , KeyWalletError > {
563- // Parse the extended public key from string
564- let xpub =
565- ExtendedPubKey :: from_str ( & account_xpub. xpub ) . map_err ( |e| KeyWalletError :: KeyError {
566- message : e. to_string ( ) ,
567- } ) ?;
568-
569- let addrs = self
570- . inner
571- . generate_range ( & xpub, external, start, count)
572- . map_err ( |e| KeyWalletError :: from ( e) ) ?;
573-
574- Ok ( addrs
575- . into_iter ( )
576- . map ( |addr| {
577- Arc :: new ( Address {
578- inner : addr,
579- } )
580- } )
581- . collect ( ) )
582- }
583- }
529+ // NOTE: AddressGenerator doesn't exist in dashcore, commented out for now
530+ // pub struct AddressGenerator {
531+ // inner: dashcore::address::AddressGenerator,
532+ // }
533+
534+ // impl AddressGenerator {
535+ // pub fn new(network: Network) -> Self {
536+ // Self {
537+ // inner: dashcore::address::AddressGenerator::new(network.into()),
538+ // }
539+ // }
540+
541+ // AddressGenerator methods commented out since AddressGenerator doesn't exist in dashcore
542+ // TODO: Implement address generation functionality without AddressGenerator
543+ // pub fn generate(
544+ // &self,
545+ // account_xpub: AccountXPub,
546+ // external: bool,
547+ // index: u32,
548+ // ) -> Result<Arc<Address>, KeyWalletError> {
549+ // // Parse the extended public key from string
550+ // let xpub =
551+ // ExtendedPubKey::from_str(&account_xpub.xpub).map_err(|e| KeyWalletError::KeyError {
552+ // message: e.to_string(),
553+ // })?;
554+ //
555+ // // Generate addresses for a single index
556+ // let addrs = self
557+ // .inner
558+ // .generate_range(&xpub, external, index, 1)
559+ // .map_err(|e| KeyWalletError::from(e))?;
560+ //
561+ // let addr = addrs.into_iter().next().ok_or_else(|| KeyWalletError::KeyError {
562+ // message: "Failed to generate address".into(),
563+ // })?;
564+ //
565+ // Ok(Arc::new(Address {
566+ // inner: addr,
567+ // }))
568+ // }
569+ //
570+ // pub fn generate_range(
571+ // &self,
572+ // account_xpub: AccountXPub,
573+ // external: bool,
574+ // start: u32,
575+ // count: u32,
576+ // ) -> Result<Vec<Arc<Address>>, KeyWalletError> {
577+ // // Parse the extended public key from string
578+ // let xpub =
579+ // ExtendedPubKey::from_str(&account_xpub.xpub).map_err(|e| KeyWalletError::KeyError {
580+ // message: e.to_string(),
581+ // })?;
582+ //
583+ // let addrs = self
584+ // .inner
585+ // .generate_range(&xpub, external, start, count)
586+ // .map_err(|e| KeyWalletError::from(e))?;
587+ //
588+ // Ok(addrs
589+ // .into_iter()
590+ // .map(|addr| {
591+ // Arc::new(Address {
592+ // inner: addr,
593+ // })
594+ // })
595+ // .collect())
596+ // }
597+ // }
584598
585599#[ cfg( test) ]
586600mod network_compatibility_tests {
0 commit comments