Skip to content

Commit

Permalink
fix: update limit param to 100 for the geniidata API for BRC20 VC (#2849
Browse files Browse the repository at this point in the history
)

* fix: update limit param to 100 for the geniidata API for BRC20 VC and change it to pagination query

* fix: change type of GENIIDATA_QUERY_LIMIT to u32, update geniidata mock server to return empty response while offset param is not 0

* fix: update geniidata mock server to return empty response while offset param is not 0 or empty

---------

Co-authored-by: higherordertech <higherordertech>
  • Loading branch information
higherordertech committed Jul 1, 2024
1 parent 0f6d532 commit 03f7c4a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
42 changes: 27 additions & 15 deletions tee-worker/litentry/core/data-providers/src/geniidata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct ResponseItem {

#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseData {
pub count: u64,
pub count: u32,
pub limit: String,
pub offset: String,
pub list: Vec<ResponseItem>,
Expand All @@ -68,8 +68,8 @@ impl RestPath<String> for GeniidataResponse {
}
}

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

pub struct GeniidataClient {
client: RestClient<HttpClient<SendWithCertificateVerification>>,
Expand Down Expand Up @@ -98,18 +98,30 @@ impl GeniidataClient {
loop_with_abort_strategy::<fn(&_) -> bool, String, DataProviderError>(
addresses,
|address| {
let query =
vec![("limit", GENIIDATA_QUERY_LIMIT), ("offset", "0"), ("address", address)];
let response = self
.client
.get_with::<String, GeniidataResponse>("".to_string(), query.as_slice())
.map_err(|e| {
DataProviderError::GeniiDataError(format!(
"GeniiData response error: {}",
e
))
})?;
all_items.extend(response.data.list);
let mut offset: u32 = 0;
loop {
let limit_str = GENIIDATA_QUERY_LIMIT.to_string();
let offset_str = offset.to_string();
let query = vec![
("limit", limit_str.as_str()),
("offset", offset_str.as_str()),
("address", address),
];
let response = self
.client
.get_with::<String, GeniidataResponse>("".to_string(), query.as_slice())
.map_err(|e| {
DataProviderError::GeniiDataError(format!(
"GeniiData response error: {}",
e
))
})?;
all_items.extend(response.data.list);
if offset >= response.data.count {
break
}
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.is_empty() && 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 03f7c4a

Please sign in to comment.