Skip to content

Commit

Permalink
Add deposit hash to history (#55)
Browse files Browse the repository at this point in the history
* better history

* wip
  • Loading branch information
kbizikav authored Jan 2, 2025
1 parent 65f8f58 commit e1b73cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion cli/src/cli/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use colored::{ColoredString, Colorize as _};
use intmax2_client_sdk::client::history::HistoryEntry;
use intmax2_interfaces::data::deposit_data::TokenType;
use intmax2_zkp::{
common::{signature::key_set::KeySet, trees::asset_tree::AssetLeaf},
common::{deposit::Deposit, signature::key_set::KeySet, trees::asset_tree::AssetLeaf},
ethereum_types::u32limb_trait::U32LimbTrait,
utils::leafable::Leafable as _,
};

use crate::cli::client::get_client;
Expand Down Expand Up @@ -102,12 +103,21 @@ fn print_history_entry(entry: &HistoryEntry) -> Result<(), CliError> {
token_id,
token_index,
amount,
pubkey_salt_hash,
is_included,
is_rejected,
meta,
} => {
let status = get_status_string(*is_included, *is_rejected);
let time = format_timestamp(meta.timestamp);
let deposit_hash = token_index.map(|idx| {
let deposit = Deposit {
pubkey_salt_hash: *pubkey_salt_hash,
token_index: idx,
amount: *amount,
};
deposit.hash()
});

println!(
"{} [{}]",
Expand All @@ -134,6 +144,10 @@ fn print_history_entry(entry: &HistoryEntry) -> Result<(), CliError> {
.white()
);
println!(" Amount: {}", amount.to_string().bright_green());
println!(
" Deposit Hash: {}",
deposit_hash.map_or("N/A".to_string(), |h| h.to_string())
);
println!(" {}", status);
}
HistoryEntry::Receive {
Expand Down
6 changes: 5 additions & 1 deletion client-sdk/src/client/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use intmax2_interfaces::{
};
use intmax2_zkp::{
common::signature::key_set::KeySet,
ethereum_types::{address::Address, u256::U256, u32limb_trait::U32LimbTrait},
ethereum_types::{address::Address, bytes32::Bytes32, u256::U256, u32limb_trait::U32LimbTrait},
};
use plonky2::{field::goldilocks_field::GoldilocksField, plonk::config::PoseidonGoldilocksConfig};
use serde::{Deserialize, Serialize};
Expand All @@ -34,6 +34,7 @@ pub enum HistoryEntry {
token_id: U256,
token_index: Option<u32>,
amount: U256,
pubkey_salt_hash: Bytes32,
is_included: bool,
is_rejected: bool,
meta: MetaData,
Expand Down Expand Up @@ -131,6 +132,7 @@ pub async fn fetch_history<
token_id: settled.token_id,
token_index: settled.token_index,
amount: settled.amount,
pubkey_salt_hash: settled.pubkey_salt_hash,
is_included: user_data.processed_deposit_uuids.contains(&meta.uuid),
is_rejected: false,
meta,
Expand All @@ -143,6 +145,7 @@ pub async fn fetch_history<
token_id: pending.token_id,
token_index: pending.token_index,
amount: pending.amount,
pubkey_salt_hash: pending.pubkey_salt_hash,
is_included: false,
is_rejected: false,
meta,
Expand All @@ -155,6 +158,7 @@ pub async fn fetch_history<
token_id: timeout.token_id,
token_index: timeout.token_index,
amount: timeout.amount,
pubkey_salt_hash: timeout.pubkey_salt_hash,
is_included: false,
is_rejected: true,
meta,
Expand Down

0 comments on commit e1b73cb

Please sign in to comment.