package Ġcom . coin ninja . coin keeper . cn . account Ċ Ċ import Ġapp . coin ninja . cn . lib bitcoin . model . Der ivation Path Ċ import Ġapp . drop bit . annotations . Mock able Ċ import Ġcom . coin ninja . coin keeper . cn . wallet . HD Wallet Wrapper Ċ import Ġcom . coin ninja . coin keeper . model . db . Wallet Ċ import Ġcom . coin ninja . coin keeper . model . dto . Address DTO Ċ import Ġcom . coin ninja . coin keeper . model . helpers . Address Helper Ċ import Ġcom . coin ninja . coin keeper . model . helpers . Wallet Helper Ċ import Ġjavax . inject . Inject Ċ Ċ @ Mock able Ċ class ĠAccount Manager Ġ@ Inject Ġinternal Ġconstructor ( ĊĠĠĠĠĠĠĠ Ġinternal Ġval Ġhd Wallet : ĠHD Wallet Wrapper , ĊĠĠĠĠĠĠĠ Ġinternal Ġval Ġwallet Helper : ĠWallet Helper , ĊĠĠĠĠĠĠĠ Ġinternal Ġval Ġaddress Cache : ĠAddress Cache , ĊĠĠĠĠĠĠĠ Ġinternal Ġval Ġaddress Helper : ĠAddress Helper Ċ ) Ġ{ ĊĊĠĠĠ Ġval Ġnext Receive Address : ĠString ĊĠĠĠĠĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġaddresses Ġ= Ġaddress Helper . get Unused Addresses For ( wallet Helper . primary Wallet , ĠHD Wallet Wrapper . EXTERNAL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( addresses . isNotEmpty ()) Ġaddresses [ 0 ]. address Ġelse Ġhd Wallet . getAddress For Path ( der ivation Path For External Index ( 0 )). address ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġnext Receive Index : ĠInt ĊĠĠĠĠĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġaddresses Ġ= Ġaddress Helper . get Unused Addresses For ( wallet Helper . primary Wallet , ĠHD Wallet Wrapper . EXTERNAL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( addresses . isNotEmpty ()) Ġaddresses [ 0 ]. index Ġelse Ġ 0 ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġnext Change Index : ĠInt ĊĠĠĠĠĠĠĠ Ġget () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġaddresses Ġ= Ġaddress Helper . get Unused Addresses For ( wallet Helper . primary Wallet , ĠHD Wallet Wrapper . INTERNAL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( addresses . isNotEmpty ()) Ġaddresses [ 0 ]. index Ġelse Ġ 0 ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġlargest Reported Change Address ( wallet : ĠWallet ): ĠInt Ġ= Ġaddress Helper . get L argest Der ivation Index Reported For ( wallet , ĠHD Wallet Wrapper . INTERNAL ) ĊĊĠĠĠ Ġfun Ġlargest Reported Receive Address ( wallet : ĠWallet ): ĠInt Ġ= Ġaddress Helper . get L argest Der ivation Index Reported For ( wallet , ĠHD Wallet Wrapper . EXTERNAL ) ĊĊĠĠĠ Ġprivate Ġfun Ġder ivation Path For External Index ( index : ĠInt ): ĠDer ivation Path Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġwallet Ġ= Ġwallet Helper . primary Wallet ĊĠĠĠĠĠĠĠ Ġreturn ĠDer ivation Path ( wallet . purpose , Ġwallet . coin Type , Ġwallet . account Index , ĠHD Wallet Wrapper . EXTERNAL , Ġindex ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġreport L argest Receive Index Cons umed ( wallet : ĠWallet , Ġindex : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( wallet . external Index Ġ<= Ġindex ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwallet . external Index Ġ= Ġindex ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwallet . update () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġreport L argest Change Index Cons umed ( wallet : ĠWallet , Ġindex : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( wallet . internal Index Ġ<= Ġindex ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwallet . internal Index Ġ= Ġindex ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwallet . update () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcache Addresses ( wallet : ĠWallet ) Ġ{ ĊĠĠĠĠĠĠĠ Ġaddress Cache . cache Addresses For ( wallet , ĠHD Wallet Wrapper . EXTERNAL ) ĊĠĠĠĠĠĠĠ Ġaddress Cache . cache Addresses For ( wallet , ĠHD Wallet Wrapper . INTERNAL ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġunused Addresses To PubKey ( chain Index : ĠInt , ĠblockSize : ĠInt ): ĠHashMap < String , ĠAddress DTO > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġunused Addresses Ġ= Ġaddress Helper . get Unused Addresses For ( wallet Helper . primary Wallet , Ġchain Index ) ĊĠĠĠĠĠĠĠ Ġval Ġaddress To DTO Ġ= ĠHashMap < String , ĠAddress DTO >() ĊĠĠĠĠĠĠĠ Ġval Ġsize Ġ= Ġif Ġ( block Size Ġ<= Ġunused Addresses . size ) ĠblockSize Ġelse Ġunused Addresses . size ĊĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 0 Ġuntil Ġsize ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġaddress Ġ= Ġunused Addresses [ i ] ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaddress To DTO [ address . address ] Ġ= ĠAddress DTO ( address , Ġaddress Cache . getUn compressed PublicKey ( address . der ivation Path )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġaddress To DTO ĊĠĠĠ Ġ} Ċ } Ċ