@@ -23,9 +23,8 @@ use protocol::{
23
23
OutPoint ,
24
24
} ,
25
25
constants:: ChainAnchor ,
26
- hasher:: { BaseHash , KeyHasher , SpaceHash } ,
26
+ hasher:: { BaseHash , SpaceHash } ,
27
27
prepare:: DataSource ,
28
- sname:: { NameLike , SName } ,
29
28
FullSpaceOut , SpaceOut ,
30
29
} ;
31
30
use serde:: { Deserialize , Serialize } ;
@@ -43,7 +42,7 @@ use crate::{
43
42
config:: ExtendedNetwork ,
44
43
node:: ValidatedBlock ,
45
44
source:: BitcoinRpc ,
46
- store:: { ChainState , LiveSnapshot , Sha256 } ,
45
+ store:: { ChainState , LiveSnapshot } ,
47
46
wallets:: { AddressKind , JointBalance , RpcWallet , TxResponse , WalletCommand , WalletResponse } ,
48
47
} ;
49
48
@@ -97,10 +96,11 @@ pub trait Rpc {
97
96
async fn get_server_info ( & self ) -> Result < ServerInfo , ErrorObjectOwned > ;
98
97
99
98
#[ method( name = "getspace" ) ]
100
- async fn get_space ( & self , space : & str ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > ;
99
+ async fn get_space ( & self , space_hash : & str ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > ;
101
100
102
101
#[ method( name = "getspaceowner" ) ]
103
- async fn get_space_owner ( & self , space : & str ) -> Result < Option < OutPoint > , ErrorObjectOwned > ;
102
+ async fn get_space_owner ( & self , space_hash : & str )
103
+ -> Result < Option < OutPoint > , ErrorObjectOwned > ;
104
104
105
105
#[ method( name = "getspaceout" ) ]
106
106
async fn get_spaceout ( & self , outpoint : OutPoint ) -> Result < Option < SpaceOut > , ErrorObjectOwned > ;
@@ -603,16 +603,8 @@ impl RpcServer for RpcServerImpl {
603
603
Ok ( ServerInfo { chain, tip } )
604
604
}
605
605
606
- async fn get_space ( & self , space : & str ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > {
607
- let space = SName :: from_str ( & space) . map_err ( |_| {
608
- ErrorObjectOwned :: owned (
609
- -1 ,
610
- "must be a valid canonical space name (e.g. @bitcoin)" ,
611
- None :: < String > ,
612
- )
613
- } ) ?;
614
-
615
- let space_hash = SpaceHash :: from ( Sha256 :: hash ( space. to_bytes ( ) ) ) ;
606
+ async fn get_space ( & self , space_hash : & str ) -> Result < Option < FullSpaceOut > , ErrorObjectOwned > {
607
+ let space_hash = space_hash_from_string ( space_hash) ?;
616
608
let info = self
617
609
. store
618
610
. get_space ( space_hash)
@@ -621,16 +613,11 @@ impl RpcServer for RpcServerImpl {
621
613
Ok ( info)
622
614
}
623
615
624
- async fn get_space_owner ( & self , space : & str ) -> Result < Option < OutPoint > , ErrorObjectOwned > {
625
- let space = SName :: from_str ( space) . map_err ( |_| {
626
- ErrorObjectOwned :: owned (
627
- -1 ,
628
- "must be a valid canonical space name (e.g. @bitcoin)" ,
629
- None :: < String > ,
630
- )
631
- } ) ?;
632
- let space_hash = SpaceHash :: from ( Sha256 :: hash ( space. to_bytes ( ) ) ) ;
633
-
616
+ async fn get_space_owner (
617
+ & self ,
618
+ space_hash : & str ,
619
+ ) -> Result < Option < OutPoint > , ErrorObjectOwned > {
620
+ let space_hash = space_hash_from_string ( space_hash) ?;
634
621
let info = self
635
622
. store
636
623
. get_space_outpoint ( space_hash)
@@ -936,3 +923,21 @@ impl AsyncChainState {
936
923
resp_rx. await ?
937
924
}
938
925
}
926
+
927
+ fn space_hash_from_string ( space_hash : & str ) -> Result < SpaceHash , ErrorObjectOwned > {
928
+ let mut hash = [ 0u8 ; 32 ] ;
929
+ hex:: decode_to_slice ( space_hash, & mut hash) . map_err ( |_| {
930
+ ErrorObjectOwned :: owned (
931
+ -1 ,
932
+ "expected a 32-byte hex encoded space hash" ,
933
+ None :: < String > ,
934
+ )
935
+ } ) ?;
936
+ SpaceHash :: from_raw ( hash) . map_err ( |_| {
937
+ ErrorObjectOwned :: owned (
938
+ -1 ,
939
+ "expected a 32-byte hex encoded space hash" ,
940
+ None :: < String > ,
941
+ )
942
+ } )
943
+ }
0 commit comments