Skip to content

Commit

Permalink
update height (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiannian authored Apr 13, 2023
1 parent e36e7a3 commit 5f4b933
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ lazy_static! {
evm_substate_v2_height: 3351349,
disable_delegate_frc20: 3401450,
fix_exec_code: 3401450,
check_signatures_num: 5000_0000,
fix_deliver_tx_revert_nonce_height: 4000_0000,
utxo_asset_prefix_height: 5000_0000,
prismxx_inital_height: 5000_0000,
prism_bridge_address: String::new(),
remove_fake_staking_hash: 5000_0000,
fix_check_replay: 5000_0000
check_signatures_num: 4033522,
fix_deliver_tx_revert_nonce_height: 4033522,
utxo_asset_prefix_height: 4033522,
prismxx_inital_height: 4033522,
prism_bridge_address: "0x4672372fDB139B7295Fc59b55b43EC5fF2761A0b".to_owned(),
remove_fake_staking_hash: 4033522,
fix_check_replay: 4033522
};
}

Expand Down
21 changes: 15 additions & 6 deletions src/components/finutils/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,14 +587,23 @@ fn restore_keypair_from_str_with_default(sk_str: Option<&str>) -> Result<XfrKeyP
}

/// Show the asset balance of a findora account
pub fn show_account(sk_str: Option<&str>, asset: Option<&str>) -> Result<()> {
pub fn show_account(sk_str: Option<&str>, _asset: Option<&str>) -> Result<()> {
let kp = restore_keypair_from_str_with_default(sk_str)?;
let token_code = asset
.map(|asset| AssetTypeCode::new_from_base64(asset).c(d!("Invalid asset code")))
.transpose()?;
let balance = utils::get_asset_balance(&kp, token_code).c(d!())?;
// let token_code = asset
// .map(|asset| AssetTypeCode::new_from_base64(asset).c(d!("Invalid asset code")))
// .transpose()?;
// let balance = utils::get_asset_balance(&kp, token_code).c(d!())?;
//
// println!("{}: {}", asset.unwrap_or("FRA"), balance);

let res = utils::get_asset_all(&kp)?;

for (k, v) in res {
let codes = k.to_base64();

println!("{codes}: {v}");
}

println!("{}: {}", asset.unwrap_or("FRA"), balance);
Ok(())
}

Expand Down
26 changes: 26 additions & 0 deletions src/components/finutils/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! Some handful function and data structure for findora cli tools
//!
use std::collections::BTreeMap;

use {
crate::{
api::{DelegationInfo, ValidatorDetail},
Expand Down Expand Up @@ -467,6 +469,30 @@ pub fn get_asset_balance(kp: &XfrKeyPair, asset: Option<AssetTypeCode>) -> Resul
Ok(balance)
}

/// Retrieve Utxos of a findora keypair and calcultate the balance of the specified asset
/// FRA is the default asset type
pub fn get_asset_all(kp: &XfrKeyPair) -> Result<BTreeMap<AssetTypeCode, u64>> {
let info = get_owned_utxos(kp.get_pk_ref())?;

let mut set = BTreeMap::new();

for (_k, v) in info {
let res = open_blind_asset_record(&v.0 .0.record, &v.1, kp)?;

let code = AssetTypeCode {
val: res.asset_type,
};

if let Some(amount) = set.get_mut(&code) {
*amount += res.amount;
} else {
set.insert(code, res.amount);
}
}

Ok(set)
}

fn get_owned_utxos(
addr: &XfrPublicKey,
) -> Result<HashMap<TxoSID, (Utxo, Option<OwnerMemo>)>> {
Expand Down

0 comments on commit 5f4b933

Please sign in to comment.