Skip to content

Commit 4111576

Browse files
committed
Wallet commands clean up. Closes #7
1 parent d4a85fa commit 4111576

File tree

1 file changed

+32
-39
lines changed

1 file changed

+32
-39
lines changed

node/src/bin/space-cli.rs

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ extern crate core;
22

33
use std::{fs, path::PathBuf, str::FromStr};
44

5-
use base64::{prelude::BASE64_STANDARD, Engine};
65
use clap::{Parser, Subcommand};
76
use jsonrpsee::{
87
core::{client::Error, ClientError},
@@ -31,14 +30,14 @@ use wallet::export::WalletExport;
3130
pub struct Args {
3231
/// Bitcoin network to use
3332
#[arg(long, env = "SPACED_CHAIN")]
34-
chain: spaced::config::ExtendedNetwork,
33+
chain: ExtendedNetwork,
3534
/// Spaced RPC URL [default: based on specified chain]
3635
#[arg(long)]
3736
spaced_rpc_url: Option<String>,
3837
/// Specify wallet to use
3938
#[arg(long, short, global = true, default_value = "default")]
4039
wallet: String,
41-
/// Custom dust amount in sat for auction outputs
40+
/// Custom dust amount in sat for bid outputs
4241
#[arg(long, short, global = true)]
4342
dust: Option<u64>,
4443
/// Force invalid transaction (for testing only)
@@ -52,21 +51,15 @@ pub struct Args {
5251
enum Commands {
5352
/// Generate a new wallet
5453
#[command(name = "createwallet")]
55-
CreateWallet {
56-
#[arg(default_value = "default")]
57-
name: String,
58-
},
54+
CreateWallet,
5955
/// Load a wallet
6056
#[command(name = "loadwallet")]
61-
LoadWallet {
62-
#[arg(default_value = "default")]
63-
name: String,
64-
},
57+
LoadWallet,
6558
/// Export a wallet
6659
#[command(name = "exportwallet")]
6760
ExportWallet {
68-
#[arg(default_value = "default")]
69-
name: String,
61+
// Destination path to export json file
62+
path: PathBuf,
7063
},
7164
/// Import a wallet
7265
#[command(name = "importwallet")]
@@ -76,10 +69,7 @@ enum Commands {
7669
},
7770
/// Export a wallet
7871
#[command(name = "getwalletinfo")]
79-
GetWalletInfo {
80-
#[arg(default_value = "default")]
81-
name: String,
82-
},
72+
GetWalletInfo,
8373
/// Export a wallet
8474
#[command(name = "getserverinfo")]
8575
GetServerInfo,
@@ -163,8 +153,8 @@ enum Commands {
163153
#[command(name = "balance")]
164154
Balance,
165155
/// Pre-create outputs that can be auctioned off during the bidding process
166-
#[command(name = "createauctionoutputs")]
167-
CreateAuctionOutputs {
156+
#[command(name = "createbidout")]
157+
CreateBidOut {
168158
/// Number of output pairs to create
169159
/// Each pair can be used to make a bid
170160
pairs: u8,
@@ -195,12 +185,13 @@ enum Commands {
195185
#[arg(default_value = "0")]
196186
target_interval: usize,
197187
},
198-
/// Associate the specified data with a given space (experimental may be removed)
199-
#[command(name = "setdata")]
200-
SetData {
188+
/// Associate the specified data with a given space (not recommended use Fabric instead)
189+
/// If for whatever reason it's not possible to use other protocols, then you may use this.
190+
#[command(name = "setrawfallback")]
191+
SetRawFallback {
201192
/// Space name
202193
space: String,
203-
/// Base64 encoded data
194+
/// Hex encoded data
204195
data: String,
205196
/// Fee rate to use in sat/vB
206197
#[arg(long, short)]
@@ -212,8 +203,8 @@ enum Commands {
212203
ListSpaces,
213204
/// List unspent auction outputs i.e. outputs that can be
214205
/// auctioned off in the bidding process
215-
#[command(name = "listauctionoutputs")]
216-
ListAuctionOutputs,
206+
#[command(name = "listbidouts")]
207+
ListBidOuts,
217208
/// List unspent coins owned by wallet
218209
#[command(name = "listunspent")]
219210
ListUnspent,
@@ -441,24 +432,26 @@ async fn handle_commands(
441432
let response = cli.client.get_spaceout(outpoint).await?;
442433
println!("{}", serde_json::to_string_pretty(&response)?);
443434
}
444-
Commands::CreateWallet { name } => {
445-
cli.client.wallet_create(&name).await?;
435+
Commands::CreateWallet => {
436+
cli.client.wallet_create(&cli.wallet).await?;
446437
}
447-
Commands::LoadWallet { name } => {
448-
cli.client.wallet_load(&name).await?;
438+
Commands::LoadWallet => {
439+
cli.client.wallet_load(&cli.wallet).await?;
449440
}
450441
Commands::ImportWallet { path } => {
451442
let content =
452443
fs::read_to_string(path).map_err(|e| ClientError::Custom(e.to_string()))?;
453444
let wallet: WalletExport = serde_json::from_str(&content)?;
454445
cli.client.wallet_import(wallet).await?;
455446
}
456-
Commands::ExportWallet { name } => {
457-
let result = cli.client.wallet_export(&name).await?;
458-
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
447+
Commands::ExportWallet { path } => {
448+
let result = cli.client.wallet_export(&cli.wallet).await?;
449+
let content = serde_json::to_string_pretty(&result).expect("result");
450+
fs::write(path, content).map_err(|e|
451+
ClientError::Custom(format!("Could not save to path: {}", e.to_string())))?;
459452
}
460-
Commands::GetWalletInfo { name } => {
461-
let result = cli.client.wallet_get_info(&name).await?;
453+
Commands::GetWalletInfo => {
454+
let result = cli.client.wallet_get_info(&cli.wallet).await?;
462455
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
463456
}
464457
Commands::GetServerInfo => {
@@ -495,7 +488,7 @@ async fn handle_commands(
495488
)
496489
.await?
497490
}
498-
Commands::CreateAuctionOutputs { pairs, fee_rate } => {
491+
Commands::CreateBidOut { pairs, fee_rate } => {
499492
cli.send_request(None, Some(pairs), fee_rate).await?
500493
}
501494
Commands::Register {
@@ -544,17 +537,17 @@ async fn handle_commands(
544537
)
545538
.await?
546539
}
547-
Commands::SetData {
540+
Commands::SetRawFallback {
548541
mut space,
549542
data,
550543
fee_rate,
551544
} => {
552545
space = normalize_space(&space);
553-
let data = match BASE64_STANDARD.decode(data) {
546+
let data = match hex::decode(data) {
554547
Ok(data) => data,
555548
Err(e) => {
556549
return Err(ClientError::Custom(format!(
557-
"Could not base64 decode data: {}",
550+
"Could not hex decode data: {}",
558551
e
559552
)))
560553
}
@@ -576,7 +569,7 @@ async fn handle_commands(
576569
let spaces = cli.client.wallet_list_unspent(&cli.wallet).await?;
577570
println!("{}", serde_json::to_string_pretty(&spaces)?);
578571
}
579-
Commands::ListAuctionOutputs => {
572+
Commands::ListBidOuts => {
580573
let spaces = cli.client.wallet_list_auction_outputs(&cli.wallet).await?;
581574
println!("{}", serde_json::to_string_pretty(&spaces)?);
582575
}

0 commit comments

Comments
 (0)