-
Notifications
You must be signed in to change notification settings - Fork 31
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
Query wasm contract state #NTRN-476 #96
Conversation
e9d4ae2
to
3841c59
Compare
b3b537b
to
45ef7ce
Compare
ced6feb
to
8f4e96d
Compare
8f4e96d
to
f4e855d
Compare
let mut storage_key = vec![0u8, 7u8]; | ||
|
||
storage_key.extend_from_slice("balance".as_bytes()); | ||
storage_key.extend_from_slice(account_address.as_bytes()); |
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.
This stuff definitely should be in the SDK helpers not here
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.
Unfortunately, it shouldn't be there, because these values are contract-dependent. I wish I could make a cw20 balance helper, but it is impossible to do.
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 think Mike means that it's not only new_register_wasm_contract_store_query_msg
should be in the helpers package as the most generic helper for interacting with contract's storage, but a more specific helper to register cw20 balance query as well (e.g. new_register_cw20_balance_query_msg
analogically to new_register_delegator_delegations_query_msg
). the helper can have contract and holder addresses as parameters and assemble the needed key inside with these vec![0u8, 7u8]
and balance
reused from constants defined here: https://github.com/neutron-org/neutron-sdk/blob/main/packages/neutron-sdk/src/interchain_queries/v045/types.rs
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.
but now I wonder if we need such a helper — to query a cw20 balance
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.
yeah, I like it how it is now, a general new_register_wasm_contract_store_query_msg
is what we need here whereas cw20 balance stuff is a too specific case to be in the sdk helpers package
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 could implement some kind of storage key factory like this:
let key: Vec<u8> =
StorageKeyFactory::new()
.push_bytes([0, 7])
.push_string("balance")
.push_string(account_address)
.into_bytes();
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 am very hesitant creating even some kind of "general helper which works for canonical cw20-base contract" because users will definitely try to use it and it won't work in some cases.
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 could implement some kind of storage key factory like this:
To be honest it doesn't make anything easier to use, I think I should abandon this idea.
I have no idea what's wrong about this pesky clippy workflow, everything works on my machine locally 🤷 |
let mut storage_key = vec![0u8, 7u8]; | ||
|
||
storage_key.extend_from_slice("balance".as_bytes()); | ||
storage_key.extend_from_slice(account_address.as_bytes()); |
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 think Mike means that it's not only new_register_wasm_contract_store_query_msg
should be in the helpers package as the most generic helper for interacting with contract's storage, but a more specific helper to register cw20 balance query as well (e.g. new_register_cw20_balance_query_msg
analogically to new_register_delegator_delegations_query_msg
). the helper can have contract and holder addresses as parameters and assemble the needed key inside with these vec![0u8, 7u8]
and balance
reused from constants defined here: https://github.com/neutron-org/neutron-sdk/blob/main/packages/neutron-sdk/src/interchain_queries/v045/types.rs
@@ -241,6 +283,19 @@ fn query_recipient_txs(deps: Deps<NeutronQuery>, recipient: String) -> NeutronRe | |||
Ok(to_binary(&GetRecipientTxsResponse { transfers: txs })?) | |||
} | |||
|
|||
pub fn query_cw20_balance( |
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.
if we create a new_register_cw20_balance_query_msg
in the helpers package, we should move this one to the helpers package as well
GetRegisteredQuery { query_id: u64 }, | ||
GetRecipientTxs { recipient: String }, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub struct Cw20BalanceResponse { |
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.
if we create a new_register_cw20_balance_query_msg in the helpers package, we should move this one to the helpers package as well
@@ -40,7 +40,7 @@ pub fn query_kv_result<T: KVReconstruct>( | |||
} | |||
|
|||
/// Queries interchain query result (raw KV storage values or transactions) from Interchain Queries Module | |||
fn get_interchain_query_result( | |||
pub fn get_interchain_query_result( |
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.
why you decided to make it pub? if we want to expose it, we should make it more obvious how it's different from the query_kv_result
above and highlight use cases for both funcs. I mean in this case we need to give it a better naming which will reflect that it returns a raw kv storage value for example and elaborate description
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.
Alright, I agree, I think I will add "raw" to the name of this function and cover it with some decent documentation.
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.
done
cw20_contract_address: String, | ||
account_address: String, | ||
) -> NeutronResult<Response<NeutronMsg>> { | ||
// cw_storage_plus uses this prefix for maps |
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.
There must be an instruction how did you get this prefix, it's not obvious
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.
Bold of you to assume I remember how I did that.
Okay, I will write some extensive docs on how to examine contract storage paths.
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 have added some docs, please check them out
@foxpy hi!
Perhaps the instructions should be added for users with M1 processors, which will have problems with the build.
But it's up to you) |
This PR adds wasm contract state query helper and example test on how to query wasm state using ICQ module.
How to review:
scripts/test_icq_wasm_juno_testnet/
README.md
[Assigned task]