Skip to content

Commit

Permalink
Merge pull request #74 from okx/feature/ruanpc/default_token_equity
Browse files Browse the repository at this point in the history
default 0 equity for missing token
  • Loading branch information
cliff0412 authored Sep 2, 2024
2 parents 51db482 + a7bef3a commit b0ecc5f
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions crates/zk-por-core/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,26 +260,20 @@ pub fn parse_account_state(parsed_data: &Map<String, Value>, tokens: &Vec<String
.unwrap();
let mut parsed_equities = Vec::new();
for token in tokens.iter() {
if let Some(val) = equities.get(token) {
let parsed_equity =
F::from_canonical_u64(val.as_str().unwrap().parse::<u64>().unwrap());
parsed_equities.push(parsed_equity);
} else {
panic!("fail to find equity for token: {:?} in accountID {:?}", token, account_id);
}
let parsed_equity = equities.get(token).map_or(F::ZERO, |val| {
F::from_canonical_u64(val.as_str().unwrap().parse::<u64>().unwrap())
});
parsed_equities.push(parsed_equity);
}

let mut parsed_debts = Vec::new();
if let Some(debts) = parsed_data.get("debt") {
let debts = debts.as_object().unwrap();
for token in tokens.iter() {
if let Some(val) = debts.get(token) {
let parsed_debt =
F::from_canonical_u64(val.as_str().unwrap().parse::<u64>().unwrap());
parsed_debts.push(parsed_debt);
} else {
panic!("fail to find debt for token: {:?} in accountID {:?}", token, account_id);
}
let parsed_debt = debts.get(token).map_or(F::ZERO, |val| {
F::from_canonical_u64(val.as_str().unwrap().parse::<u64>().unwrap())
});
parsed_debts.push(parsed_debt);
}
} else {
// if there is no debt, we fill it with zero
Expand Down

0 comments on commit b0ecc5f

Please sign in to comment.