stellar_base/
lib.rs

1//! # Stellar Base
2//!
3//! The `stellar-base` crate provides low level Stellar types.
4//!
5//!  - Create and sign transactions
6//!  - Encode and decode Stellar objects from XDR
7//!
8//! If you are looking for a way to interact with Horizon, take a
9//! look at [`stellar-horizon`](https://docs.rs/stellar-horizon).
10//!
11//!
12//! ## Creating a KeyPair
13//!
14//! A Stellar KeyPair contains a Secretkey and a PublicKey. You can
15//! use the PublicKey to identify the Stellar account, and the SecretKey
16//! to sign transactions.
17//!
18//! ```rust
19//! use stellar_base::crypto::{DalekKeyPair};
20//!
21//! # fn run() -> stellar_base::error::Result<()> {
22//! let random_kp = DalekKeyPair::random()?;
23//! println!("Account Id = {}", random_kp.public_key().account_id());
24//! # Ok(())
25//! # }
26//! ```
27//!
28//!
29//! # Creating and signing a Transaction
30//!
31//! You can use this crate to create Stellar transactions and serialize them
32//! to XDR.
33//!
34//! ```rust
35//! use stellar_base::amount::Amount;
36//! use stellar_base::asset::Asset;
37//! use stellar_base::crypto::{PublicKey, DalekKeyPair};
38//! use stellar_base::memo::Memo;
39//! use stellar_base::network::Network;
40//! use stellar_base::operations::Operation;
41//! use stellar_base::transaction::{Transaction, MIN_BASE_FEE};
42//! use stellar_base::xdr::XDRSerialize;
43//! use std::str::FromStr;
44//!
45//! # fn run() -> stellar_base::error::Result<()> {
46//! let source_kp = DalekKeyPair::random()?;
47//! let destination = PublicKey::from_account_id("GATTMQEODSDX45WZK2JFIYETXWYCU5GRJ5I3Z7P2UDYD6YFVONDM4CX4")?;
48//!
49//! let payment_amount = Amount::from_str("13.12")?;
50//!
51//! let payment = Operation::new_payment()
52//!     .with_destination(destination)
53//!     .with_amount(payment_amount)?
54//!     .with_asset(Asset::new_native())
55//!     .build()?;
56//!
57//! let mut tx = Transaction::builder(source_kp.public_key(), 1234, MIN_BASE_FEE)
58//!     .with_memo(Memo::new_id(7483792))
59//!     .add_operation(payment)
60//!     .into_transaction()?;
61//!
62//! tx.sign(&source_kp.as_ref(), &Network::new_test());
63//! let xdr = tx.into_envelope().xdr_base64()?;
64//! println!("Xdr = {}", xdr);
65//! # Ok(())
66//! # }
67//! ```
68//!
69#[macro_use]
70extern crate bitflags;
71extern crate chrono;
72extern crate json;
73
74pub mod account;
75pub mod amount;
76pub mod asset;
77pub mod claim;
78pub mod crypto;
79pub mod error;
80pub mod ledger;
81pub mod liquidity_pool;
82pub mod memo;
83pub mod network;
84pub mod operation_result;
85pub mod operations;
86pub mod time_bounds;
87pub mod transaction;
88pub mod transaction_result;
89pub mod xdr;
90
91pub use self::asset::Asset;
92pub use self::crypto::PublicKey;
93pub use self::memo::Memo;
94pub use self::network::Network;
95pub use self::operation_result::OperationResult;
96pub use self::operations::Operation;
97pub use self::transaction::Transaction;
98pub use self::transaction_result::TransactionResult;