Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit 7cf8564

Browse files
committed
fetch stacks height
1 parent 9643231 commit 7cf8564

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
3+
use reqwest::blocking::Client;
4+
use url::Url;
5+
6+
pub fn stacks_url() -> Url {
7+
let base = env::var("PROJECT_NAME").unwrap();
8+
Url::parse(&format!("http://{base}-stacks-1:20443")).unwrap()
9+
}
10+
11+
pub fn fetch_stacks_height(ctx: &Client) -> u64 {
12+
let endpoint = stacks_url().join("v2/info").unwrap();
13+
14+
let response_json: serde_json::Value =
15+
ctx.get(endpoint).send().unwrap().json().unwrap();
16+
17+
serde_json::from_value(response_json["stacks_tip_height"].clone()).unwrap()
18+
}
19+
20+
// Test fetch stacks info.
21+
#[cfg(test)]
22+
mod test {
23+
use super::*;
24+
25+
#[test]
26+
fn fetch_height() {
27+
let ctx = Client::new();
28+
fetch_stacks_height(&ctx);
29+
}
30+
}

0 commit comments

Comments
 (0)