Struct deep_space::client::Contact [−][src]
pub struct Contact { /* fields omitted */ }Expand description
An instance of Contact Cosmos RPC Client.
Implementations
Gets a list of coins in the community pool, note returned values from this endpoint are in DecCoins for precision, for the sake of ease of use this endpoint converts them into their normal form, for easy comparison against any other coin or amount.
Gets the current chain status, returns an enum taking into account the various possible states of the chain and the requesting full node. In the common case this provides the block number
Gets the latest block from the node, taking into account the possibility that the chain is halted and also the possibility that the node is syncing
pub async fn get_account_info(
&self,
address: Address
) -> Result<BaseAccount, CosmosGrpcError>
pub async fn get_account_info(
&self,
address: Address
) -> Result<BaseAccount, CosmosGrpcError>
Gets account info for the provided Cosmos account using the accounts endpoint accounts do not have any info if they have no tokens or are otherwise never seen before in this case we return the special error NoToken
pub async fn get_message_args(
&self,
our_address: Address,
fee: Fee
) -> Result<MessageArgs, CosmosGrpcError>
pub async fn get_message_args(
&self,
our_address: Address,
fee: Fee
) -> Result<MessageArgs, CosmosGrpcError>
Grabs an up to date MessageArgs structure for an address, provided a fee value to insert into the structure. The goal of this function is to be very minimal and make a lot of choices for the user. Like how to handle changes in chain-id or timeout heights
Waits for the next block to be produced, useful if you want to wait for an on chain event or some thing to change
pub async fn get_governance_proposals(
&self,
filters: QueryProposalsRequest
) -> Result<QueryProposalsResponse, CosmosGrpcError>
pub async fn get_governance_proposals(
&self,
filters: QueryProposalsRequest
) -> Result<QueryProposalsResponse, CosmosGrpcError>
Gets a list of governance proposals, user provides filter items
pub async fn get_governance_proposals_in_voting_period(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
pub async fn get_governance_proposals_in_voting_period(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
Gets a list of all active governance proposals currently in the voting period
pub async fn get_passed_governance_proposals(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
pub async fn get_passed_governance_proposals(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
Gets a list of all governance proposals that have passed
pub async fn get_failed_governance_proposals(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
pub async fn get_failed_governance_proposals(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
Gets a list of all governance proposals that have failed
pub async fn get_rejected_governance_proposals(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
pub async fn get_rejected_governance_proposals(
&self
) -> Result<QueryProposalsResponse, CosmosGrpcError>
Gets a list of all governance proposals that have been rejected
pub async fn vote_on_gov_proposal(
&self,
proposal_id: u64,
vote: VoteOption,
fee: Coin,
private_key: PrivateKey,
wait_timeout: Option<Duration>
) -> Result<TxResponse, CosmosGrpcError>
pub async fn create_gov_proposal(
&self,
content: Any,
deposit: Coin,
fee: Coin,
private_key: PrivateKey,
wait_timeout: Option<Duration>
) -> Result<TxResponse, CosmosGrpcError>
pub async fn create_gov_proposal(
&self,
content: Any,
deposit: Coin,
fee: Coin,
private_key: PrivateKey,
wait_timeout: Option<Duration>
) -> Result<TxResponse, CosmosGrpcError>
Provides an interface for submitting governance proposals
pub async fn send_transaction(
&self,
msg: Vec<u8>,
mode: BroadcastMode
) -> Result<TxResponse, CosmosGrpcError>
pub async fn send_transaction(
&self,
msg: Vec<u8>,
mode: BroadcastMode
) -> Result<TxResponse, CosmosGrpcError>
Sends an already serialized and signed transaction, checking for various errors in the
transaction response. This is the lowest level transaction sending function and you
probably shouldn’t use it unless you have specific needs. send_message is more
appropriate for general use.
Arguments
msg- A proto encoded and already signed message in byte formatmode- The Broadcast mode to use,BroadcastMode::Syncwaits for basic validationBroadcastMode::Blockis supposed to wait for the tx to enter the chain but grpc timeouts mean this is unreliable.BroadcastMode::Asyncsends and returns without waiting for any validation
Examples
use cosmos_sdk_proto::cosmos::bank::v1beta1::MsgSend;
use cosmos_sdk_proto::cosmos::tx::v1beta1::BroadcastMode;
use deep_space::{Coin, client::Contact, Fee, MessageArgs, Msg, PrivateKey};
use std::time::Duration;
let private_key = PrivateKey::from_secret("mySecret".as_bytes());
let public_key = private_key.to_public_key("cosmospub").unwrap();
let address = public_key.to_address();
let coin = Coin {
denom: "validatortoken".to_string(),
amount: 1u32.into(),
};
let send = MsgSend {
amount: vec![coin.clone().into()],
from_address: address.to_string(),
to_address: "cosmos1pr2n6tfymnn2tk6rkxlu9q5q2zq5ka3wtu7sdj".to_string(),
};
let fee = Fee {
amount: vec![coin],
gas_limit: 500_000,
granter: None,
payer: None,
};
let msg = Msg::new("/cosmos.crypto.secp256k1.PubKey", send);
let args = MessageArgs {
sequence: 0,
account_number: 0,
chain_id: "mychainid".to_string(),
fee,
timeout_height: 100,
};
let tx = private_key.sign_std_msg(&[msg], args, "").unwrap();
let contact = Contact::new("https:://your-grpc-server", Duration::from_secs(5), "prefix").unwrap();
// future must be awaited in tokio runtime
contact.send_transaction(tx, BroadcastMode::Sync);pub async fn send_message(
&self,
messages: &[Msg],
memo: Option<String>,
fee_coin: &[Coin],
wait_timeout: Option<Duration>,
private_key: PrivateKey
) -> Result<TxResponse, CosmosGrpcError>
pub async fn send_message(
&self,
messages: &[Msg],
memo: Option<String>,
fee_coin: &[Coin],
wait_timeout: Option<Duration>,
private_key: PrivateKey
) -> Result<TxResponse, CosmosGrpcError>
High level message sending function, you provide an arbitrary vector of messages to send a private key to sign with, and a fee coin (if any). The gas is then estimated and set automatically. This function will return on or before the provided wait_timeout value if no timeout is provided we will still wait for a response from the Cosmos node with the results of ValidateBasic() on your transaction this may take up to a few seconds.
Arguments
messages- An array of messages to sendmemo- An optional memo to be included in the transaction, if None the default memo value is setfee_coin- A fee amount and coin type to use, pass an empty array to send a zero fee transactionwait_timeout- An optional amount of time to wait for the transaction to enter the blockchainprivate_key- A private key used to sign and send the transaction
Examples
use cosmos_sdk_proto::cosmos::bank::v1beta1::MsgSend;
use cosmos_sdk_proto::cosmos::tx::v1beta1::BroadcastMode;
use deep_space::{Coin, client::Contact, Fee, MessageArgs, Msg, PrivateKey};
use std::time::Duration;
let private_key = PrivateKey::from_secret("mySecret".as_bytes());
let public_key = private_key.to_public_key("cosmospub").unwrap();
let address = public_key.to_address();
let coin = Coin {
denom: "validatortoken".to_string(),
amount: 1u32.into(),
};
let send = MsgSend {
amount: vec![coin.clone().into()],
from_address: address.to_string(),
to_address: "cosmos1pr2n6tfymnn2tk6rkxlu9q5q2zq5ka3wtu7sdj".to_string(),
};
let msg = Msg::new("/cosmos.crypto.secp256k1.PubKey", send);
let contact = Contact::new("https:://your-grpc-server", Duration::from_secs(5), "prefix").unwrap();
// future must be awaited in tokio runtime
contact.send_message(&vec![msg], None, &[coin], None, private_key);pub async fn get_fee_info(
&self,
messages: &[Msg],
fee_token: &[Coin],
private_key: PrivateKey
) -> Result<Fee, CosmosGrpcError>
pub async fn get_fee_info(
&self,
messages: &[Msg],
fee_token: &[Coin],
private_key: PrivateKey
) -> Result<Fee, CosmosGrpcError>
Simulates the provided array of messages and returns a fee object with the gas amount actually used
pub async fn simulate_tx(
&self,
messages: &[Msg],
private_key: PrivateKey
) -> Result<SimulateResponse, CosmosGrpcError>
pub async fn simulate_tx(
&self,
messages: &[Msg],
private_key: PrivateKey
) -> Result<SimulateResponse, CosmosGrpcError>
Simulates the provided array of messages and returns the simulation result
pub async fn send_coins(
&self,
coin: Coin,
fee_coin: Option<Coin>,
destination: Address,
wait_timeout: Option<Duration>,
private_key: PrivateKey
) -> Result<TxResponse, CosmosGrpcError>
pub async fn send_coins(
&self,
coin: Coin,
fee_coin: Option<Coin>,
destination: Address,
wait_timeout: Option<Duration>,
private_key: PrivateKey
) -> Result<TxResponse, CosmosGrpcError>
A utility function that creates a one to one simple Coin transfer and sends it from the provided private key, waiting the configured amount of time for the tx to enter the chain, if you do not specify a fee the smallest working amount will be selected.
Arguments
coin- The amount and type of coin you are sendingfee_coin- A fee amount and coin type to use, pass an empty array to send a zero fee transactiondestination- The target destination addresswait_timeout- An optional amount of time to wait for the transaction to enter the blockchainprivate_key- A private key used to sign and send the transaction
Examples
use cosmos_sdk_proto::cosmos::bank::v1beta1::MsgSend;
use cosmos_sdk_proto::cosmos::tx::v1beta1::BroadcastMode;
use deep_space::{Coin, client::Contact, Fee, MessageArgs, Msg, PrivateKey};
use std::time::Duration;
let private_key = PrivateKey::from_secret("mySecret".as_bytes());
let public_key = private_key.to_public_key("cosmospub").unwrap();
let address = public_key.to_address();
let coin = Coin {
denom: "validatortoken".to_string(),
amount: 1u32.into(),
};
let contact = Contact::new("https:://your-grpc-server", Duration::from_secs(5), "prefix").unwrap();
// future must be awaited in tokio runtime
contact.send_coins(coin.clone(), Some(coin), address, None, private_key);pub async fn wait_for_tx(
&self,
response: TxResponse,
timeout: Duration
) -> Result<TxResponse, CosmosGrpcError>
pub async fn wait_for_tx(
&self,
response: TxResponse,
timeout: Duration
) -> Result<TxResponse, CosmosGrpcError>
Utility function that waits for a tx to enter the chain by querying it’s txid, will not exit for timeout time unless the error is known and unrecoverable
pub async fn get_validators_list(
&self,
filters: QueryValidatorsRequest
) -> Result<QueryValidatorsResponse, CosmosGrpcError>
pub async fn get_validators_list(
&self,
filters: QueryValidatorsRequest
) -> Result<QueryValidatorsResponse, CosmosGrpcError>
Gets a list of validators
Gets a list of bonded validators
pub async fn delegate_to_validator(
&self,
validator_address: Address,
amount_to_delegate: Coin,
fee: Coin,
private_key: PrivateKey,
wait_timeout: Option<Duration>
) -> Result<TxResponse, CosmosGrpcError>
pub async fn delegate_to_validator(
&self,
validator_address: Address,
amount_to_delegate: Coin,
fee: Coin,
private_key: PrivateKey,
wait_timeout: Option<Duration>
) -> Result<TxResponse, CosmosGrpcError>
Delegates tokens to a specified bonded validator
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Contact
impl UnwindSafe for Contact
Blanket Implementations
Mutably borrows from an owned value. Read more
Wrap the input message T in a tonic::Request
pub fn vzip(self) -> V
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more