Skip to content

Commit

Permalink
Just some notes
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Dec 19, 2024
1 parent f19b727 commit b2d8b20
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
14 changes: 12 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,23 @@ pub struct Inscriptions {
pub page_index: u32,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct OutputRecursive {
pub address: Option<Address<NetworkUnchecked>>,
pub inscriptions: Option<Vec<InscriptionId>>,
pub runes: Option<BTreeMap<SpacedRune, Pile>>,
pub sat_ranges: Option<Vec<(u64, u64)>>,
pub script_pubkey: ScriptBuf,
pub value: u64,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct Output {
pub address: Option<Address<NetworkUnchecked>>,
pub indexed: bool,
pub inscriptions: Vec<InscriptionId>,
pub inscriptions: Option<Vec<InscriptionId>>,
pub outpoint: OutPoint,
pub runes: BTreeMap<SpacedRune, Pile>,
pub runes: Option<BTreeMap<SpacedRune, Pile>>,
pub sat_ranges: Option<Vec<(u64, u64)>>,
pub script_pubkey: ScriptBuf,
pub spent: bool,
Expand Down
78 changes: 38 additions & 40 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,10 @@ impl Server {
) -> ServerResult {
let accept_json = AcceptJson(true);
Self::output(
Extension(server_config),
Extension(index),
Path(outpoint),
accept_json,
Extension(server_config),
Extension(index),
Path(outpoint),
accept_json,
)
.await
}
Expand Down Expand Up @@ -6343,42 +6343,40 @@ next

#[test]
fn output_recursive_endpoint() {
let server = TestServer::builder().chain(Chain::Regtest).build();

server.mine_blocks(1);

let inscription = Inscription {
content_type: Some("text/plain".into()),
body: Some("foo".into()),
..default()
};

let txid = server.core.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0, inscription.to_witness())],
..default()
});

server.mine_blocks(1);

let inscription_id = InscriptionId { txid, index: 0 };
let outpoint: OutPoint = OutPoint { txid, vout: 0 };

let output_response = server.get_json::<api::Output>(
format!("/r/output/{}", outpoint)
);

assert_eq!(output_response.outpoint, outpoint);
assert!(!output_response.spent);
assert!(output_response.indexed);
assert_eq!(output_response.inscriptions, vec![inscription_id]);
assert!(output_response.address.is_some());
assert!(!output_response.script_pubkey.is_empty());
assert_eq!(output_response.transaction, txid);
assert!(output_response.value > 0);
assert!(output_response.runes.is_empty());
if let Some(sat_ranges) = &output_response.sat_ranges {
assert!(!sat_ranges.is_empty());
}
let server = TestServer::builder().chain(Chain::Regtest).build();

server.mine_blocks(1);

let inscription = Inscription {
content_type: Some("text/plain".into()),
body: Some("foo".into()),
..default()
};

let txid = server.core.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0, inscription.to_witness())],
..default()
});

server.mine_blocks(1);

let inscription_id = InscriptionId { txid, index: 0 };
let outpoint: OutPoint = OutPoint { txid, vout: 0 };

let output_response = server.get_json::<api::Output>(format!("/r/output/{}", outpoint));

assert_eq!(output_response.outpoint, outpoint);
assert!(!output_response.spent);
assert!(output_response.indexed);
assert_eq!(output_response.inscriptions, vec![inscription_id]);
assert!(output_response.address.is_some());
assert!(!output_response.script_pubkey.is_empty());
assert_eq!(output_response.transaction, txid);
assert!(output_response.value > 0);
assert!(output_response.runes.is_empty());
if let Some(sat_ranges) = &output_response.sat_ranges {
assert!(!sat_ranges.is_empty());
}
}

#[test]
Expand Down

0 comments on commit b2d8b20

Please sign in to comment.