@@ -24,7 +24,7 @@ use spaces_client::{
2424 config:: { default_cookie_path, default_spaces_rpc_port, ExtendedNetwork } ,
2525 deserialize_base64,
2626 format:: {
27- print_error_rpc_response, print_list_bidouts, print_list_spaces_response,
27+ print_error_rpc_response, print_list_all_spaces , print_list_bidouts, print_list_spaces_response,
2828 print_list_transactions, print_list_unspent, print_list_wallets, print_server_info,
2929 print_wallet_balance_response, print_wallet_info, print_wallet_response, Format ,
3030 } ,
@@ -157,6 +157,10 @@ enum Commands {
157157 /// The script public key as hex string
158158 spk : String ,
159159
160+ /// Hex encoded data to set on the created ptr
161+ #[ arg( long) ]
162+ data : Option < String > ,
163+
160164 #[ arg( long, short) ]
161165 fee_rate : Option < u64 > ,
162166 } ,
@@ -166,6 +170,13 @@ enum Commands {
166170 /// The sha256 hash of the spk or the spk itself prefixed with hex:
167171 spk : String ,
168172 } ,
173+ /// Get all ptrs info (same output format as getptr)
174+ #[ command( name = "getallptrs" ) ]
175+ GetAllPtrs {
176+ /// Only return PTRs with non-null data
177+ #[ arg( long) ]
178+ with_data : bool ,
179+ } ,
169180 /// Transfer ownership of spaces and/or PTRs to the given name or address
170181 #[ command(
171182 name = "transfer" ,
@@ -425,6 +436,9 @@ enum Commands {
425436 /// still in auction with a winning bid
426437 #[ command( name = "listspaces" ) ]
427438 ListSpaces ,
439+ /// List all spaces in the chain state (not just wallet-related)
440+ #[ command( name = "listallspaces" ) ]
441+ ListAllSpaces ,
428442 /// List unspent auction outputs i.e. outputs that can be
429443 /// auctioned off in the bidding process
430444 #[ command( name = "listbidouts" ) ]
@@ -672,6 +686,40 @@ async fn main() -> anyhow::Result<()> {
672686 Ok ( ( ) )
673687}
674688
689+ fn parse_ptr_for_json ( ptr : & spaces_ptr:: FullPtrOut ) -> serde_json:: Value {
690+ use spaces_ptr:: vtlv;
691+
692+ let mut ptr_json = serde_json:: to_value ( ptr) . expect ( "ptr should be serializable" ) ;
693+
694+ // Since ptrout and sptr are flattened via serde(flatten), the data field
695+ // appears directly in the JSON object, not nested. Look for "data" at the top level.
696+ if let Some ( obj) = ptr_json. as_object_mut ( ) {
697+ if let Some ( data) = obj. remove ( "data" ) {
698+ // Bytes serializes as hex string in JSON
699+ if let Some ( hex_str) = data. as_str ( ) {
700+ if let Ok ( data_bytes) = hex:: decode ( hex_str) {
701+ match vtlv:: parse_vtlv ( & data_bytes) {
702+ Ok ( parsed) => {
703+ obj. insert ( "parsed" . to_string ( ) , serde_json:: to_value ( parsed) . expect ( "parsed should be serializable" ) ) ;
704+ }
705+ Err ( _) => {
706+ // If parsing fails, keep the original data
707+ obj. insert ( "data" . to_string ( ) , data) ;
708+ }
709+ }
710+ } else {
711+ obj. insert ( "data" . to_string ( ) , data) ;
712+ }
713+ } else {
714+ // Not a string, keep as-is
715+ obj. insert ( "data" . to_string ( ) , data) ;
716+ }
717+ }
718+ }
719+
720+ ptr_json
721+ }
722+
675723async fn handle_commands ( cli : & SpaceCli , command : Commands ) -> Result < ( ) , ClientError > {
676724 match command {
677725 Commands :: GetRollout {
@@ -894,6 +942,9 @@ async fn handle_commands(cli: &SpaceCli, command: Commands) -> Result<(), Client
894942 . await ?;
895943 } else {
896944 // TODO: support set data for spaces
945+ return Err ( ClientError :: Custom ( format ! (
946+ "setrawfallback: setting data for spaces is not yet supported. Use an SPTR (sptr1...) instead of a space name."
947+ ) ) ) ;
897948 // // Space fallback: use existing space script
898949 // let space = normalize_space(&space_or_sptr);
899950 // let space_script =
@@ -931,6 +982,11 @@ async fn handle_commands(cli: &SpaceCli, command: Commands) -> Result<(), Client
931982 let spaces = cli. client . wallet_list_spaces ( & cli. wallet ) . await ?;
932983 print_list_spaces_response ( tip. tip . height , spaces, cli. format ) ;
933984 }
985+ Commands :: ListAllSpaces => {
986+ let tip = cli. client . get_server_info ( ) . await ?;
987+ let spaces = cli. client . get_all_spaces ( ) . await ?;
988+ print_list_all_spaces ( tip. tip . height , spaces, cli. format ) ;
989+ }
934990 Commands :: Balance => {
935991 let balance = cli. client . wallet_get_balance ( & cli. wallet ) . await ?;
936992 print_wallet_balance_response ( balance, cli. format ) ;
@@ -1100,15 +1156,25 @@ async fn handle_commands(cli: &SpaceCli, command: Commands) -> Result<(), Client
11001156
11011157 println ! ( "{}" , serde_json:: to_string( & event) . expect( "result" ) ) ;
11021158 }
1103- Commands :: CreatePtr { spk, fee_rate } => {
1159+ Commands :: CreatePtr { spk, data , fee_rate } => {
11041160 let spk = ScriptBuf :: from ( hex:: decode ( spk)
11051161 . map_err ( |_| ClientError :: Custom ( "Invalid spk hex" . to_string ( ) ) ) ?) ;
11061162
1163+ let data = match data {
1164+ Some ( data_hex) => {
1165+ Some ( hex:: decode ( data_hex) . map_err ( |e| {
1166+ ClientError :: Custom ( format ! ( "Could not hex decode data: {}" , e) )
1167+ } ) ?)
1168+ }
1169+ None => None ,
1170+ } ;
1171+
11071172 let sptr = Sptr :: from_spk :: < Sha256 > ( spk. clone ( ) ) ;
11081173 println ! ( "Creating sptr: {}" , sptr) ;
11091174 cli. send_request (
11101175 Some ( RpcWalletRequest :: CreatePtr ( CreatePtrParams {
11111176 spk : hex:: encode ( spk. as_bytes ( ) ) ,
1177+ data,
11121178 } ) ) ,
11131179 None ,
11141180 fee_rate,
@@ -1127,6 +1193,17 @@ async fn handle_commands(cli: &SpaceCli, command: Commands) -> Result<(), Client
11271193 . map_err ( |e| ClientError :: Custom ( e. to_string ( ) ) ) ?;
11281194 println ! ( "{}" , serde_json:: to_string( & ptr) . expect( "result" ) ) ;
11291195 }
1196+ Commands :: GetAllPtrs { with_data } => {
1197+ let ptrs = cli
1198+ . client
1199+ . get_all_ptrs ( with_data)
1200+ . await
1201+ . map_err ( |e| ClientError :: Custom ( e. to_string ( ) ) ) ?;
1202+ let parsed_ptrs: Vec < serde_json:: Value > = ptrs. iter ( )
1203+ . map ( |ptr| parse_ptr_for_json ( ptr) )
1204+ . collect ( ) ;
1205+ println ! ( "{}" , serde_json:: to_string( & parsed_ptrs) . expect( "result" ) ) ;
1206+ }
11301207
11311208 Commands :: GetPtrOut { outpoint } => {
11321209 let ptrout = cli
0 commit comments