-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(x/wasm): add AllKeys query binding (#185)
* feat(cosmwasm): add support for calling warden module from contracts * feat(cosmwasm): add bindings and sample contract * fix(cosmwasm): straightforward changes after the code review * fix(cosmwasm): update changelog * feat(cosmwasm): query keys from contracts * fix(cosmwasm): update changelog * feat(cosmwasm): populate contract related readme files * fix(cosmwasm): update changelog file * fix(cosmwasm): fix typos in readme files * fix(cosmwasm): fix typos * fix(cosmwasm): sync rust types with updated proto definitions * fix(cosmwasm) rewrite the sentence about the key to make it clearer --------- Co-authored-by: Pavel Afanasyev <pavel.afanasyev@equilibrium.io>
- Loading branch information
1 parent
a9dd252
commit c96080d
Showing
17 changed files
with
327 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
# Sample | ||
|
||
This is a sample contract which uses bindings for the core Warden Protocol blockchain functionality. | ||
|
||
You can deploy it by itself, or you can use it as a starting point for your own contract. | ||
|
||
Note that this is a preview, so only limited functionality available right now. | ||
The sample contract exposes `NewKeyRequest` transaction and `AllKeys` query, but more are on the way! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
use cosmwasm_schema::write_api; | ||
|
||
use sample::msg::{ExecuteMsg}; | ||
use sample::msg::{ExecuteMsg, QueryMsg}; | ||
|
||
fn main() { | ||
write_api! { | ||
execute: ExecuteMsg, | ||
query: QueryMsg | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
# Bindings | ||
|
||
This crate provides bindings for the Warden Protocol blockchain core functionality. | ||
You can use it in your own contracts to interact with a Warden Protocol. | ||
|
||
Note that this is a preview, so only limited functionality available right now. | ||
You can execute `NewKeyRequest` and query `AllKeys`, but more on the way! | ||
|
||
To start using Warden Protocol from the CosmWasm contracts, please refer to the sample contract. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use cosmwasm_schema::cw_serde; | ||
use cosmwasm_std::{Binary}; | ||
|
||
pub type KeyType = i32; | ||
|
||
#[cw_serde] | ||
pub struct Key { | ||
id: u64, | ||
space_id: u64, | ||
keychain_id: u64, | ||
#[serde(rename = "type")] | ||
key_type: KeyType, | ||
public_key: Binary, | ||
intent_id: u64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
pub mod msg; | ||
pub mod query; | ||
pub mod querier; | ||
pub mod key; | ||
|
||
pub use crate::msg::WardenProtocolMsg; | ||
pub use crate::query::{WardenProtocolQuery, QueryKeysResponse}; | ||
pub use crate::querier::WardenQuerier; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use cosmwasm_std::{PageRequest, QuerierWrapper, StdResult}; | ||
|
||
use crate::{QueryKeysResponse, WardenProtocolQuery}; | ||
use crate::query::{AddressType, WardenQuery}; | ||
|
||
pub struct WardenQuerier<'a> { | ||
querier: &'a QuerierWrapper<'a, WardenProtocolQuery>, | ||
} | ||
|
||
impl<'a> WardenQuerier<'a> { | ||
pub fn new(querier: &'a QuerierWrapper<WardenProtocolQuery>) -> Self { | ||
WardenQuerier { querier } | ||
} | ||
|
||
pub fn query_warden_all_keys(&self, pagination: PageRequest, derive_addresses: Vec<AddressType>) -> StdResult<QueryKeysResponse> { | ||
let request = WardenProtocolQuery::Warden(WardenQuery::AllKeys { pagination, derive_addresses }); | ||
let response = self.querier.query::<QueryKeysResponse>(&request.into())?; | ||
Ok(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use cosmwasm_schema::cw_serde; | ||
use cosmwasm_std::{CustomQuery, Addr, PageRequest}; | ||
use cosmwasm_std::{Binary}; | ||
use crate::key::Key; | ||
|
||
#[cw_serde] | ||
pub enum WardenProtocolQuery { | ||
Warden(WardenQuery), | ||
} | ||
|
||
impl CustomQuery for WardenProtocolQuery {} | ||
|
||
#[cw_serde] | ||
pub enum WardenQuery { | ||
AllKeys { pagination: PageRequest, derive_addresses: Vec<AddressType> }, | ||
} | ||
|
||
pub type AddressType = i32; | ||
|
||
#[cw_serde] | ||
pub struct PageResponse { | ||
next_key: Option<Binary>, | ||
total: Option<u64>, | ||
} | ||
|
||
#[cw_serde] | ||
pub struct AddressResponse { | ||
address: Addr, | ||
#[serde(rename = "type")] | ||
address_type: AddressType | ||
} | ||
|
||
#[cw_serde] | ||
pub struct QueryKeyResponse { | ||
key: Key, | ||
addresses: Vec<AddressResponse> | ||
} | ||
#[cw_serde] | ||
pub struct QueryKeysResponse { | ||
pagination: PageResponse, | ||
keys: Option<QueryKeyResponse>, | ||
} |
Oops, something went wrong.