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
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions bins/ctx/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,7 @@ pub async fn topics(client: &Client, json_out: bool) -> Result<(), String> {
if json_out {
return Ok(());
}
let items = reply
.body
.as_array()
.or_else(|| reply.body.get("topics").and_then(Value::as_array));
let items = topic_list_items(&reply.body);
match items {
Some(list) if list.is_empty() => {
println!("No open topics. Submits answer 503 until an operator publishes one.");
Expand Down Expand Up @@ -245,6 +242,14 @@ fn print_fields(body: &Value) {
}
}

/// `GET /v1/proof/topics` returns `{ "items": [...] }`. Older shapes used
/// a bare array or `{ "topics": [...] }`.
fn topic_list_items(body: &Value) -> Option<&Vec<Value>> {
body.as_array()
.or_else(|| body.get("items").and_then(Value::as_array))
.or_else(|| body.get("topics").and_then(Value::as_array))
}

fn explain_failure(status: u16, message: &str) -> String {
match status {
400 => format!("refused ({message}). Nothing was stored and nothing was rented."),
Expand Down Expand Up @@ -287,4 +292,18 @@ mod tests {
let ok = "a".repeat(64);
assert_eq!(normalize_hex64(&ok, "hotkey").unwrap(), ok);
}

#[test]
fn topic_list_reads_the_items_wrapper() {
let body = serde_json::json!({
"items": [
{ "id": "dt-no-ib-v0", "status": "open", "payout_mode": "wta" },
{ "id": "muon-vs-adamw-10m-v0", "status": "open", "payout_mode": "wta" }
]
});
let items = topic_list_items(&body).expect("items");
assert_eq!(items.len(), 2);
assert_eq!(items[0]["id"], "dt-no-ib-v0");
assert_eq!(items[1]["id"], "muon-vs-adamw-10m-v0");
}
}
7 changes: 7 additions & 0 deletions bins/proof-challenge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@ telemetry = { path = "../../crates/telemetry" }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "signal"] }
tracing = "0.1"

[dev-dependencies]
crypto = { path = "../../crates/crypto" }
hex = "0.4"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "json"] }
sha2 = "0.10"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "process", "time"] }

[lints]
workspace = true
Loading