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

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

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

Gets a list of governance proposals, user provides filter items

Gets a list of all active governance proposals currently in the voting period

Gets a list of all governance proposals that have passed

Gets a list of all governance proposals that have failed

Gets a list of all governance proposals that have been rejected

Provides an interface for submitting governance proposals

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 format
  • mode - The Broadcast mode to use, BroadcastMode::Sync waits for basic validation BroadcastMode::Block is supposed to wait for the tx to enter the chain but grpc timeouts mean this is unreliable. BroadcastMode::Async sends 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);

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 send
  • memo - An optional memo to be included in the transaction, if None the default memo value is set
  • fee_coin - A fee amount and coin type to use, pass an empty array to send a zero fee transaction
  • wait_timeout - An optional amount of time to wait for the transaction to enter the blockchain
  • private_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);

Simulates the provided array of messages and returns a fee object with the gas amount actually used

Simulates the provided array of messages and returns the simulation result

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 sending
  • fee_coin - A fee amount and coin type to use, pass an empty array to send a zero fee transaction
  • destination - The target destination address
  • wait_timeout - An optional amount of time to wait for the transaction to enter the blockchain
  • private_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);

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

Gets a list of validators

Gets a list of bonded validators

Delegates tokens to a specified bonded validator

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Wrap the input message T in a tonic::Request

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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