Expose public resolution lifecycle and preserve arbitration after a reset

This commit is contained in:
2026-12-03 12:21:20 +08:00
parent 220978ec83
commit 5696e3dae2
12 changed files with 379 additions and 60 deletions
+35 -2
View File
@@ -1,5 +1,5 @@
use anyhow::{ensure, Result};
use rusqlite::Transaction;
use anyhow::{ensure, Context, Result};
use rusqlite::{Connection, Transaction};
pub(crate) fn identifier(id: &str) -> Result<()> {
ensure!(
!id.trim().is_empty() && id.trim().chars().count() <= 256,
@@ -46,3 +46,36 @@ impl IdSelector {
Ok(ids)
}
}
pub(crate) fn directory_selector(
db: &Connection,
raw: Option<&str>,
numeric: bool,
) -> Result<Option<IdSelector>> {
raw.map(|raw| {
let mut keys = Vec::new();
for id in raw.split(',').map(str::trim) {
identifier(id)?;
if numeric {
let n = id.parse::<i64>().context("invalid event_id")?;
ensure!(n > 0, "invalid event_id");
keys.push(n.to_string());
} else {
if id.starts_with("0x")
&& !(id.len() == 66 && id[2..].bytes().all(|b| b.is_ascii_hexdigit()))
{
// Locally listed condition IDs may legitimately use a short 0x prefix.
let listed: bool = db.query_row(
"SELECT EXISTS(SELECT 1 FROM markets WHERE id=?1)",
[id],
|r| r.get(0),
)?;
ensure!(listed, "invalid condition: {id}");
}
keys.push(id.to_owned());
}
}
Ok(IdSelector::Many(keys))
})
.transpose()
}