terra_rust_api/lib.rs
1// `error_chain!` can recurse deeply
2// #![recursion_limit = "1024"]
3#![allow(missing_docs)]
4/*!
5* This crate provides an interface into the Terra LCD HTTP service.
6* # PFC
7*
8* This work is sponsored by the PFC (Pretty Freaking Cool) Validator,
9* feel free to delegate to the [PFC](https://station.terra.money/validator/terravaloper12g4nkvsjjnl0t7fvq3hdcw7y8dc9fq69nyeu9q) validator.
10*
11* It will help defray the costs.
12*
13* # Warning
14* This uses crytpographic routines that have not gone through any security audit.
15*
16* 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.
17*
18* This is ALPHA software.
19*
20* # Usage
21* ```toml
22* [dependencies]
23* terra-rust-api="0.1"
24* tokio = { version = "1.4", features = ["full"] }
25* ```
26* ```
27* use terra_rust_api::{Terra, GasOptions, PrivateKey};
28* use terra_rust_api::core_types::{Coin, StdSignMsg, StdSignature};
29* use terra_rust_api::messages::{MsgSend, Message};
30* use bitcoin::secp256k1::Secp256k1;
31*
32*
33* async fn demo() -> anyhow::Result<()> {
34* // set up the LCD client
35* let gas_opts = GasOptions::create_with_gas_estimate("50ukrw",1.4)?;
36* let terra = Terra::lcd_client("https://bombay-lcd.terra.dev/", "bombay-12", &gas_opts,None);
37* // generate a private key
38* let secp = Secp256k1::new();
39* let from_key = PrivateKey::from_words(&secp,"your secret words",0,0)?;
40* let from_public_key = from_key.public_key(&secp);
41* // generate the message SEND 1000 uluna from your private key to someone else
42* let coin: Coin = Coin::parse("1000uluna")?.unwrap();
43* let from_account = from_public_key.account()?;
44* let send: Message = MsgSend::create(from_account, String::from("terra1usws7c2c6cs7nuc8vma9qzaky5pkgvm2uag6rh"), vec![coin])?;
45* // generate the transaction & calc fees
46* let messages: Vec<Message> = vec![send];
47* let (std_sign_msg, sigs) = terra
48* .generate_transaction_to_broadcast(
49* &secp,
50* &from_key,
51* messages,
52* None
53* )
54* .await?;
55* // send it out
56* let resp = terra.tx().broadcast_sync(&std_sign_msg, &sigs).await?;
57* match resp.code {
58* Some(code) => {
59* log::error!("{}", serde_json::to_string(&resp)?);
60* eprintln!("Transaction returned a {} {}", code, resp.txhash)
61* }
62* None => {
63* println!("{}", resp.txhash)
64* }
65* }
66* Ok(())
67* }
68* ```
69*/
70/// address book definition
71pub mod addressbook;
72/// APIs
73pub mod client;
74/// Error Messages
75pub mod errors;
76mod keys;
77/// definitions of the different type of Messages we have implemented
78pub mod messages;
79
80#[macro_use]
81extern crate lazy_static;
82#[macro_use]
83extern crate erased_serde;
84//extern crate rustc_serialize;
85//
86//#[macro_use]
87//extern crate error_chain;
88extern crate reqwest;
89//use crate::Error;
90
91pub use crate::client_types::{
92 terra_datetime_format, terra_decimal_format, terra_f64_format, terra_opt_decimal_format,
93 terra_opt_u64_format, terra_u64_format,
94};
95pub use addressbook::AddressBook;
96pub use client::lcd_types::{LCDResult, LCDResultVec, LCDTypeValue};
97pub use client::{auth_types, client_types, core_types, staking_types, tendermint_types};
98pub use client::{GasOptions, Terra};
99pub use keys::{PrivateKey, PublicKey, Signature};
100pub use messages::bank;
101pub use messages::wasm::MsgExecuteContract;
102pub use messages::Message;