-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add token supply query #17
Conversation
About that non-exhaustive issue: In newer versions of let mut res = SupplyResponse::default();
res.amount = amount; |
What is left to fix here? I'm blocked on this, happy to finish up the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments here to improve.
Also would like to see some tests
// TODO: remove this when I figure out how non_exhaustive works | ||
#[cfg(feature = "cosmwasm_1_1")] | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub struct SupplyResponse { | ||
/// Always returns a Coin with the requested denom. | ||
/// This will be of zero amount if the denom does not exist. | ||
pub amount: Coin, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cosmwasm-std
version should be bumped and then this can be removed. Instead the SupplyResponse
from cosmwasm-std
should be used (using either the Default
impl or the recently introduced constructor)
fn get_supply(&self, bank_storage: &dyn Storage, denom: String) -> AnyResult<Coin> { | ||
let supply: Uint128 = BALANCES | ||
.range(bank_storage, None, None, Order::Ascending) | ||
.into_iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to call into_iter()
here, it's a noop
let supply: Uint128 = BALANCES | ||
.range(bank_storage, None, None, Order::Ascending) | ||
.into_iter() | ||
.map(|a| a.unwrap().1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of this unwrap, the error should be bubbled up
Builds off: CosmWasm#17
Builds off: CosmWasm#17
Pretty much self explanatory, I need to be able to query for the supply of a native token during testing.
I don't know how to get around the
non_exhaustive
issue, that's why I've redefined theSupplyResponse
struct.