@@ -23,8 +23,9 @@ use protocol::{
23
23
OutPoint ,
24
24
} ,
25
25
constants:: ChainAnchor ,
26
- hasher:: { BaseHash , SpaceHash } ,
26
+ hasher:: { BaseHash , KeyHasher , SpaceHash } ,
27
27
prepare:: DataSource ,
28
+ sname:: { NameLike , SName } ,
28
29
FullSpaceOut , SpaceOut ,
29
30
} ;
30
31
use serde:: { Deserialize , Serialize } ;
@@ -42,7 +43,7 @@ use crate::{
42
43
config:: ExtendedNetwork ,
43
44
node:: ValidatedBlock ,
44
45
source:: BitcoinRpc ,
45
- store:: { ChainState , LiveSnapshot } ,
46
+ store:: { ChainState , LiveSnapshot , Sha256 } ,
46
47
wallets:: { AddressKind , JointBalance , RpcWallet , TxResponse , WalletCommand , WalletResponse } ,
47
48
} ;
48
49
@@ -58,7 +59,7 @@ pub enum ChainStateCommand {
58
59
GetTip {
59
60
resp : Responder < anyhow:: Result < ChainAnchor > > ,
60
61
} ,
61
- GetSpaceInfo {
62
+ GetSpace {
62
63
hash : SpaceHash ,
63
64
resp : Responder < anyhow:: Result < Option < FullSpaceOut > > > ,
64
65
} ,
@@ -95,27 +96,21 @@ pub trait Rpc {
95
96
#[ method( name = "getserverinfo" ) ]
96
97
async fn get_server_info ( & self ) -> Result < ServerInfo , ErrorObjectOwned > ;
97
98
98
- #[ method( name = "getspaceinfo" ) ]
99
- async fn get_space_info (
100
- & self ,
101
- space_hash : String ,
102
- ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > ;
99
+ #[ method( name = "getspace" ) ]
100
+ async fn get_space ( & self , space : String ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > ;
101
+
102
+ #[ method( name = "getspaceowner" ) ]
103
+ async fn get_space_owner ( & self , space : String ) -> Result < Option < OutPoint > , ErrorObjectOwned > ;
104
+
105
+ #[ method( name = "getspaceout" ) ]
106
+ async fn get_spaceout ( & self , outpoint : OutPoint ) -> Result < Option < SpaceOut > , ErrorObjectOwned > ;
103
107
104
108
#[ method( name = "estimatebid" ) ]
105
109
async fn estimate_bid ( & self , target : usize ) -> Result < u64 , ErrorObjectOwned > ;
106
110
107
111
#[ method( name = "getrollout" ) ]
108
112
async fn get_rollout ( & self , target : usize ) -> Result < Vec < ( u32 , SpaceHash ) > , ErrorObjectOwned > ;
109
113
110
- #[ method( name = "getspaceowner" ) ]
111
- async fn get_space_owner (
112
- & self ,
113
- space_hash : String ,
114
- ) -> Result < Option < OutPoint > , ErrorObjectOwned > ;
115
-
116
- #[ method( name = "getspaceout" ) ]
117
- async fn get_spaceout ( & self , outpoint : OutPoint ) -> Result < Option < SpaceOut > , ErrorObjectOwned > ;
118
-
119
114
#[ method( name = "getblockdata" ) ]
120
115
async fn get_block_data (
121
116
& self ,
@@ -615,71 +610,33 @@ impl RpcServer for RpcServerImpl {
615
610
Ok ( ServerInfo { chain, tip } )
616
611
}
617
612
618
- async fn get_space_info (
619
- & self ,
620
- space_hash_str : String ,
621
- ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > {
622
- let mut space_hash = [ 0u8 ; 32 ] ;
623
- hex:: decode_to_slice ( space_hash_str, & mut space_hash) . map_err ( |_| {
624
- ErrorObjectOwned :: owned (
625
- -1 ,
626
- "expected a 32-byte hex encoded space hash a" ,
627
- None :: < String > ,
628
- )
629
- } ) ?;
630
- let space_hash = SpaceHash :: from_raw ( space_hash) . map_err ( |_| {
613
+ async fn get_space ( & self , space : String ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > {
614
+ let space = SName :: from_str ( & space) . map_err ( |_| {
631
615
ErrorObjectOwned :: owned (
632
616
-1 ,
633
- "expected a 32-byte hex encoded space hash b " ,
617
+ "must be a valid canonical space name (e.g. @bitcoin) " ,
634
618
None :: < String > ,
635
619
)
636
620
} ) ?;
637
621
622
+ let space_hash = SpaceHash :: from ( Sha256 :: hash ( space. to_bytes ( ) ) ) ;
638
623
let info = self
639
624
. store
640
- . get_space_info ( space_hash)
625
+ . get_space ( space_hash)
641
626
. await
642
627
. map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) ) ?;
643
628
Ok ( info)
644
629
}
645
630
646
- async fn estimate_bid ( & self , target : usize ) -> Result < u64 , ErrorObjectOwned > {
647
- let info = self
648
- . store
649
- . estimate_bid ( target)
650
- . await
651
- . map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) ) ?;
652
- Ok ( info)
653
- }
654
-
655
- async fn get_rollout ( & self , target : usize ) -> Result < Vec < ( u32 , SpaceHash ) > , ErrorObjectOwned > {
656
- let rollouts = self
657
- . store
658
- . get_rollout ( target)
659
- . await
660
- . map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) ) ?;
661
- Ok ( rollouts)
662
- }
663
-
664
- async fn get_space_owner (
665
- & self ,
666
- space_hash_str : String ,
667
- ) -> Result < Option < OutPoint > , ErrorObjectOwned > {
668
- let mut space_hash = [ 0u8 ; 32 ] ;
669
- hex:: decode_to_slice ( space_hash_str, & mut space_hash) . map_err ( |_| {
631
+ async fn get_space_owner ( & self , space : String ) -> Result < Option < OutPoint > , ErrorObjectOwned > {
632
+ let space = SName :: from_str ( & space) . map_err ( |_| {
670
633
ErrorObjectOwned :: owned (
671
634
-1 ,
672
- "expected a 32-byte hex encoded space hash" ,
673
- None :: < String > ,
674
- )
675
- } ) ?;
676
- let space_hash = SpaceHash :: from_raw ( space_hash) . map_err ( |_| {
677
- ErrorObjectOwned :: owned (
678
- -1 ,
679
- "expected a 32-byte hex encoded space hash" ,
635
+ "must be a valid canonical space name (e.g. @bitcoin)" ,
680
636
None :: < String > ,
681
637
)
682
638
} ) ?;
639
+ let space_hash = SpaceHash :: from ( Sha256 :: hash ( space. to_bytes ( ) ) ) ;
683
640
684
641
let info = self
685
642
. store
@@ -699,6 +656,24 @@ impl RpcServer for RpcServerImpl {
699
656
Ok ( spaceout)
700
657
}
701
658
659
+ async fn estimate_bid ( & self , target : usize ) -> Result < u64 , ErrorObjectOwned > {
660
+ let info = self
661
+ . store
662
+ . estimate_bid ( target)
663
+ . await
664
+ . map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) ) ?;
665
+ Ok ( info)
666
+ }
667
+
668
+ async fn get_rollout ( & self , target : usize ) -> Result < Vec < ( u32 , SpaceHash ) > , ErrorObjectOwned > {
669
+ let rollouts = self
670
+ . store
671
+ . get_rollout ( target)
672
+ . await
673
+ . map_err ( |error| ErrorObjectOwned :: owned ( -1 , error. to_string ( ) , None :: < String > ) ) ?;
674
+ Ok ( rollouts)
675
+ }
676
+
702
677
async fn get_block_data (
703
678
& self ,
704
679
block_hash : BlockHash ,
@@ -851,7 +826,7 @@ impl AsyncChainState {
851
826
let tip = chain_state. tip . read ( ) . expect ( "read meta" ) . clone ( ) ;
852
827
_ = resp. send ( Ok ( tip) )
853
828
}
854
- ChainStateCommand :: GetSpaceInfo { hash, resp } => {
829
+ ChainStateCommand :: GetSpace { hash, resp } => {
855
830
let result = chain_state. get_space_info ( & hash) ;
856
831
let _ = resp. send ( result) ;
857
832
}
@@ -927,10 +902,10 @@ impl AsyncChainState {
927
902
resp_rx. await ?
928
903
}
929
904
930
- pub async fn get_space_info ( & self , hash : SpaceHash ) -> anyhow:: Result < Option < FullSpaceOut > > {
905
+ pub async fn get_space ( & self , hash : SpaceHash ) -> anyhow:: Result < Option < FullSpaceOut > > {
931
906
let ( resp, resp_rx) = oneshot:: channel ( ) ;
932
907
self . sender
933
- . send ( ChainStateCommand :: GetSpaceInfo { hash, resp } )
908
+ . send ( ChainStateCommand :: GetSpace { hash, resp } )
934
909
. await ?;
935
910
resp_rx. await ?
936
911
}
0 commit comments