Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,6 @@ pub mod args {
pub const SOURCE: Arg<WalletAddress> = arg("source");
pub const SOURCE_OPT: ArgOpt<WalletAddress> = SOURCE.opt();
pub const STORAGE_KEY: Arg<storage::Key> = arg("storage-key");
pub const SUB_PREFIX: ArgOpt<String> = arg_opt("sub-prefix");
pub const SUSPEND_ACTION: ArgFlag = flag("suspend");
pub const TIMEOUT_HEIGHT: ArgOpt<u64> = arg_opt("timeout-height");
pub const TIMEOUT_SEC_OFFSET: ArgOpt<u64> = arg_opt("timeout-sec-offset");
Expand Down Expand Up @@ -2147,7 +2146,6 @@ pub mod args {
source: ctx.get_cached(&self.source),
target: ctx.get(&self.target),
token: ctx.get(&self.token),
sub_prefix: self.sub_prefix,
amount: self.amount,
native_token: ctx.native_token.clone(),
tx_code_path: self.tx_code_path.to_path_buf(),
Expand All @@ -2161,15 +2159,13 @@ pub mod args {
let source = TRANSFER_SOURCE.parse(matches);
let target = TRANSFER_TARGET.parse(matches);
let token = TOKEN.parse(matches);
let sub_prefix = SUB_PREFIX.parse(matches);
let amount = AMOUNT.parse(matches);
let tx_code_path = PathBuf::from(TX_TRANSFER_WASM);
Self {
tx,
source,
target,
token,
sub_prefix,
amount,
native_token: (),
tx_code_path,
Expand All @@ -2187,7 +2183,6 @@ pub mod args {
to produce the signature.",
))
.arg(TOKEN.def().about("The transfer token."))
.arg(SUB_PREFIX.def().about("The token's sub prefix."))
.arg(AMOUNT.def().about("The amount to transfer in decimal."))
}
}
Expand All @@ -2199,7 +2194,6 @@ pub mod args {
source: ctx.get(&self.source),
receiver: self.receiver,
token: ctx.get(&self.token),
sub_prefix: self.sub_prefix,
amount: self.amount,
port_id: self.port_id,
channel_id: self.channel_id,
Expand All @@ -2216,7 +2210,6 @@ pub mod args {
let source = SOURCE.parse(matches);
let receiver = RECEIVER.parse(matches);
let token = TOKEN.parse(matches);
let sub_prefix = SUB_PREFIX.parse(matches);
let amount = AMOUNT.parse(matches);
let port_id = PORT_ID.parse(matches);
let channel_id = CHANNEL_ID.parse(matches);
Expand All @@ -2228,7 +2221,6 @@ pub mod args {
source,
receiver,
token,
sub_prefix,
amount,
port_id,
channel_id,
Expand All @@ -2248,7 +2240,6 @@ pub mod args {
"The receiver address on the destination chain as string.",
))
.arg(TOKEN.def().about("The transfer token."))
.arg(SUB_PREFIX.def().about("The token's sub prefix."))
.arg(AMOUNT.def().about("The amount to transfer in decimal."))
.arg(PORT_ID.def().about("The port ID."))
.arg(CHANNEL_ID.def().about("The channel ID."))
Expand Down Expand Up @@ -2908,7 +2899,6 @@ pub mod args {
owner: self.owner.map(|x| ctx.get_cached(&x)),
token: self.token.map(|x| ctx.get(&x)),
no_conversions: self.no_conversions,
sub_prefix: self.sub_prefix,
}
}
}
Expand All @@ -2919,13 +2909,11 @@ pub mod args {
let owner = BALANCE_OWNER.parse(matches);
let token = TOKEN_OPT.parse(matches);
let no_conversions = NO_CONVERSIONS.parse(matches);
let sub_prefix = SUB_PREFIX.parse(matches);
Self {
query,
owner,
token,
no_conversions,
sub_prefix,
}
}

Expand All @@ -2946,11 +2934,6 @@ pub mod args {
"Whether not to automatically perform conversions.",
),
)
.arg(
SUB_PREFIX.def().about(
"The token's sub prefix whose balance to query.",
),
)
}
}

