@@ -8,26 +8,26 @@ use jsonrpsee::{
8
8
core:: { client:: Error , ClientError } ,
9
9
http_client:: { HttpClient , HttpClientBuilder } ,
10
10
} ;
11
- use protocol:: {
12
- bitcoin:: { Amount , FeeRate , OutPoint , Txid } ,
13
- hasher:: KeyHasher ,
14
- slabel:: SLabel ,
15
- } ;
16
- use spaced:: {
11
+ use spaces_client:: {
17
12
config:: { default_spaces_rpc_port, ExtendedNetwork } ,
13
+ format:: {
14
+ print_error_rpc_response, print_list_bidouts, print_list_spaces_response,
15
+ print_list_transactions, print_list_unspent, print_server_info,
16
+ print_wallet_balance_response, print_wallet_info, print_wallet_response, Format ,
17
+ } ,
18
18
rpc:: {
19
19
BidParams , ExecuteParams , OpenParams , RegisterParams , RpcClient , RpcWalletRequest ,
20
- RpcWalletTxBuilder , SendCoinsParams , TransferSpacesParams ,
20
+ RpcWalletTxBuilder , SendCoinsParams , SignedMessage , TransferSpacesParams ,
21
21
} ,
22
22
store:: Sha256 ,
23
- wallets:: AddressKind ,
23
+ wallets:: { AddressKind , WalletResponse } ,
24
24
} ;
25
- use spaced :: format :: { print_error_rpc_response , print_list_bidouts , print_list_spaces_response , print_list_transactions , print_list_unspent , print_server_info , print_wallet_balance_response , print_wallet_info , print_wallet_response , Format } ;
26
- use spaced :: rpc :: SignedMessage ;
27
- use spaced :: wallets :: WalletResponse ;
28
- use wallet :: bitcoin :: secp256k1 :: schnorr :: Signature ;
29
- use wallet :: export :: WalletExport ;
30
- use wallet :: Listing ;
25
+ use spaces_protocol :: {
26
+ bitcoin :: { Amount , FeeRate , OutPoint , Txid } ,
27
+ hasher :: KeyHasher ,
28
+ slabel :: SLabel ,
29
+ } ;
30
+ use spaces_wallet :: { bitcoin :: secp256k1 :: schnorr :: Signature , export :: WalletExport , Listing } ;
31
31
32
32
#[ derive( Parser , Debug ) ]
33
33
#[ command( version, about, long_about = None ) ]
@@ -138,7 +138,7 @@ enum Commands {
138
138
fee_rate : Option < u64 > ,
139
139
} ,
140
140
/// Renew ownership of a space
141
- #[ command( name = "renew" , ) ]
141
+ #[ command( name = "renew" ) ]
142
142
Renew {
143
143
/// Spaces to renew
144
144
#[ arg( display_order = 0 ) ]
@@ -372,7 +372,6 @@ impl SpaceCli {
372
372
)
373
373
. await ?;
374
374
375
-
376
375
print_wallet_response ( self . network . fallback_network ( ) , result, self . format ) ;
377
376
Ok ( ( ) )
378
377
}
@@ -387,8 +386,6 @@ fn normalize_space(space: &str) -> String {
387
386
}
388
387
}
389
388
390
-
391
-
392
389
#[ tokio:: main]
393
390
async fn main ( ) -> anyhow:: Result < ( ) > {
394
391
let ( cli, args) = SpaceCli :: configure ( ) . await ?;
@@ -512,7 +509,7 @@ async fn handle_commands(
512
509
fee_rate,
513
510
false ,
514
511
)
515
- . await ?
512
+ . await ?
516
513
}
517
514
Commands :: Bid {
518
515
space,
@@ -529,7 +526,7 @@ async fn handle_commands(
529
526
fee_rate,
530
527
confirmed_only,
531
528
)
532
- . await ?
529
+ . await ?
533
530
}
534
531
Commands :: CreateBidOuts { pairs, fee_rate } => {
535
532
cli. send_request ( None , Some ( pairs) , fee_rate, false ) . await ?
@@ -548,7 +545,7 @@ async fn handle_commands(
548
545
fee_rate,
549
546
false ,
550
547
)
551
- . await ?
548
+ . await ?
552
549
}
553
550
Commands :: Renew { spaces, fee_rate } => {
554
551
let spaces: Vec < _ > = spaces. into_iter ( ) . map ( |s| normalize_space ( & s) ) . collect ( ) ;
@@ -561,7 +558,7 @@ async fn handle_commands(
561
558
fee_rate,
562
559
false ,
563
560
)
564
- . await ?
561
+ . await ?
565
562
}
566
563
Commands :: Transfer {
567
564
spaces,
@@ -578,7 +575,7 @@ async fn handle_commands(
578
575
fee_rate,
579
576
false ,
580
577
)
581
- . await ?
578
+ . await ?
582
579
}
583
580
Commands :: SendCoins {
584
581
amount,
@@ -594,7 +591,7 @@ async fn handle_commands(
594
591
fee_rate,
595
592
false ,
596
593
)
597
- . await ?
594
+ . await ?
598
595
}
599
596
Commands :: SetRawFallback {
600
597
mut space,
@@ -612,7 +609,8 @@ async fn handle_commands(
612
609
}
613
610
} ;
614
611
615
- let space_script = protocol:: script:: SpaceScript :: create_set_fallback ( data. as_slice ( ) ) ;
612
+ let space_script =
613
+ spaces_protocol:: script:: SpaceScript :: create_set_fallback ( data. as_slice ( ) ) ;
616
614
617
615
cli. send_request (
618
616
Some ( RpcWalletRequest :: Execute ( ExecuteParams {
@@ -623,7 +621,7 @@ async fn handle_commands(
623
621
fee_rate,
624
622
false ,
625
623
)
626
- . await ?;
624
+ . await ?;
627
625
}
628
626
Commands :: ListUnspent => {
629
627
let utxos = cli. client . wallet_list_unspent ( & cli. wallet ) . await ?;
@@ -670,24 +668,36 @@ async fn handle_commands(
670
668
. wallet_bump_fee ( & cli. wallet , txid, fee_rate, cli. skip_tx_check )
671
669
. await ?;
672
670
print_wallet_response (
673
- cli. network . fallback_network ( ) , WalletResponse {
674
- result : response,
675
- } , cli. format ) ;
671
+ cli. network . fallback_network ( ) ,
672
+ WalletResponse { result : response } ,
673
+ cli. format ,
674
+ ) ;
676
675
}
677
676
Commands :: HashSpace { space } => {
678
677
println ! (
679
678
"{}" ,
680
679
hash_space( & space) . map_err( |e| ClientError :: Custom ( e. to_string( ) ) ) ?
681
680
) ;
682
681
}
683
- Commands :: Buy { space, price, signature, seller, fee_rate } => {
682
+ Commands :: Buy {
683
+ space,
684
+ price,
685
+ signature,
686
+ seller,
687
+ fee_rate,
688
+ } => {
684
689
let listing = Listing {
685
690
space : normalize_space ( & space) ,
686
691
price,
687
692
seller,
688
- signature : Signature :: from_slice ( hex:: decode ( signature)
689
- . map_err ( |_| ClientError :: Custom ( "Signature must be in hex format" . to_string ( ) ) ) ?. as_slice ( ) )
690
- . map_err ( |_| ClientError :: Custom ( "Invalid signature" . to_string ( ) ) ) ?,
693
+ signature : Signature :: from_slice (
694
+ hex:: decode ( signature)
695
+ . map_err ( |_| {
696
+ ClientError :: Custom ( "Signature must be in hex format" . to_string ( ) )
697
+ } ) ?
698
+ . as_slice ( ) ,
699
+ )
700
+ . map_err ( |_| ClientError :: Custom ( "Invalid signature" . to_string ( ) ) ) ?,
691
701
} ;
692
702
let result = cli
693
703
. client
@@ -696,57 +706,75 @@ async fn handle_commands(
696
706
listing,
697
707
fee_rate. map ( |rate| FeeRate :: from_sat_per_vb ( rate) . expect ( "valid fee rate" ) ) ,
698
708
cli. skip_tx_check ,
699
- ) . await ?;
700
- print_wallet_response ( cli. network . fallback_network ( ) , WalletResponse {
701
- result : vec ! [ result] ,
702
- } , cli. format
709
+ )
710
+ . await ?;
711
+ print_wallet_response (
712
+ cli. network . fallback_network ( ) ,
713
+ WalletResponse {
714
+ result : vec ! [ result] ,
715
+ } ,
716
+ cli. format ,
703
717
) ;
704
718
}
705
- Commands :: Sell { mut space, price, } => {
719
+ Commands :: Sell { mut space, price } => {
706
720
space = normalize_space ( & space) ;
707
- let result = cli
708
- . client
709
- . wallet_sell (
710
- & cli. wallet ,
711
- space,
712
- price,
713
- ) . await ?;
721
+ let result = cli. client . wallet_sell ( & cli. wallet , space, price) . await ?;
714
722
println ! ( "{}" , serde_json:: to_string_pretty( & result) . expect( "result" ) ) ;
715
723
}
716
- Commands :: VerifyListing { space, price, signature, seller } => {
724
+ Commands :: VerifyListing {
725
+ space,
726
+ price,
727
+ signature,
728
+ seller,
729
+ } => {
717
730
let listing = Listing {
718
731
space : normalize_space ( & space) ,
719
732
price,
720
733
seller,
721
- signature : Signature :: from_slice ( hex:: decode ( signature)
722
- . map_err ( |_| ClientError :: Custom ( "Signature must be in hex format" . to_string ( ) ) ) ?. as_slice ( ) )
723
- . map_err ( |_| ClientError :: Custom ( "Invalid signature" . to_string ( ) ) ) ?,
734
+ signature : Signature :: from_slice (
735
+ hex:: decode ( signature)
736
+ . map_err ( |_| {
737
+ ClientError :: Custom ( "Signature must be in hex format" . to_string ( ) )
738
+ } ) ?
739
+ . as_slice ( ) ,
740
+ )
741
+ . map_err ( |_| ClientError :: Custom ( "Invalid signature" . to_string ( ) ) ) ?,
724
742
} ;
725
743
726
- cli. client
727
- . verify_listing ( listing) . await ?;
744
+ cli. client . verify_listing ( listing) . await ?;
728
745
println ! ( "{} Listing verified" , "✓" . color( Color :: Green ) ) ;
729
746
}
730
747
Commands :: SignMessage { mut space, message } => {
731
748
space = normalize_space ( & space) ;
732
- let result = cli. client
733
- . wallet_sign_message ( & cli. wallet , & space, protocol:: Bytes :: new ( message. as_bytes ( ) . to_vec ( ) ) ) . await ?;
749
+ let result = cli
750
+ . client
751
+ . wallet_sign_message (
752
+ & cli. wallet ,
753
+ & space,
754
+ spaces_protocol:: Bytes :: new ( message. as_bytes ( ) . to_vec ( ) ) ,
755
+ )
756
+ . await ?;
734
757
println ! ( "{}" , result. signature) ;
735
758
}
736
- Commands :: VerifyMessage { mut space, message, signature } => {
759
+ Commands :: VerifyMessage {
760
+ mut space,
761
+ message,
762
+ signature,
763
+ } => {
737
764
space = normalize_space ( & space) ;
738
765
let raw = hex:: decode ( signature)
739
766
. map_err ( |_| ClientError :: Custom ( "Invalid signature" . to_string ( ) ) ) ?;
740
767
let signature = Signature :: from_slice ( raw. as_slice ( ) )
741
768
. map_err ( |_| ClientError :: Custom ( "Invalid signature" . to_string ( ) ) ) ?;
742
- cli. client . verify_message ( SignedMessage {
743
- space,
744
- message : protocol:: Bytes :: new ( message. as_bytes ( ) . to_vec ( ) ) ,
745
- signature,
746
- } ) . await ?;
769
+ cli. client
770
+ . verify_message ( SignedMessage {
771
+ space,
772
+ message : spaces_protocol:: Bytes :: new ( message. as_bytes ( ) . to_vec ( ) ) ,
773
+ signature,
774
+ } )
775
+ . await ?;
747
776
println ! ( "{} Message verified" , "✓" . color( Color :: Green ) ) ;
748
777
}
749
-
750
778
}
751
779
752
780
Ok ( ( ) )
0 commit comments