Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supercharge Inscriptions with Runes #3538

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
45 changes: 45 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ impl Server {
"/r/inscription/:inscription_id",
get(Self::inscription_recursive),
)
.route(
"/r/inscription/:inscription_id/rune/:rune_id",
get(Self::inscription_rune),
)
.route("/r/children/:inscription_id", get(Self::children_recursive))
.route(
"/r/children/:inscription_id/:page",
Expand Down Expand Up @@ -990,6 +994,47 @@ impl Server {
})
}

async fn inscription_rune(
Extension(index): Extension<Arc<Index>>,
Path((inscription_id, rune_id)): Path<(InscriptionId, RuneId)>,
) -> ServerResult {
task::block_in_place(|| {
index
.get_inscription_by_id(inscription_id)?
.ok_or_not_found(|| format!("inscription {inscription_id}"))?;

let satpoint = index
.get_inscription_satpoint_by_id(inscription_id)
.ok()
.flatten()
.unwrap();

let rune = index
.get_rune_by_id(rune_id)?
.ok_or_not_found(|| format!("rune {rune_id}"))?;

let (_, rune_entry, _) = index
.rune(rune)?
.ok_or_not_found(|| format!("rune {rune}"))?;

let runes = index.get_rune_balances_for_outpoint(satpoint.outpoint)?;

let pile = runes.into_iter()
.find_map(|(spaced_rune, pile)| {
if spaced_rune.rune == rune {
Some(pile)
} else {
None
}
})
.unwrap_or_else(|| rune_entry.pile(0));

Ok(
Json(pile).into_response()
)
})
}

async fn status(
Extension(server_config): Extension<Arc<ServerConfig>>,
Extension(index): Extension<Arc<Index>>,
Expand Down
Loading