11//! Core address book implementation for managing Solana addresses with labels and roles.
22
3- use crate :: pda_seeds:: { SeedPart , find_pda_with_bump_and_strings} ;
3+ use crate :: pda_seeds:: find_pda_with_bump_and_strings;
44use crate :: registered_address:: { AddressRole , RegisteredAddress } ;
55use anchor_lang:: prelude:: * ;
66use anchor_lang:: solana_program:: system_program;
@@ -174,65 +174,6 @@ impl AddressBook {
174174 self . add ( pubkey, label, RegisteredAddress :: wallet ( pubkey) )
175175 }
176176
177- /// Adds a token mint address to the address book.
178- ///
179- /// # Errors
180- ///
181- /// Returns an error if the label already exists with a different address.
182- ///
183- /// # Example
184- ///
185- /// ```
186- /// use solana_address_book::AddressBook;
187- /// use anchor_lang::prelude::*;
188- ///
189- /// let mut book = AddressBook::new();
190- /// let mint = Pubkey::new_unique();
191- ///
192- /// book.add_mint(mint, "usdc_mint".to_string()).unwrap();
193- /// assert_eq!(book.get_label(&mint), "usdc_mint");
194- /// ```
195- pub fn add_mint ( & mut self , pubkey : Pubkey , label : String ) -> Result < ( ) > {
196- self . add ( pubkey, label, RegisteredAddress :: mint ( pubkey) )
197- }
198-
199- /// Adds an Associated Token Account (ATA) address to the address book.
200- ///
201- /// # Arguments
202- ///
203- /// * `pubkey` - The ATA's public key
204- /// * `label` - Human-readable label for the ATA
205- /// * `mint` - The token mint public key
206- /// * `owner` - The owner's public key
207- ///
208- /// # Errors
209- ///
210- /// Returns an error if the label already exists with a different address.
211- ///
212- /// # Example
213- ///
214- /// ```
215- /// use solana_address_book::AddressBook;
216- /// use anchor_lang::prelude::*;
217- ///
218- /// let mut book = AddressBook::new();
219- /// let ata = Pubkey::new_unique();
220- /// let mint = Pubkey::new_unique();
221- /// let owner = Pubkey::new_unique();
222- ///
223- /// book.add_ata(ata, "alice_usdc".to_string(), mint, owner).unwrap();
224- /// assert_eq!(book.get_label(&ata), "alice_usdc");
225- /// ```
226- pub fn add_ata (
227- & mut self ,
228- pubkey : Pubkey ,
229- label : String ,
230- mint : Pubkey ,
231- owner : Pubkey ,
232- ) -> Result < ( ) > {
233- self . add ( pubkey, label, RegisteredAddress :: ata ( pubkey, mint, owner) )
234- }
235-
236177 /// Adds a custom role address to the address book.
237178 ///
238179 /// Use this for addresses that don't fit into the standard categories.
@@ -357,7 +298,7 @@ impl AddressBook {
357298 /// # Example
358299 ///
359300 /// ```
360- /// use solana_address_book::{ AddressBook, SeedPart} ;
301+ /// use solana_address_book::AddressBook;
361302 /// use anchor_lang::prelude::*;
362303 ///
363304 /// let mut book = AddressBook::new();
@@ -366,7 +307,7 @@ impl AddressBook {
366307 ///
367308 /// let (pda, bump) = book.find_pda_with_bump(
368309 /// "user_vault",
369- /// &[& "vault" as &dyn SeedPart, & user as &dyn SeedPart ],
310+ /// &[b "vault", user.as_ref() ],
370311 /// program
371312 /// ).unwrap();
372313 ///
@@ -375,7 +316,7 @@ impl AddressBook {
375316 pub fn find_pda_with_bump (
376317 & mut self ,
377318 label : & str ,
378- seeds : & [ & dyn SeedPart ] ,
319+ seeds : & [ & [ u8 ] ] ,
379320 program_id : Pubkey ,
380321 ) -> Result < ( Pubkey , u8 ) > {
381322 // Use the helper function from pda_seeds module
@@ -580,13 +521,13 @@ impl AddressBook {
580521 /// # Example
581522 ///
582523 /// ```
583- /// use solana_address_book::AddressBook;
524+ /// use solana_address_book::{ AddressBook, RegisteredAddress} ;
584525 /// use anchor_lang::prelude::*;
585526 ///
586527 /// let mut book = AddressBook::new();
587528 /// let token = Pubkey::new_unique();
588529 ///
589- /// book.add_mint (token, "my_token".to_string()).unwrap();
530+ /// book.add (token, "my_token".to_string(), RegisteredAddress::mint(token )).unwrap();
590531 ///
591532 /// let text = format!("Transfer to {}", token);
592533 /// let formatted = book.replace_addresses_in_text(&text);
@@ -628,12 +569,13 @@ impl AddressBook {
628569 /// # Example
629570 ///
630571 /// ```
631- /// use solana_address_book::AddressBook;
572+ /// use solana_address_book::{ AddressBook, RegisteredAddress} ;
632573 /// use anchor_lang::prelude::*;
633574 ///
634575 /// let mut book = AddressBook::new();
635576 /// book.add_wallet(Pubkey::new_unique(), "alice".to_string()).unwrap();
636- /// book.add_mint(Pubkey::new_unique(), "usdc".to_string()).unwrap();
577+ /// let mint = Pubkey::new_unique();
578+ /// book.add(mint, "usdc".to_string(), RegisteredAddress::mint(mint)).unwrap();
637579 ///
638580 /// // Prints a formatted table of all addresses
639581 /// book.print_all();
@@ -863,31 +805,35 @@ mod tests {
863805 }
864806
865807 #[ test]
866- fn test_add_mint ( ) {
808+ fn test_add_mint ( ) -> Result < ( ) > {
867809 let mut book = AddressBook :: new ( ) ;
868810 let pubkey = Pubkey :: new_unique ( ) ;
869811
870- book. add_mint ( pubkey, "test_mint" . to_string ( ) ) . unwrap ( ) ;
812+ book. add (
813+ pubkey,
814+ "test_mint" . to_string ( ) ,
815+ RegisteredAddress :: mint ( pubkey) ,
816+ ) ?;
871817
872818 let ( label, registered) = book. get_first ( & pubkey) . unwrap ( ) ;
873819 assert_eq ! ( * label, "test_mint" ) ;
874820 matches ! ( registered. role, AddressRole :: Mint ) ;
821+
822+ Ok ( ( ) )
875823 }
876824
877825 #[ test]
878- fn test_add_ata ( ) {
826+ fn test_add_ata ( ) -> Result < ( ) > {
879827 let mut book = AddressBook :: new ( ) ;
880828 let ata_pubkey = Pubkey :: new_unique ( ) ;
881829 let mint_pubkey = Pubkey :: new_unique ( ) ;
882830 let owner_pubkey = Pubkey :: new_unique ( ) ;
883831
884- book. add_ata (
832+ book. add (
885833 ata_pubkey,
886834 "test_ata" . to_string ( ) ,
887- mint_pubkey,
888- owner_pubkey,
889- )
890- . unwrap ( ) ;
835+ RegisteredAddress :: ata ( ata_pubkey, mint_pubkey, owner_pubkey) ,
836+ ) ?;
891837
892838 let ( label, registered) = book. get_first ( & ata_pubkey) . unwrap ( ) ;
893839 assert_eq ! ( * label, "test_ata" ) ;
@@ -896,7 +842,8 @@ mod tests {
896842 assert_eq ! ( * owner, owner_pubkey) ;
897843 } else {
898844 panic ! ( "Expected ATA role" ) ;
899- }
845+ } ;
846+ Ok ( ( ) )
900847 }
901848
902849 #[ test]
@@ -968,7 +915,8 @@ mod tests {
968915
969916 book. add_wallet ( wallet1, "wallet1" . to_string ( ) ) . unwrap ( ) ;
970917 book. add_wallet ( wallet2, "wallet2" . to_string ( ) ) . unwrap ( ) ;
971- book. add_mint ( mint, "mint1" . to_string ( ) ) . unwrap ( ) ;
918+ book. add ( mint, "mint1" . to_string ( ) , RegisteredAddress :: mint ( mint) )
919+ . unwrap ( ) ;
972920
973921 let wallets = book. get_all_by_role_type ( "wallet" ) ;
974922 assert_eq ! ( wallets. len( ) , 2 ) ;
@@ -983,9 +931,7 @@ mod tests {
983931 #[ test]
984932 fn test_pda_creation ( ) {
985933 let program_id = Pubkey :: new_unique ( ) ;
986- let seeds: Vec < & dyn SeedPart > = vec ! [ & "test" , & "seed" ] ;
987-
988- let ( _pubkey, bump, registered) = RegisteredAddress :: pda ( & seeds, & program_id) ;
934+ let ( _pubkey, bump, registered) = RegisteredAddress :: pda ( & [ b"test" , b"seed" ] , & program_id) ;
989935
990936 if let AddressRole :: Pda {
991937 seeds : pda_seeds,
0 commit comments