@@ -2,17 +2,15 @@ extern crate core;
22
33use std:: { fs, path:: PathBuf , str:: FromStr } ;
44
5- use base64:: { prelude:: BASE64_STANDARD , Engine } ;
65use clap:: { Parser , Subcommand } ;
76use jsonrpsee:: {
87 core:: { client:: Error , ClientError } ,
98 http_client:: { HttpClient , HttpClientBuilder } ,
109} ;
1110use protocol:: {
1211 bitcoin:: { Amount , FeeRate , OutPoint , Txid } ,
13- hasher:: { KeyHasher , SpaceKey } ,
12+ hasher:: { KeyHasher } ,
1413 slabel:: SLabel ,
15- Covenant , FullSpaceOut ,
1614} ;
1715use serde:: { Deserialize , Serialize } ;
1816use spaced:: {
@@ -31,14 +29,14 @@ use wallet::export::WalletExport;
3129pub struct Args {
3230 /// Bitcoin network to use
3331 #[ arg( long, env = "SPACED_CHAIN" ) ]
34- chain : spaced :: config :: ExtendedNetwork ,
32+ chain : ExtendedNetwork ,
3533 /// Spaced RPC URL [default: based on specified chain]
3634 #[ arg( long) ]
3735 spaced_rpc_url : Option < String > ,
3836 /// Specify wallet to use
3937 #[ arg( long, short, global = true , default_value = "default" ) ]
4038 wallet : String ,
41- /// Custom dust amount in sat for auction outputs
39+ /// Custom dust amount in sat for bid outputs
4240 #[ arg( long, short, global = true ) ]
4341 dust : Option < u64 > ,
4442 /// Force invalid transaction (for testing only)
@@ -52,21 +50,15 @@ pub struct Args {
5250enum Commands {
5351 /// Generate a new wallet
5452 #[ command( name = "createwallet" ) ]
55- CreateWallet {
56- #[ arg( default_value = "default" ) ]
57- name : String ,
58- } ,
53+ CreateWallet ,
5954 /// Load a wallet
6055 #[ command( name = "loadwallet" ) ]
61- LoadWallet {
62- #[ arg( default_value = "default" ) ]
63- name : String ,
64- } ,
56+ LoadWallet ,
6557 /// Export a wallet
6658 #[ command( name = "exportwallet" ) ]
6759 ExportWallet {
68- # [ arg ( default_value = "default" ) ]
69- name : String ,
60+ // Destination path to export json file
61+ path : PathBuf ,
7062 } ,
7163 /// Import a wallet
7264 #[ command( name = "importwallet" ) ]
@@ -76,10 +68,7 @@ enum Commands {
7668 } ,
7769 /// Export a wallet
7870 #[ command( name = "getwalletinfo" ) ]
79- GetWalletInfo {
80- #[ arg( default_value = "default" ) ]
81- name : String ,
82- } ,
71+ GetWalletInfo ,
8372 /// Export a wallet
8473 #[ command( name = "getserverinfo" ) ]
8574 GetServerInfo ,
@@ -163,8 +152,8 @@ enum Commands {
163152 #[ command( name = "balance" ) ]
164153 Balance ,
165154 /// Pre-create outputs that can be auctioned off during the bidding process
166- #[ command( name = "createauctionoutputs " ) ]
167- CreateAuctionOutputs {
155+ #[ command( name = "createbidouts " ) ]
156+ CreateBidOuts {
168157 /// Number of output pairs to create
169158 /// Each pair can be used to make a bid
170159 pairs : u8 ,
@@ -187,20 +176,21 @@ enum Commands {
187176 outpoint : OutPoint ,
188177 } ,
189178 /// Get the estimated rollout batch for the specified interval
190- #[ command( name = "getrolloutestimate " ) ]
191- GetRolloutEstimate {
179+ #[ command( name = "getrollout " ) ]
180+ GetRollout {
192181 // Get the estimated rollout for the target interval. Every ~144 blocks (a rollout interval),
193182 // 10 spaces are released for auction. Specify 0 [default] for the coming interval, 1
194183 // for the interval after and so on.
195184 #[ arg( default_value = "0" ) ]
196185 target_interval : usize ,
197186 } ,
198- /// Associate the specified data with a given space (experimental may be removed)
199- #[ command( name = "setdata" ) ]
200- SetData {
187+ /// Associate the specified data with a given space (not recommended use Fabric instead)
188+ /// If for whatever reason it's not possible to use other protocols, then you may use this.
189+ #[ command( name = "setrawfallback" ) ]
190+ SetRawFallback {
201191 /// Space name
202192 space : String ,
203- /// Base64 encoded data
193+ /// Hex encoded data
204194 data : String ,
205195 /// Fee rate to use in sat/vB
206196 #[ arg( long, short) ]
@@ -212,8 +202,8 @@ enum Commands {
212202 ListSpaces ,
213203 /// List unspent auction outputs i.e. outputs that can be
214204 /// auctioned off in the bidding process
215- #[ command( name = "listauctionoutputs " ) ]
216- ListAuctionOutputs ,
205+ #[ command( name = "listbidouts " ) ]
206+ ListBidOuts ,
217207 /// List unspent coins owned by wallet
218208 #[ command( name = "listunspent" ) ]
219209 ListUnspent ,
@@ -225,19 +215,18 @@ enum Commands {
225215 /// compatible with most bitcoin wallets
226216 #[ command( name = "getnewaddress" ) ]
227217 GetCoinAddress ,
228- /// Calculate a spacehash from the specified space name
229- #[ command( name = "spacehash" ) ]
230- SpaceHash {
231- /// The space name
232- space : String ,
233- } ,
234218 /// Force spend an output owned by wallet (for testing only)
235219 #[ command( name = "forcespend" ) ]
236220 ForceSpend {
237221 outpoint : OutPoint ,
238222 #[ arg( long, short) ]
239223 fee_rate : u64 ,
240224 } ,
225+ /// DNS encodes the space and calculates the SHA-256 hash
226+ #[ command( name = "hashspace" ) ]
227+ HashSpace {
228+ space : String ,
229+ } ,
241230}
242231
243232struct SpaceCli {
@@ -376,89 +365,56 @@ async fn main() -> anyhow::Result<()> {
376365 Ok ( ( ) )
377366}
378367
379- fn space_hash ( spaceish : & str ) -> anyhow:: Result < String > {
368+ fn hash_space ( spaceish : & str ) -> anyhow:: Result < String > {
380369 let space = normalize_space ( & spaceish) ;
381370 let sname = SLabel :: from_str ( & space) ?;
382- let spacehash = SpaceKey :: from ( Sha256 :: hash ( sname. as_ref ( ) ) ) ;
383- Ok ( hex:: encode ( spacehash. as_slice ( ) ) )
371+ Ok ( hex:: encode ( Sha256 :: hash ( sname. as_ref ( ) ) ) )
384372}
385373
386374async fn handle_commands (
387375 cli : & SpaceCli ,
388376 command : Commands ,
389377) -> std:: result:: Result < ( ) , ClientError > {
390378 match command {
391- Commands :: GetRolloutEstimate {
379+ Commands :: GetRollout {
392380 target_interval : target,
393381 } => {
394- let hashes = cli. client . get_rollout ( target) . await ?;
395- let mut spaceouts = Vec :: with_capacity ( hashes. len ( ) ) ;
396- for ( priority, spacehash) in hashes {
397- let outpoint = cli
398- . client
399- . get_space_owner ( & hex:: encode ( spacehash. as_slice ( ) ) )
400- . await ?;
401-
402- if let Some ( outpoint) = outpoint {
403- if let Some ( spaceout) = cli. client . get_spaceout ( outpoint) . await ? {
404- spaceouts. push ( (
405- priority,
406- FullSpaceOut {
407- txid : outpoint. txid ,
408- spaceout,
409- } ,
410- ) ) ;
411- }
412- }
413- }
414-
415- let data: Vec < _ > = spaceouts
416- . into_iter ( )
417- . map ( |( priority, spaceout) | {
418- let space = spaceout. spaceout . space . unwrap ( ) ;
419- (
420- space. name . to_string ( ) ,
421- match space. covenant {
422- Covenant :: Bid { .. } => priority,
423- _ => 0 ,
424- } ,
425- )
426- } )
427- . collect ( ) ;
428-
382+ let data = cli. client . get_rollout ( target) . await ?;
429383 println ! ( "{}" , serde_json:: to_string_pretty( & data) ?) ;
430384 }
431385 Commands :: EstimateBid { target } => {
432386 let response = cli. client . estimate_bid ( target) . await ?;
433387 println ! ( "{} sat" , Amount :: from_sat( response) . to_string( ) ) ;
434388 }
435389 Commands :: GetSpace { space } => {
436- let space_hash = space_hash ( & space) . map_err ( |e| ClientError :: Custom ( e. to_string ( ) ) ) ?;
390+ let space_hash = hash_space ( & space) . map_err ( |e| ClientError :: Custom ( e. to_string ( ) ) ) ?;
437391 let response = cli. client . get_space ( & space_hash) . await ?;
438392 println ! ( "{}" , serde_json:: to_string_pretty( & response) ?) ;
439393 }
440394 Commands :: GetSpaceOut { outpoint } => {
441395 let response = cli. client . get_spaceout ( outpoint) . await ?;
442396 println ! ( "{}" , serde_json:: to_string_pretty( & response) ?) ;
443397 }
444- Commands :: CreateWallet { name } => {
445- cli. client . wallet_create ( & name ) . await ?;
398+ Commands :: CreateWallet => {
399+ cli. client . wallet_create ( & cli . wallet ) . await ?;
446400 }
447- Commands :: LoadWallet { name } => {
448- cli. client . wallet_load ( & name ) . await ?;
401+ Commands :: LoadWallet => {
402+ cli. client . wallet_load ( & cli . wallet ) . await ?;
449403 }
450404 Commands :: ImportWallet { path } => {
451405 let content =
452406 fs:: read_to_string ( path) . map_err ( |e| ClientError :: Custom ( e. to_string ( ) ) ) ?;
453407 let wallet: WalletExport = serde_json:: from_str ( & content) ?;
454408 cli. client . wallet_import ( wallet) . await ?;
455409 }
456- Commands :: ExportWallet { name } => {
457- let result = cli. client . wallet_export ( & name) . await ?;
458- println ! ( "{}" , serde_json:: to_string_pretty( & result) . expect( "result" ) ) ;
410+ Commands :: ExportWallet { path } => {
411+ let result = cli. client . wallet_export ( & cli. wallet ) . await ?;
412+ let content = serde_json:: to_string_pretty ( & result) . expect ( "result" ) ;
413+ fs:: write ( path, content) . map_err ( |e|
414+ ClientError :: Custom ( format ! ( "Could not save to path: {}" , e. to_string( ) ) ) ) ?;
459415 }
460- Commands :: GetWalletInfo { name } => {
461- let result = cli. client . wallet_get_info ( & name ) . await ?;
416+ Commands :: GetWalletInfo => {
417+ let result = cli. client . wallet_get_info ( & cli . wallet ) . await ?;
462418 println ! ( "{}" , serde_json:: to_string_pretty( & result) . expect( "result" ) ) ;
463419 }
464420 Commands :: GetServerInfo => {
@@ -495,7 +451,7 @@ async fn handle_commands(
495451 )
496452 . await ?
497453 }
498- Commands :: CreateAuctionOutputs { pairs, fee_rate } => {
454+ Commands :: CreateBidOuts { pairs, fee_rate } => {
499455 cli. send_request ( None , Some ( pairs) , fee_rate) . await ?
500456 }
501457 Commands :: Register {
@@ -544,17 +500,17 @@ async fn handle_commands(
544500 )
545501 . await ?
546502 }
547- Commands :: SetData {
503+ Commands :: SetRawFallback {
548504 mut space,
549505 data,
550506 fee_rate,
551507 } => {
552508 space = normalize_space ( & space) ;
553- let data = match BASE64_STANDARD . decode ( data) {
509+ let data = match hex :: decode ( data) {
554510 Ok ( data) => data,
555511 Err ( e) => {
556512 return Err ( ClientError :: Custom ( format ! (
557- "Could not base64 decode data: {}" ,
513+ "Could not hex decode data: {}" ,
558514 e
559515 ) ) )
560516 }
@@ -576,7 +532,7 @@ async fn handle_commands(
576532 let spaces = cli. client . wallet_list_unspent ( & cli. wallet ) . await ?;
577533 println ! ( "{}" , serde_json:: to_string_pretty( & spaces) ?) ;
578534 }
579- Commands :: ListAuctionOutputs => {
535+ Commands :: ListBidOuts => {
580536 let spaces = cli. client . wallet_list_auction_outputs ( & cli. wallet ) . await ?;
581537 println ! ( "{}" , serde_json:: to_string_pretty( & spaces) ?) ;
582538 }
@@ -610,12 +566,6 @@ async fn handle_commands(
610566 . await ?;
611567 println ! ( "{}" , serde_json:: to_string_pretty( & response) ?) ;
612568 }
613- Commands :: SpaceHash { space } => {
614- println ! (
615- "{}" ,
616- space_hash( & space) . map_err( |e| ClientError :: Custom ( e. to_string( ) ) ) ?
617- ) ;
618- }
619569 Commands :: ForceSpend { outpoint, fee_rate } => {
620570 let result = cli
621571 . client
@@ -627,6 +577,12 @@ async fn handle_commands(
627577 . await ?;
628578 println ! ( "{}" , serde_json:: to_string_pretty( & result) . expect( "result" ) ) ;
629579 }
580+ Commands :: HashSpace { space } => {
581+ println ! (
582+ "{}" ,
583+ hash_space( & space) . map_err( |e| ClientError :: Custom ( e. to_string( ) ) ) ?
584+ ) ;
585+ }
630586 }
631587
632588 Ok ( ( ) )
0 commit comments