Expand Down
137 changes: 59 additions & 78 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,71 +283,46 @@ pub async fn query_transparent_balance<
wallet: &mut Wallet<CliWalletUtils>,
args: args::QueryBalance,
) {
let tokens = wallet.get_addresses_with_vp_type(AddressVpType::Token);
let prefix = Key::from(
Address::Internal(namada::types::address::InternalAddress::Multitoken)
.to_db_key(),
);
match (args.token, args.owner) {
(Some(token), Some(owner)) => {
let key = match &args.sub_prefix {
Some(sub_prefix) => {
let sub_prefix = Key::parse(sub_prefix).unwrap();
let prefix =
token::multitoken_balance_prefix(&token, &sub_prefix);
token::multitoken_balance_key(
&prefix,
&owner.address().unwrap(),
)
}
None => token::balance_key(&token, &owner.address().unwrap()),
};
let key = token::balance_key(&token, &owner.address().unwrap());
let token_alias = lookup_alias(wallet, &token);
match query_storage_value::<C, token::Amount>(client, &key).await {
Some(balance) => match &args.sub_prefix {
Some(sub_prefix) => {
println!(
"{} with {}: {}",
token_alias, sub_prefix, balance
);
}
None => println!("{}: {}", token_alias, balance),
},
Some(balance) => println!("{}: {}", token_alias, balance),
None => {
println!("No {} balance found for {}", token_alias, owner)
}
}
}
(None, Some(owner)) => {
for token in tokens {
let prefix =
token::balance_key(&token, &owner.address().unwrap());
let balances =
query_storage_prefix::<C, token::Amount>(client, &prefix)
.await;
if let Some(balances) = balances {
print_balances(
wallet,
balances,
&token,
owner.address().as_ref(),
);
}
let balances =
query_storage_prefix::<C, token::Amount>(client, &prefix).await;
if let Some(balances) = balances {
print_balances(
wallet,
balances,
None,
owner.address().as_ref(),
);
}
}
(Some(token), None) => {
let prefix = token::balance_prefix(&token);
let balances =
query_storage_prefix::<C, token::Amount>(client, &prefix).await;
if let Some(balances) = balances {
print_balances(wallet, balances, &token, None);
print_balances(wallet, balances, Some(&token), None);
}
}
(None, None) => {
for token in tokens {
let key = token::balance_prefix(&token);
let balances =
query_storage_prefix::<C, token::Amount>(client, &key)
.await;
if let Some(balances) = balances {
print_balances(wallet, balances, &token, None);
}
let balances =
query_storage_prefix::<C, token::Amount>(client, &prefix).await;
if let Some(balances) = balances {
print_balances(wallet, balances, None, None);
}
}
}
Expand Down Expand Up @@ -482,58 +457,64 @@ pub async fn query_pinned_balance<
fn print_balances(
wallet: &Wallet<CliWalletUtils>,
balances: impl Iterator<Item = (storage::Key, token::Amount)>,
token: &Address,
token: Option<&Address>,
target: Option<&Address>,
) {
let stdout = io::stdout();
let mut w = stdout.lock();

let token_alias = lookup_alias(wallet, token);
writeln!(w, "Token {}", token_alias).unwrap();

let mut print_token = None;
let print_num = balances
.filter_map(
|(key, balance)| match token::is_any_multitoken_balance_key(&key) {
Some((sub_prefix, owner)) => Some((
.filter_map(|(key, balance)| {
token::is_any_token_balance_key(&key).map(|(token, owner)| {
(
token.clone(),
owner.clone(),
format!(
"with {}: {}, owned by {}",
sub_prefix,
": {}, owned by {}",
balance,
lookup_alias(wallet, owner)
),
)),
None => token::is_any_token_balance_key(&key).map(|owner| {
(
owner.clone(),
format!(
": {}, owned by {}",
balance,
lookup_alias(wallet, owner)
),
)
}),
},
)
.filter_map(|(o, s)| match target {
Some(t) if o == *t => Some(s),
Some(_) => None,
None => Some(s),
)
})
})
.map(|s| {
.filter_map(|(t, o, s)| match (token, target) {
(Some(token), Some(target)) if t == *token && o == *target => {
Some((t, s))
}
(Some(token), None) if t == *token => Some((t, s)),
(None, Some(target)) if o == *target => Some((t, s)),
(None, None) => Some((t, s)),
_ => None,
})
.map(|(t, s)| {
match &print_token {
Some(token) if *token == t => {
// the token was already printed
}
Some(_) | None => {
let token_alias = lookup_alias(wallet, &t);
writeln!(w, "Token {}", token_alias).unwrap();
print_token = Some(t);
}
}
writeln!(w, "{}", s).unwrap();
})
.count();

if print_num == 0 {
match target {
Some(t) => {
writeln!(w, "No balances owned by {}", lookup_alias(wallet, t))
.unwrap()
}
None => {
match (token, target) {
(Some(_), Some(target)) | (None, Some(target)) => writeln!(
w,
"No balances owned by {}",
lookup_alias(wallet, target)
)
.unwrap(),
(Some(token), None) => {
let token_alias = lookup_alias(wallet, token);
writeln!(w, "No balances for token {}", token_alias).unwrap()
}
(None, None) => writeln!(w, "No balances").unwrap(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use namada::proof_of_stake::{
use namada::types::address::Address;
use namada::types::key::tm_raw_hash_to_string;
use namada::types::storage::{BlockHash, BlockResults, Epoch, Header};
use namada::types::token::{total_supply_key, Amount};
use namada::types::token::{minted_balance_key, Amount};
use rust_decimal::prelude::Decimal;

use super::governance::execute_governance_proposals;
Expand Down Expand Up @@ -639,7 +639,7 @@ where
.expect("PoS inflation rate should exist in storage");
// Read from PoS storage
let total_tokens = self
.read_storage_key(&total_supply_key(&staking_token_address(
.read_storage_key(&minted_balance_key(&staking_token_address(
&self.wl_storage,
)))
.expect("Total NAM balance should exist in storage");
Expand Down
10 changes: 9 additions & 1 deletion core/src/ledger/ibc/context/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! IbcCommonContext implementation for IBC

use borsh::BorshSerialize;
use prost::Message;
use sha2::Digest;

Expand Down Expand Up @@ -363,7 +364,14 @@ pub trait IbcCommonContext: IbcStorageContext {
denom: PrefixedDenom,
) -> Result<(), ContextError> {
let key = storage::ibc_denom_key(trace_hash);
let bytes = denom.to_string().as_bytes().to_vec();
let bytes = denom.to_string().try_to_vec().map_err(|e| {
ContextError::ChannelError(ChannelError::Other {
description: format!(
"Encoding the denom failed: Denom {}, error {}",
denom, e
),
})
})?;
self.write(&key, bytes).map_err(|_| {
ContextError::ChannelError(ChannelError::Other {
description: format!("Writing the denom failed: Key {}", key),
Expand Down
22 changes: 20 additions & 2 deletions core/src/ledger/ibc/context/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub use ics23::ProofSpec;

use super::super::Error;
use crate::ledger::storage_api;
use crate::types::address::Address;
use crate::types::ibc::IbcEvent;
use crate::types::storage::{BlockHeight, Header, Key};
use crate::types::token::Amount;
Expand Down Expand Up @@ -54,8 +55,25 @@ pub trait IbcStorageContext {
/// Transfer token
fn transfer_token(
&mut self,
src: &Key,
dest: &Key,
src: &Address,
dest: &Address,
token: &Address,
amount: Amount,
) -> Result<(), Self::Error>;

/// Mint token
fn mint_token(
&mut self,
target: &Address,
token: &Address,
amount: Amount,
) -> Result<(), Self::Error>;

/// Burn token
fn burn_token(
&mut self,
target: &Address,
token: &Address,
amount: Amount,
) -> Result<(), Self::Error>;

Expand Down
Loading