@@ -97,10 +97,10 @@ pub trait Rpc {
97
97
async fn get_server_info ( & self ) -> Result < ServerInfo , ErrorObjectOwned > ;
98
98
99
99
#[ method( name = "getspace" ) ]
100
- async fn get_space ( & self , space : String ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > ;
100
+ async fn get_space ( & self , space : & str ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > ;
101
101
102
102
#[ method( name = "getspaceowner" ) ]
103
- async fn get_space_owner ( & self , space : String ) -> Result < Option < OutPoint > , ErrorObjectOwned > ;
103
+ async fn get_space_owner ( & self , space : & str ) -> Result < Option < OutPoint > , ErrorObjectOwned > ;
104
104
105
105
#[ method( name = "getspaceout" ) ]
106
106
async fn get_spaceout ( & self , outpoint : OutPoint ) -> Result < Option < SpaceOut > , ErrorObjectOwned > ;
@@ -118,62 +118,58 @@ pub trait Rpc {
118
118
) -> Result < Option < ValidatedBlock > , ErrorObjectOwned > ;
119
119
120
120
#[ method( name = "walletload" ) ]
121
- async fn wallet_load ( & self , name : String ) -> Result < ( ) , ErrorObjectOwned > ;
121
+ async fn wallet_load ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > ;
122
122
123
123
#[ method( name = "walletimport" ) ]
124
- async fn wallet_import ( & self , content : String ) -> Result < ( ) , ErrorObjectOwned > ;
124
+ async fn wallet_import ( & self , content : & str ) -> Result < ( ) , ErrorObjectOwned > ;
125
125
126
126
#[ method( name = "walletgetinfo" ) ]
127
- async fn wallet_get_info ( & self , name : String ) -> Result < WalletInfo , ErrorObjectOwned > ;
127
+ async fn wallet_get_info ( & self , name : & str ) -> Result < WalletInfo , ErrorObjectOwned > ;
128
128
129
129
#[ method( name = "walletexport" ) ]
130
- async fn wallet_export ( & self , name : String ) -> Result < String , ErrorObjectOwned > ;
130
+ async fn wallet_export ( & self , name : & str ) -> Result < String , ErrorObjectOwned > ;
131
131
132
132
#[ method( name = "walletcreate" ) ]
133
- async fn wallet_create ( & self , name : String ) -> Result < ( ) , ErrorObjectOwned > ;
133
+ async fn wallet_create ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > ;
134
134
135
135
#[ method( name = "walletsendrequest" ) ]
136
136
async fn wallet_send_request (
137
137
& self ,
138
- wallet : String ,
138
+ wallet : & str ,
139
139
request : RpcWalletTxBuilder ,
140
140
) -> Result < WalletResponse , ErrorObjectOwned > ;
141
141
142
142
#[ method( name = "walletgetnewaddress" ) ]
143
143
async fn wallet_get_new_address (
144
144
& self ,
145
- wallet : String ,
145
+ wallet : & str ,
146
146
kind : AddressKind ,
147
147
) -> Result < String , ErrorObjectOwned > ;
148
148
149
149
#[ method( name = "walletbumpfee" ) ]
150
150
async fn wallet_bump_fee (
151
151
& self ,
152
- wallet : String ,
152
+ wallet : & str ,
153
153
txid : Txid ,
154
154
fee_rate : FeeRate ,
155
155
) -> Result < Vec < TxResponse > , ErrorObjectOwned > ;
156
156
157
157
#[ method( name = "walletlistspaces" ) ]
158
- async fn wallet_list_spaces (
159
- & self ,
160
- wallet : String ,
161
- ) -> Result < Vec < FullSpaceOut > , ErrorObjectOwned > ;
158
+ async fn wallet_list_spaces ( & self , wallet : & str )
159
+ -> Result < Vec < FullSpaceOut > , ErrorObjectOwned > ;
162
160
163
161
#[ method( name = "walletlistunspent" ) ]
164
- async fn wallet_list_unspent (
165
- & self ,
166
- wallet : String ,
167
- ) -> Result < Vec < LocalOutput > , ErrorObjectOwned > ;
162
+ async fn wallet_list_unspent ( & self , wallet : & str )
163
+ -> Result < Vec < LocalOutput > , ErrorObjectOwned > ;
168
164
169
165
#[ method( name = "walletlistauctionoutputs" ) ]
170
166
async fn wallet_list_auction_outputs (
171
167
& self ,
172
- wallet : String ,
168
+ wallet : & str ,
173
169
) -> Result < Vec < DoubleUtxo > , ErrorObjectOwned > ;
174
170
175
171
#[ method( name = "walletgetbalance" ) ]
176
- async fn wallet_get_balance ( & self , wallet : String ) -> Result < JointBalance , ErrorObjectOwned > ;
172
+ async fn wallet_get_balance ( & self , wallet : & str ) -> Result < JointBalance , ErrorObjectOwned > ;
177
173
}
178
174
179
175
#[ derive( Clone , Serialize , Deserialize ) ]
@@ -296,29 +292,25 @@ impl WalletManager {
296
292
let mut file = fs:: File :: create ( wallet_export_path) ?;
297
293
file. write_all ( wallet. to_string ( ) . as_bytes ( ) ) ?;
298
294
299
- self . load_wallet ( client, wallet. label ) . await ?;
295
+ self . load_wallet ( client, & wallet. label ) . await ?;
300
296
Ok ( ( ) )
301
297
}
302
298
303
- pub async fn export_wallet ( & self , name : String ) -> anyhow:: Result < String > {
304
- let wallet_dir = self . data_dir . join ( & name) ;
299
+ pub async fn export_wallet ( & self , name : & str ) -> anyhow:: Result < String > {
300
+ let wallet_dir = self . data_dir . join ( name) ;
305
301
if !wallet_dir. exists ( ) {
306
302
return Err ( anyhow ! ( "Wallet does not exist" ) ) ;
307
303
}
308
304
Ok ( fs:: read_to_string ( wallet_dir. join ( "wallet.json" ) ) ?)
309
305
}
310
306
311
- pub async fn create_wallet (
312
- & self ,
313
- client : & reqwest:: Client ,
314
- name : String ,
315
- ) -> anyhow:: Result < ( ) > {
307
+ pub async fn create_wallet ( & self , client : & reqwest:: Client , name : & str ) -> anyhow:: Result < ( ) > {
316
308
let mnemonic: GeneratedKey < _ , Tap > =
317
309
Mnemonic :: generate ( ( WordCount :: Words12 , Language :: English ) )
318
310
. map_err ( |_| anyhow ! ( "Mnemonic generation error" ) ) ?;
319
311
320
312
let start_block = self . get_wallet_start_block ( client) . await ?;
321
- self . setup_new_wallet ( name. clone ( ) , mnemonic. to_string ( ) , start_block) ?;
313
+ self . setup_new_wallet ( name. to_string ( ) , mnemonic. to_string ( ) , start_block) ?;
322
314
self . load_wallet ( client, name) . await ?;
323
315
Ok ( ( ) )
324
316
}
@@ -440,11 +432,11 @@ impl WalletManager {
440
432
Ok ( true )
441
433
}
442
434
443
- pub async fn load_wallet ( & self , client : & reqwest:: Client , name : String ) -> anyhow:: Result < ( ) > {
444
- let wallet_dir = self . data_dir . join ( name. clone ( ) ) ;
435
+ pub async fn load_wallet ( & self , client : & reqwest:: Client , name : & str ) -> anyhow:: Result < ( ) > {
436
+ let wallet_dir = self . data_dir . join ( name) ;
445
437
if !wallet_dir. exists ( ) {
446
438
if self
447
- . migrate_legacy_v0_0_1_wallet ( name. clone ( ) , wallet_dir. clone ( ) )
439
+ . migrate_legacy_v0_0_1_wallet ( name. to_string ( ) , wallet_dir. clone ( ) )
448
440
. await ?
449
441
{
450
442
info ! ( "Migrated legacy wallet {}" , name) ;
@@ -461,7 +453,7 @@ impl WalletManager {
461
453
let mut wallet = SpacesWallet :: new ( WalletConfig {
462
454
start_block : export. block_height ,
463
455
data_dir : wallet_dir,
464
- name : name. clone ( ) ,
456
+ name : name. to_string ( ) ,
465
457
network,
466
458
genesis_hash,
467
459
coins_descriptors : export. descriptors ( ) ,
@@ -482,7 +474,7 @@ impl WalletManager {
482
474
483
475
self . wallet_loader . send ( loaded_wallet) . await ?;
484
476
let mut wallets = self . wallets . write ( ) . await ;
485
- wallets. insert ( name, rpc_wallet) ;
477
+ wallets. insert ( name. to_string ( ) , rpc_wallet) ;
486
478
Ok ( ( ) )
487
479
}
488
480
@@ -611,7 +603,7 @@ impl RpcServer for RpcServerImpl {
611
603
Ok ( ServerInfo { chain, tip } )
612
604
}
613
605
614
- async fn get_space ( & self , space : String ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > {
606
+ async fn get_space ( & self , space : & str ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > {
615
607
let space = SName :: from_str ( & space) . map_err ( |_| {
616
608
ErrorObjectOwned :: owned (
617
609
-1 ,
@@ -629,8 +621,8 @@ impl RpcServer for RpcServerImpl {
629
621
Ok ( info)
630
622
}
631
623
632
- async fn get_space_owner ( & self , space : String ) -> Result < Option < OutPoint > , ErrorObjectOwned > {
633
- let space = SName :: from_str ( & space) . map_err ( |_| {
624
+ async fn get_space_owner ( & self , space : & str ) -> Result < Option < OutPoint > , ErrorObjectOwned > {
625
+ let space = SName :: from_str ( space) . map_err ( |_| {
634
626
ErrorObjectOwned :: owned (
635
627
-1 ,
636
628
"must be a valid canonical space name (e.g. @bitcoin)" ,
@@ -688,7 +680,7 @@ impl RpcServer for RpcServerImpl {
688
680
Ok ( data)
689
681
}
690
682
691
- async fn wallet_load ( & self , name : String ) -> Result < ( ) , ErrorObjectOwned > {
683
+ async fn wallet_load ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > {
692
684
self . wallet_manager
693
685
. load_wallet ( & self . client , name)
694
686
. await
@@ -697,24 +689,24 @@ impl RpcServer for RpcServerImpl {
697
689
} )
698
690
}
699
691
700
- async fn wallet_import ( & self , content : String ) -> Result < ( ) , ErrorObjectOwned > {
692
+ async fn wallet_import ( & self , content : & str ) -> Result < ( ) , ErrorObjectOwned > {
701
693
self . wallet_manager
702
- . import_wallet ( & self . client , & content)
694
+ . import_wallet ( & self . client , content)
703
695
. await
704
696
. map_err ( |error| {
705
697
ErrorObjectOwned :: owned ( RPC_WALLET_NOT_LOADED , error. to_string ( ) , None :: < String > )
706
698
} )
707
699
}
708
700
709
- async fn wallet_get_info ( & self , wallet : String ) -> Result < WalletInfo , ErrorObjectOwned > {
701
+ async fn wallet_get_info ( & self , wallet : & str ) -> Result < WalletInfo , ErrorObjectOwned > {
710
702
self . wallet ( & wallet)
711
703
. await ?
712
704
. send_get_info ( )
713
705
. await
714
706
. map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) )
715
707
}
716
708
717
- async fn wallet_export ( & self , name : String ) -> Result < String , ErrorObjectOwned > {
709
+ async fn wallet_export ( & self , name : & str ) -> Result < String , ErrorObjectOwned > {
718
710
self . wallet_manager
719
711
. export_wallet ( name)
720
712
. await
@@ -723,17 +715,17 @@ impl RpcServer for RpcServerImpl {
723
715
} )
724
716
}
725
717
726
- async fn wallet_create ( & self , name : String ) -> Result < ( ) , ErrorObjectOwned > {
718
+ async fn wallet_create ( & self , name : & str ) -> Result < ( ) , ErrorObjectOwned > {
727
719
self . wallet_manager
728
- . create_wallet ( & self . client , name. clone ( ) )
720
+ . create_wallet ( & self . client , name)
729
721
. await
730
722
. map_err ( |error| {
731
723
ErrorObjectOwned :: owned ( RPC_WALLET_NOT_LOADED , error. to_string ( ) , None :: < String > )
732
724
} )
733
725
}
734
726
async fn wallet_send_request (
735
727
& self ,
736
- wallet : String ,
728
+ wallet : & str ,
737
729
request : RpcWalletTxBuilder ,
738
730
) -> Result < WalletResponse , ErrorObjectOwned > {
739
731
let result = self
@@ -747,7 +739,7 @@ impl RpcServer for RpcServerImpl {
747
739
748
740
async fn wallet_get_new_address (
749
741
& self ,
750
- wallet : String ,
742
+ wallet : & str ,
751
743
kind : AddressKind ,
752
744
) -> Result < String , ErrorObjectOwned > {
753
745
self . wallet ( & wallet)
@@ -759,7 +751,7 @@ impl RpcServer for RpcServerImpl {
759
751
760
752
async fn wallet_bump_fee (
761
753
& self ,
762
- wallet : String ,
754
+ wallet : & str ,
763
755
txid : Txid ,
764
756
fee_rate : FeeRate ,
765
757
) -> Result < Vec < TxResponse > , ErrorObjectOwned > {
@@ -772,7 +764,7 @@ impl RpcServer for RpcServerImpl {
772
764
773
765
async fn wallet_list_spaces (
774
766
& self ,
775
- wallet : String ,
767
+ wallet : & str ,
776
768
) -> Result < Vec < FullSpaceOut > , ErrorObjectOwned > {
777
769
self . wallet ( & wallet)
778
770
. await ?
@@ -783,7 +775,7 @@ impl RpcServer for RpcServerImpl {
783
775
784
776
async fn wallet_list_unspent (
785
777
& self ,
786
- wallet : String ,
778
+ wallet : & str ,
787
779
) -> Result < Vec < LocalOutput > , ErrorObjectOwned > {
788
780
self . wallet ( & wallet)
789
781
. await ?
@@ -794,7 +786,7 @@ impl RpcServer for RpcServerImpl {
794
786
795
787
async fn wallet_list_auction_outputs (
796
788
& self ,
797
- wallet : String ,
789
+ wallet : & str ,
798
790
) -> Result < Vec < DoubleUtxo > , ErrorObjectOwned > {
799
791
self . wallet ( & wallet)
800
792
. await ?
@@ -803,7 +795,7 @@ impl RpcServer for RpcServerImpl {
803
795
. map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) )
804
796
}
805
797
806
- async fn wallet_get_balance ( & self , wallet : String ) -> Result < JointBalance , ErrorObjectOwned > {
798
+ async fn wallet_get_balance ( & self , wallet : & str ) -> Result < JointBalance , ErrorObjectOwned > {
807
799
self . wallet ( & wallet)
808
800
. await ?
809
801
. send_get_balance ( )
0 commit comments