-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'grarco/async-light-sdk-rebase' (#2399)
- Loading branch information
Showing
28 changed files
with
1,562 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Both the `reading` and `writing` modules of the light SDK can now be used from | ||
within an async runtime. ([\#2399](https://github.com/anoma/namada/pull/2399)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use namada_sdk::account::Account; | ||
use namada_sdk::types::key::common; | ||
|
||
use super::*; | ||
|
||
/// Query token amount of owner. | ||
pub async fn get_token_balance( | ||
tendermint_addr: &str, | ||
token: &Address, | ||
owner: &Address, | ||
) -> Result<token::Amount, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::get_token_balance(&client, token, owner).await | ||
} | ||
|
||
/// Check if the address exists on chain. Established address exists if it | ||
/// has a stored validity predicate. Implicit and internal addresses | ||
/// always return true. | ||
pub async fn known_address( | ||
tendermint_addr: &str, | ||
address: &Address, | ||
) -> Result<bool, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::known_address(&client, address).await | ||
} | ||
|
||
/// Query the accunt substorage space of an address | ||
pub async fn get_account_info( | ||
tendermint_addr: &str, | ||
owner: &Address, | ||
) -> Result<Option<Account>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::get_account_info(&client, owner).await | ||
} | ||
|
||
/// Query if the public_key is revealed | ||
pub async fn is_public_key_revealed( | ||
tendermint_addr: &str, | ||
owner: &Address, | ||
) -> Result<bool, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::is_public_key_revealed(&client, owner).await | ||
} | ||
|
||
/// Query an account substorage at a specific index | ||
pub async fn get_public_key_at( | ||
tendermint_addr: &str, | ||
owner: &Address, | ||
index: u8, | ||
) -> Result<Option<common::PublicKey>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::get_public_key_at(&client, owner, index).await | ||
} |
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,43 @@ | ||
use namada_sdk::governance::parameters::GovernanceParameters; | ||
use namada_sdk::governance::storage::proposal::StorageProposal; | ||
use namada_sdk::governance::utils::Vote; | ||
|
||
use super::*; | ||
|
||
/// Query proposal by Id | ||
pub async fn query_proposal_by_id( | ||
tendermint_addr: &str, | ||
proposal_id: u64, | ||
) -> Result<Option<StorageProposal>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::query_proposal_by_id(&client, proposal_id).await | ||
} | ||
|
||
/// Get the givernance parameters | ||
pub async fn query_governance_parameters( | ||
tendermint_addr: &str, | ||
) -> Result<GovernanceParameters, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
Ok(rpc::query_governance_parameters(&client).await) | ||
} | ||
|
||
/// Get the givernance parameters | ||
pub async fn query_proposal_votes( | ||
tendermint_addr: &str, | ||
proposal_id: u64, | ||
) -> Result<Vec<Vote>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::query_proposal_votes(&client, proposal_id).await | ||
} |
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,76 @@ | ||
use std::str::FromStr; | ||
|
||
use namada_sdk::error::{EncodingError, Error}; | ||
use namada_sdk::io::StdIo; | ||
use namada_sdk::queries::RPC; | ||
use namada_sdk::rpc; | ||
use namada_sdk::state::LastBlock; | ||
use namada_sdk::types::address::Address; | ||
use namada_sdk::types::storage::BlockResults; | ||
use namada_sdk::types::token::{self, DenominatedAmount}; | ||
use tendermint_config::net::Address as TendermintAddress; | ||
use tendermint_rpc::HttpClient; | ||
|
||
pub mod account; | ||
pub mod governance; | ||
pub mod pgf; | ||
pub mod pos; | ||
pub mod tx; | ||
|
||
/// Query the address of the native token | ||
pub async fn query_native_token( | ||
tendermint_addr: &str, | ||
) -> Result<Address, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::query_native_token(&client).await | ||
} | ||
|
||
/// Query the last committed block, if any. | ||
pub async fn query_block( | ||
tendermint_addr: &str, | ||
) -> Result<Option<LastBlock>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::query_block(&client).await | ||
} | ||
|
||
/// Query the results of the last committed block | ||
pub async fn query_results( | ||
tendermint_addr: &str, | ||
) -> Result<Vec<BlockResults>, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
rpc::query_results(&client).await | ||
} | ||
|
||
/// Get a properly denominated amount of a token | ||
pub async fn denominate_amount( | ||
tendermint_addr: &str, | ||
amount: u64, | ||
token: &str, | ||
) -> Result<DenominatedAmount, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
let token = Address::decode(token) | ||
.map_err(|e| Error::Encode(EncodingError::Decoding(e.to_string())))?; | ||
Ok(rpc::denominate_amount( | ||
&client, | ||
&StdIo {}, | ||
&token, | ||
token::Amount::from(amount), | ||
) | ||
.await) | ||
} |
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,14 @@ | ||
use super::*; | ||
|
||
/// Check if the given address is a pgf steward. | ||
pub async fn is_steward( | ||
tendermint_addr: &str, | ||
address: &Address, | ||
) -> Result<bool, Error> { | ||
let client = HttpClient::new( | ||
TendermintAddress::from_str(tendermint_addr) | ||
.map_err(|e| Error::Other(e.to_string()))?, | ||
) | ||
.map_err(|e| Error::Other(e.to_string()))?; | ||
Ok(rpc::is_steward(&client, address).await) | ||
} |
Oops, something went wrong.