From 19f4e015d65dfd61c1049c9c5b8a1c443bdd42c3 Mon Sep 17 00:00:00 2001 From: Ruan Pingcheng Date: Mon, 2 Sep 2024 13:59:05 +0800 Subject: [PATCH 1/2] default 0 equity for missing token --- crates/zk-por-core/src/parser.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/zk-por-core/src/parser.rs b/crates/zk-por-core/src/parser.rs index ffc89dc..291d1ff 100644 --- a/crates/zk-por-core/src/parser.rs +++ b/crates/zk-por-core/src/parser.rs @@ -260,26 +260,22 @@ pub fn parse_account_state(parsed_data: &Map, tokens: &Vec().unwrap()); - parsed_equities.push(parsed_equity); - } else { - panic!("fail to find equity for token: {:?} in accountID {:?}", token, account_id); + parsed_equity = F::from_canonical_u64(val.as_str().unwrap().parse::().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() { + let mut parsed_debt = F::ZERO; if let Some(val) = debts.get(token) { - let parsed_debt = - F::from_canonical_u64(val.as_str().unwrap().parse::().unwrap()); - parsed_debts.push(parsed_debt); - } else { - panic!("fail to find debt for token: {:?} in accountID {:?}", token, account_id); + parsed_debt = F::from_canonical_u64(val.as_str().unwrap().parse::().unwrap()); } + parsed_debts.push(parsed_debt); } } else { // if there is no debt, we fill it with zero From a7bef3ac9a0089717e57d55e4646fbd4344415a1 Mon Sep 17 00:00:00 2001 From: Ruan Pingcheng Date: Mon, 2 Sep 2024 14:05:35 +0800 Subject: [PATCH 2/2] change to rust format --- crates/zk-por-core/src/parser.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/zk-por-core/src/parser.rs b/crates/zk-por-core/src/parser.rs index 291d1ff..55e703c 100644 --- a/crates/zk-por-core/src/parser.rs +++ b/crates/zk-por-core/src/parser.rs @@ -260,10 +260,9 @@ pub fn parse_account_state(parsed_data: &Map, tokens: &Vec().unwrap()); - } + let parsed_equity = equities.get(token).map_or(F::ZERO, |val| { + F::from_canonical_u64(val.as_str().unwrap().parse::().unwrap()) + }); parsed_equities.push(parsed_equity); } @@ -271,10 +270,9 @@ pub fn parse_account_state(parsed_data: &Map, tokens: &Vec().unwrap()); - } + let parsed_debt = debts.get(token).map_or(F::ZERO, |val| { + F::from_canonical_u64(val.as_str().unwrap().parse::().unwrap()) + }); parsed_debts.push(parsed_debt); } } else {