Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions client/src/bin/space-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,25 +780,25 @@ async fn handle_commands(cli: &SpaceCli, command: Commands) -> Result<(), Client
ClientError::Custom(format!("Failed to read stdin: {}", e)))?;
let record_set: sip7::RecordSet = serde_json::from_str(input.trim())
.map_err(|e| ClientError::Custom(format!("Invalid SIP-7 JSON: {}", e)))?;
record_set.encode()
record_set.to_bytes()
} else if !txt_records.is_empty() || !blob_records.is_empty() {
// Build from --txt and --blob flags
let mut record_set = sip7::RecordSet::new();
let mut records = Vec::new();
for txt in &txt_records {
let (key, value) = txt.split_once('=').ok_or_else(||
ClientError::Custom(format!("Invalid --txt format '{}': expected key=value", txt)))?;
record_set.push_txt(key, value).map_err(|e|
ClientError::Custom(format!("Invalid TXT record: {}", e)))?;
records.push(sip7::Record::txt(key, value));
}
for blob in &blob_records {
let (key, b64_value) = blob.split_once('=').ok_or_else(||
ClientError::Custom(format!("Invalid --blob format '{}': expected key=base64", blob)))?;
let value = base64::engine::general_purpose::STANDARD.decode(b64_value)
.map_err(|e| ClientError::Custom(format!("Invalid base64 in --blob '{}': {}", key, e)))?;
record_set.push_blob(key, value).map_err(|e|
ClientError::Custom(format!("Invalid BLOB record: {}", e)))?;
records.push(sip7::Record::blob(key, value));
}
record_set.encode()
sip7::RecordSet::pack(records)
.map_err(|e| ClientError::Custom(format!("Invalid record: {}", e)))?
.to_bytes()
} else {
return Err(ClientError::Custom(
"No data specified. Use --txt, --blob, --raw, or --stdin".to_string()
Expand Down
3 changes: 2 additions & 1 deletion client/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,8 @@ impl RpcServer for RpcServerImpl {
Some(raw) => {
use base64::Engine;
let encoded = base64::engine::general_purpose::STANDARD.encode(&raw);
let records = sip7::RecordSet::decode(&raw).ok();
let rs = sip7::RecordSet::new(raw);
let records = if rs.unpack().is_ok() { Some(rs) } else { None };
Ok(Some(FallbackResponse {
data: encoded,
records,
Expand Down
20 changes: 11 additions & 9 deletions client/tests/ptr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,10 +920,11 @@ async fn it_should_set_and_get_space_fallback(rig: &TestRig) -> anyhow::Result<(

// Test 1: Set SIP-7 fallback data on the space
println!("\nTest 1: Set SIP-7 fallback data on space");
let mut records = sip7::RecordSet::new();
records.push_txt("btc", "bc1qtest").unwrap();
records.push_txt("nostr", "npub1abc").unwrap();
let wire_data = records.encode();
let records = sip7::RecordSet::pack(vec![
sip7::Record::txt("btc", "bc1qtest"),
sip7::Record::txt("nostr", "npub1abc"),
]).unwrap();
let wire_data = records.as_slice().to_vec();

let set_result = wallet_do(
rig,
Expand Down Expand Up @@ -961,7 +962,7 @@ async fn it_should_set_and_get_space_fallback(rig: &TestRig) -> anyhow::Result<(
let fallback = rig.spaced.client.get_fallback(subject.clone()).await?
.expect("getfallback should return data");
let parsed = fallback.records.expect("should parse as SIP-7 records");
assert_eq!(parsed.records().len(), 2, "should have 2 records");
assert_eq!(parsed.unpack().unwrap().len(), 2, "should have 2 records");
println!("✓ getfallback returns parsed SIP-7 records");

// Test 2: Alice can still transfer the space after setfallback
Expand All @@ -988,9 +989,10 @@ async fn it_should_set_and_get_space_fallback(rig: &TestRig) -> anyhow::Result<(

// Test 3: Bob can overwrite the fallback data
println!("\nTest 3: Bob overwrites fallback data");
let mut new_records = sip7::RecordSet::new();
new_records.push_txt("eth", "0xdeadbeef").unwrap();
let new_wire = new_records.encode();
let new_records = sip7::RecordSet::pack(vec![
sip7::Record::txt("eth", "0xdeadbeef"),
]).unwrap();
let new_wire = new_records.as_slice().to_vec();

let bob_set = wallet_do(
rig,
Expand All @@ -1007,7 +1009,7 @@ async fn it_should_set_and_get_space_fallback(rig: &TestRig) -> anyhow::Result<(
let fallback_bob = rig.spaced.client.get_fallback(subject).await?
.expect("should have fallback data");
let bob_parsed = fallback_bob.records.expect("should parse as SIP-7");
assert_eq!(bob_parsed.records().len(), 1, "should have 1 record now");
assert_eq!(bob_parsed.unpack().unwrap().len(), 1, "should have 1 record now");
println!("✓ Bob successfully overwrote fallback data");

Ok(())
Expand Down
Loading
Loading