Skip to content

Commit

Permalink
fix: change type of GENIIDATA_QUERY_LIMIT to u32, update geniidata mo…
Browse files Browse the repository at this point in the history
…ck server to return empty response while offset param is not 0
  • Loading branch information
higherordertech committed Jul 1, 2024
1 parent cdbfebe commit 0f9f8b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tee-worker/litentry/core/data-providers/src/geniidata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl RestPath<String> for GeniidataResponse {
}

// According to https://geniidata.readme.io/reference/get-brc20-tick-list-copy, the maximum limit is 100
const GENIIDATA_QUERY_LIMIT: &str = "100";
const GENIIDATA_QUERY_LIMIT: u32 = 100;

pub struct GeniidataClient {
client: RestClient<HttpClient<SendWithCertificateVerification>>,
Expand Down Expand Up @@ -100,9 +100,10 @@ impl GeniidataClient {
|address| {
let mut offset: u32 = 0;
loop {
let limit_str = GENIIDATA_QUERY_LIMIT.to_string();
let offset_str = offset.to_string();
let query = vec![
("limit", GENIIDATA_QUERY_LIMIT),
("limit", limit_str.as_str()),
("offset", offset_str.as_str()),
("address", address),
];
Expand All @@ -119,7 +120,7 @@ impl GeniidataClient {
if offset >= response.data.count {
break
}
offset += GENIIDATA_QUERY_LIMIT.parse::<u32>().unwrap();
offset += GENIIDATA_QUERY_LIMIT;
}

Ok(LoopControls::Continue)
Expand Down
20 changes: 19 additions & 1 deletion tee-worker/litentry/core/mock-server/src/geniidata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,33 @@ use lc_data_providers::geniidata::{GeniidataResponse, ResponseData, ResponseItem
use std::{collections::HashMap, vec::Vec};
use warp::{http::Response, Filter};

const EMPTY_RESPONSE: &str = r#"
{
"code": 0,
"message": "success",
"data": {
"count": 1,
"limit": "20",
"offset": "0",
"list": []
}
}
"#;

pub(crate) fn query() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
warp::get()
.and(warp::path!("api" / "1" / "brc20" / "balance"))
.and(warp::query::<HashMap<String, String>>())
.map(|params: HashMap<String, String>| {
let default = String::default();
let offset = params.get("offset").unwrap_or(&default).as_str();
let tick = params.get("tick").unwrap_or(&default).as_str();
let address = params.get("address").unwrap_or(&default).as_str();

if offset != "0" {
return Response::builder().body(EMPTY_RESPONSE.to_string())
}

let _expected_address =
"bc1pgr5fw4p9gl9me0vzjklnlnap669caxc0gsk4j62gff2qktlw6naqm4m3d0";

Expand Down Expand Up @@ -88,7 +106,7 @@ pub(crate) fn query() -> impl Filter<Extract = impl warp::Reply, Error = warp::R
code: 0,
message: "success".to_string(),
data: ResponseData {
count: 16435,
count: 3,
limit: "20".to_string(),
offset: "0".to_string(),
list,
Expand Down

0 comments on commit 0f9f8b2

Please sign in to comment.