Skip to content

Commit 32e6456

Browse files
committed
merge main
2 parents f2eb07e + f664298 commit 32e6456

23 files changed

+1515
-1543
lines changed

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/src/bin/space-cli.rs

Lines changed: 72 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ 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},
98
http_client::{HttpClient, HttpClientBuilder},
109
};
1110
use protocol::{
1211
bitcoin::{Amount, FeeRate, OutPoint, Txid},
13-
hasher::{KeyHasher, SpaceKey},
14-
opcodes::OP_SETALL,
15-
sname::{NameLike, SName},
16-
Covenant, FullSpaceOut,
12+
hasher::KeyHasher,
13+
slabel::SLabel,
1714
};
1815
use serde::{Deserialize, Serialize};
1916
use spaced::{
@@ -32,14 +29,14 @@ use wallet::export::WalletExport;
3229
pub struct Args {
3330
/// Bitcoin network to use
3431
#[arg(long, env = "SPACED_CHAIN")]
35-
chain: spaced::config::ExtendedNetwork,
32+
chain: ExtendedNetwork,
3633
/// Spaced RPC URL [default: based on specified chain]
3734
#[arg(long)]
3835
spaced_rpc_url: Option<String>,
3936
/// Specify wallet to use
4037
#[arg(long, short, global = true, default_value = "default")]
4138
wallet: String,
42-
/// Custom dust amount in sat for auction outputs
39+
/// Custom dust amount in sat for bid outputs
4340
#[arg(long, short, global = true)]
4441
dust: Option<u64>,
4542
/// Force invalid transaction (for testing only)
@@ -53,21 +50,15 @@ pub struct Args {
5350
enum Commands {
5451
/// Generate a new wallet
5552
#[command(name = "createwallet")]
56-
CreateWallet {
57-
#[arg(default_value = "default")]
58-
name: String,
59-
},
53+
CreateWallet,
6054
/// Load a wallet
6155
#[command(name = "loadwallet")]
62-
LoadWallet {
63-
#[arg(default_value = "default")]
64-
name: String,
65-
},
56+
LoadWallet,
6657
/// Export a wallet
6758
#[command(name = "exportwallet")]
6859
ExportWallet {
69-
#[arg(default_value = "default")]
70-
name: String,
60+
// Destination path to export json file
61+
path: PathBuf,
7162
},
7263
/// Import a wallet
7364
#[command(name = "importwallet")]
@@ -77,10 +68,7 @@ enum Commands {
7768
},
7869
/// Export a wallet
7970
#[command(name = "getwalletinfo")]
80-
GetWalletInfo {
81-
#[arg(default_value = "default")]
82-
name: String,
83-
},
71+
GetWalletInfo,
8472
/// Export a wallet
8573
#[command(name = "getserverinfo")]
8674
GetServerInfo,
@@ -164,8 +152,8 @@ enum Commands {
164152
#[command(name = "balance")]
165153
Balance,
166154
/// Pre-create outputs that can be auctioned off during the bidding process
167-
#[command(name = "createauctionoutputs")]
168-
CreateAuctionOutputs {
155+
#[command(name = "createbidouts")]
156+
CreateBidOuts {
169157
/// Number of output pairs to create
170158
/// Each pair can be used to make a bid
171159
pairs: u8,
@@ -188,20 +176,21 @@ enum Commands {
188176
outpoint: OutPoint,
189177
},
190178
/// Get the estimated rollout batch for the specified interval
191-
#[command(name = "getrolloutestimate")]
192-
GetRolloutEstimate {
179+
#[command(name = "getrollout")]
180+
GetRollout {
193181
// Get the estimated rollout for the target interval. Every ~144 blocks (a rollout interval),
194182
// 10 spaces are released for auction. Specify 0 [default] for the coming interval, 1
195183
// for the interval after and so on.
196184
#[arg(default_value = "0")]
197185
target_interval: usize,
198186
},
199-
/// Associate the specified data with a given space (experimental may be removed)
200-
#[command(name = "setdata")]
201-
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 {
202191
/// Space name
203192
space: String,
204-
/// Base64 encoded data
193+
/// Hex encoded data
205194
data: String,
206195
/// Fee rate to use in sat/vB
207196
#[arg(long, short)]
@@ -221,8 +210,8 @@ enum Commands {
221210
ListSpaces,
222211
/// List unspent auction outputs i.e. outputs that can be
223212
/// auctioned off in the bidding process
224-
#[command(name = "listauctionoutputs")]
225-
ListAuctionOutputs,
213+
#[command(name = "listbidouts")]
214+
ListBidOuts,
226215
/// List unspent coins owned by wallet
227216
#[command(name = "listunspent")]
228217
ListUnspent,
@@ -234,12 +223,16 @@ enum Commands {
234223
/// compatible with most bitcoin wallets
235224
#[command(name = "getnewaddress")]
236225
GetCoinAddress,
237-
/// Calculate a spacehash from the specified space name
238-
#[command(name = "spacehash")]
239-
SpaceHash {
240-
/// The space name
241-
space: String,
226+
/// Force spend an output owned by wallet (for testing only)
227+
#[command(name = "forcespend")]
228+
ForceSpend {
229+
outpoint: OutPoint,
230+
#[arg(long, short)]
231+
fee_rate: u64,
242232
},
233+
/// DNS encodes the space and calculates the SHA-256 hash
234+
#[command(name = "hashspace")]
235+
HashSpace { space: String },
243236
}
244237

245238
struct SpaceCli {
@@ -275,7 +268,7 @@ impl SpaceCli {
275268
async fn send_request(
276269
&self,
277270
req: Option<RpcWalletRequest>,
278-
auction_outputs: Option<u8>,
271+
bidouts: Option<u8>,
279272
fee_rate: Option<u64>,
280273
) -> Result<(), ClientError> {
281274
let fee_rate = fee_rate.map(|fee| FeeRate::from_sat_per_vb(fee).unwrap());
@@ -284,7 +277,7 @@ impl SpaceCli {
284277
.wallet_send_request(
285278
&self.wallet,
286279
RpcWalletTxBuilder {
287-
auction_outputs,
280+
bidouts,
288281
requests: match req {
289282
None => vec![],
290283
Some(req) => vec![req],
@@ -378,89 +371,57 @@ async fn main() -> anyhow::Result<()> {
378371
Ok(())
379372
}
380373

381-
fn space_hash(spaceish: &str) -> anyhow::Result<String> {
374+
fn hash_space(spaceish: &str) -> anyhow::Result<String> {
382375
let space = normalize_space(&spaceish);
383-
let sname = SName::from_str(&space)?;
384-
let spacehash = SpaceKey::from(Sha256::hash(sname.to_bytes()));
385-
Ok(hex::encode(spacehash.as_slice()))
376+
let sname = SLabel::from_str(&space)?;
377+
Ok(hex::encode(Sha256::hash(sname.as_ref())))
386378
}
387379

388380
async fn handle_commands(
389381
cli: &SpaceCli,
390382
command: Commands,
391383
) -> std::result::Result<(), ClientError> {
392384
match command {
393-
Commands::GetRolloutEstimate {
385+
Commands::GetRollout {
394386
target_interval: target,
395387
} => {
396-
let hashes = cli.client.get_rollout(target).await?;
397-
let mut spaceouts = Vec::with_capacity(hashes.len());
398-
for (priority, spacehash) in hashes {
399-
let outpoint = cli
400-
.client
401-
.get_space_owner(&hex::encode(spacehash.as_slice()))
402-
.await?;
403-
404-
if let Some(outpoint) = outpoint {
405-
if let Some(spaceout) = cli.client.get_spaceout(outpoint).await? {
406-
spaceouts.push((
407-
priority,
408-
FullSpaceOut {
409-
txid: outpoint.txid,
410-
spaceout,
411-
},
412-
));
413-
}
414-
}
415-
}
416-
417-
let data: Vec<_> = spaceouts
418-
.into_iter()
419-
.map(|(priority, spaceout)| {
420-
let space = spaceout.spaceout.space.unwrap();
421-
(
422-
space.name.to_string(),
423-
match space.covenant {
424-
Covenant::Bid { .. } => priority,
425-
_ => 0,
426-
},
427-
)
428-
})
429-
.collect();
430-
388+
let data = cli.client.get_rollout(target).await?;
431389
println!("{}", serde_json::to_string_pretty(&data)?);
432390
}
433391
Commands::EstimateBid { target } => {
434392
let response = cli.client.estimate_bid(target).await?;
435393
println!("{} sat", Amount::from_sat(response).to_string());
436394
}
437395
Commands::GetSpace { space } => {
438-
let space_hash = space_hash(&space).map_err(|e| ClientError::Custom(e.to_string()))?;
396+
let space_hash = hash_space(&space).map_err(|e| ClientError::Custom(e.to_string()))?;
439397
let response = cli.client.get_space(&space_hash).await?;
440398
println!("{}", serde_json::to_string_pretty(&response)?);
441399
}
442400
Commands::GetSpaceOut { outpoint } => {
443401
let response = cli.client.get_spaceout(outpoint).await?;
444402
println!("{}", serde_json::to_string_pretty(&response)?);
445403
}
446-
Commands::CreateWallet { name } => {
447-
cli.client.wallet_create(&name).await?;
404+
Commands::CreateWallet => {
405+
cli.client.wallet_create(&cli.wallet).await?;
448406
}
449-
Commands::LoadWallet { name } => {
450-
cli.client.wallet_load(&name).await?;
407+
Commands::LoadWallet => {
408+
cli.client.wallet_load(&cli.wallet).await?;
451409
}
452410
Commands::ImportWallet { path } => {
453411
let content =
454412
fs::read_to_string(path).map_err(|e| ClientError::Custom(e.to_string()))?;
455413
let wallet: WalletExport = serde_json::from_str(&content)?;
456414
cli.client.wallet_import(wallet).await?;
457415
}
458-
Commands::ExportWallet { name } => {
459-
let result = cli.client.wallet_export(&name).await?;
460-
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
416+
Commands::ExportWallet { path } => {
417+
let result = cli.client.wallet_export(&cli.wallet).await?;
418+
let content = serde_json::to_string_pretty(&result).expect("result");
419+
fs::write(path, content).map_err(|e| {
420+
ClientError::Custom(format!("Could not save to path: {}", e.to_string()))
421+
})?;
461422
}
462-
Commands::GetWalletInfo { name } => {
463-
let result = cli.client.wallet_get_info(&name).await?;
423+
Commands::GetWalletInfo => {
424+
let result = cli.client.wallet_get_info(&cli.wallet).await?;
464425
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
465426
}
466427
Commands::GetServerInfo => {
@@ -497,7 +458,7 @@ async fn handle_commands(
497458
)
498459
.await?
499460
}
500-
Commands::CreateAuctionOutputs { pairs, fee_rate } => {
461+
Commands::CreateBidOuts { pairs, fee_rate } => {
501462
cli.send_request(None, Some(pairs), fee_rate).await?
502463
}
503464
Commands::Register {
@@ -546,28 +507,28 @@ async fn handle_commands(
546507
)
547508
.await?
548509
}
549-
Commands::SetData {
510+
Commands::SetRawFallback {
550511
mut space,
551512
data,
552513
fee_rate,
553514
} => {
554515
space = normalize_space(&space);
555-
let data = match BASE64_STANDARD.decode(data) {
516+
let data = match hex::decode(data) {
556517
Ok(data) => data,
557518
Err(e) => {
558519
return Err(ClientError::Custom(format!(
559-
"Could not base64 decode data: {}",
520+
"Could not hex decode data: {}",
560521
e
561522
)))
562523
}
563524
};
564-
let builder = protocol::script::ScriptBuilder::new()
565-
.push_slice(data.as_slice())
566-
.push_opcode(OP_SETALL.into());
525+
526+
let space_script = protocol::script::SpaceScript::create_set_fallback(data.as_slice());
527+
567528
cli.send_request(
568529
Some(RpcWalletRequest::Execute(ExecuteParams {
569530
context: vec![space],
570-
space_script: builder,
531+
space_script,
571532
})),
572533
None,
573534
fee_rate,
@@ -578,8 +539,8 @@ async fn handle_commands(
578539
let spaces = cli.client.wallet_list_unspent(&cli.wallet).await?;
579540
println!("{}", serde_json::to_string_pretty(&spaces)?);
580541
}
581-
Commands::ListAuctionOutputs => {
582-
let spaces = cli.client.wallet_list_auction_outputs(&cli.wallet).await?;
542+
Commands::ListBidOuts => {
543+
let spaces = cli.client.wallet_list_bidouts(&cli.wallet).await?;
583544
println!("{}", serde_json::to_string_pretty(&spaces)?);
584545
}
585546
Commands::ListTransactions { count, skip } => {
@@ -619,10 +580,21 @@ async fn handle_commands(
619580
.await?;
620581
println!("{}", serde_json::to_string_pretty(&response)?);
621582
}
622-
Commands::SpaceHash { space } => {
583+
Commands::ForceSpend { outpoint, fee_rate } => {
584+
let result = cli
585+
.client
586+
.wallet_force_spend(
587+
&cli.wallet,
588+
outpoint,
589+
FeeRate::from_sat_per_vb(fee_rate).unwrap(),
590+
)
591+
.await?;
592+
println!("{}", serde_json::to_string_pretty(&result).expect("result"));
593+
}
594+
Commands::HashSpace { space } => {
623595
println!(
624596
"{}",
625-
space_hash(&space).map_err(|e| ClientError::Custom(e.to_string()))?
597+
hash_space(&space).map_err(|e| ClientError::Custom(e.to_string()))?
626598
);
627599
}
628600
}

node/src/bin/spaced.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Composer {
128128
}
129129

130130
async fn run(&mut self) -> anyhow::Result<()> {
131-
let spaced = Args::configure()?;
131+
let spaced = Args::configure().await?;
132132
self.setup_rpc_services(&spaced).await;
133133
self.setup_sync_service(spaced).await;
134134

0 commit comments

Comments
 (0)