Crate terra_rust_api[−][src]
This crate provides an interface into the Terra LCD HTTP service.
PFC
This work is sponsored by the PFC (Pretty Freaking Cool) Validator, feel free to delegate to the PFC validator.
It will help defray the costs.
Warning
This uses crytpographic routines that have not gone through any security audit.
The manner which it stores private keys may be unsecure/subject to hacks, and if you use it, may put the assets behind those keys at risk.
This is ALPHA software.
Usage
[dependencies]
terra-rust-api="0.1"
use terra_rust_api::{Terra, GasOptions, PrivateKey}; use terra_rust_api::core_types::{Coin, Msg, StdSignMsg, StdSignature}; use terra_rust_api::messages::MsgSend; use terra_rust_api::auth_types::AuthAccountResult; // set up the LCD client let gas_opts = GasOptions::create_with_gas_estimate("50ukrw",1.4); let t = Terra::lcd_client("https://tequila-lcd.terra.dev/", "tequila-0004", &gas_opts).await?; // generate a private key let secp = Secp256k1::new(); let from_key = PrivateKey::from_words(&secp,"your secret words"); let from_public_key = from_key.public_key(&secp); // generate the message SEND 1000 uluna from your private key to someone else let coin: Coin = Coin::parse("1000uluna")?.unwrap(); let from_account = from_public_key.account()?; let send: MsgSend = MsgSend::create(from_account, "terra1usws7c2c6cs7nuc8vma9qzaky5pkgvm2uag6rh", vec![coin]); // generate the transaction & calc fees let messages: Vec<Box<dyn Msg>> = vec![Box::new(send)]; let std_fee = terra.calc_fees(&messages).await?; let auth_result: AuthAccountResult = terra.auth().account(&from_public_key.account()?).await?; let account_number = auth_result.result.value.account_number; let std_sign_msg = StdSignMsg { chain_id: terra.chain_id.to_string(), account_number, sequence: auth_result.result.value.sequence, fee: std_fee, msgs: messages, memo: "Luna to the Moon!".to_string(), }; // Sign it let js = serde_json::to_string(&std_sign_msg)?; let sig = from_key.sign(&secp, &js)?; let sigs: Vec<StdSignature> = vec![sig]; // send it out let resp = terra.tx().broadcast_sync(&std_sign_msg, &sigs).await?; match resp.code { Some(code) => { log::error!("{}", serde_json::to_string(&resp)?); eprintln!("Transaction returned a {} {}", code, resp.txhash) } None => { println!("{}", resp.txhash) } }
Re-exports
pub use messages::bank; |
Modules
auth_types | Structures used in account authentication |
client_types | JSON Serializer/Deserializer helpers routines used to serialize / deserialize a Cosmos / Tendermint / TerraD structure |
core_types | Common Structures throughout the library |
errors | Error Messages |
market_types | Structures used for Market APIs |
messages | definitions of the different type of Messages we have implemented |
staking_types | Structures used for Staking APIs |
Structs
GasOptions | When Submitting transactions you need to either submit gas or a fee to the validator This structure is used to determine what your preferences are by default Higher fees may be given preference by the validator to include the transaction in their block |
PrivateKey | The Private key structure that is used to generate signatures and public keys WARNING: No Security Audit has been performed |
PublicKey | The public key we used to generate the cosmos/tendermind/terrad addresses |
Terra | The main structure that all API calls are generated from |