shuttle_core/
lib.rs

1#![deny(warnings)]
2#![deny(missing_docs)]
3#![deny(missing_debug_implementations)]
4
5//! # shuttle-core
6//!
7//! The `shuttle-core` crate provides an high-level library to read, write and
8//! sign the XDR structures used in the Stellar Network Protocol.
9//!
10//! ## KeyPair, PublicKey, and Account
11//!
12//! In `shuttle-core` there are three structures that represent accounts:
13//!
14//! - `KeyPair` contains both public and secret keys and they are used for signing
15//!   transactions
16//! - `PublicKey` represents an account public key, that is the addrress starting
17//!   with `G`
18//! - `Account` is a public key with the associated sequence number.
19//!
20//! ```ignore
21//! let random_keypair = KeyPair::random().unwrap();
22//! let keypair = KeyPair::from_secret("SDFRU2NGDPXYIY67BVS6L6W4OY33HCFCEJQ73TZZPR3IDYVVI7BVPV5Q").unwrap();
23//! let public_key = keypair.public_key();
24//!
25//! // Create public key only
26//! let address = PublicKey::from_account_id("GBR6A7TTX6MUYO6WZXZFAX3L2QSLYIHIGKN52EBNVKKB4AN4B6CRD22T").unwrap();
27//!
28//! // Create account
29//! let account = Account::new(address, 0);
30//! ```
31//!
32//! ## Asset and Amount
33//!
34//! The Stellar Network has two different types of assets: native and credit assets.
35//! You can create them with `Asset::native` and `Asset::credit`.
36//!
37//! `Amount` represent an amount of the native asset, a.k.a. Lumens.
38//!
39//! ```ignore
40//! let xlm = Asset::native();
41//! let btc = Asset::credit("BTC", issuer_key).unwrap();
42//!
43//! // Parse string as amount, will error if more than 7 digits
44//! let amount = Amount::from_str("123.4567").unwrap();
45//! ```
46//!
47//!
48//! ## Creating Transactions
49//!
50//! `shuttle-core` uses the builder pattern for transactions and operations.
51//! Once you have a `SignedTransaction` you can serialize it to the base64 representation
52//! of the transaction envelope and submit it to the network.
53//! Alternatively, you can inspect it in the [Stellar Laboraty](https://www.stellar.org/laboratory/).
54//!
55//! ```ignore
56//! let tx = TransactionBuilder::new(&mut source_account)
57//!     .operation(
58//!         OperationBuilder::payment(destination_address, asset, amount).build()
59//!     )
60//!     .with_memo(memo)
61//!     .build();
62//! let signed_tx = tx.sign(&source_keypair, &network).unwrap();
63//! let encoded = signed_tx.to_base64().unwrap();
64//!
65//! // You can decode a transaction as well
66//! let new_signed_tx = SignedTransaction::from_base64(&encode).unwrap();
67//! ```
68extern crate base32;
69extern crate base64;
70extern crate bigdecimal;
71extern crate byteorder;
72extern crate crc16;
73extern crate num_bigint;
74extern crate num_traits;
75extern crate sodiumoxide;
76
77extern crate serde;
78extern crate serde_bytes;
79#[macro_use]
80extern crate serde_derive;
81extern crate serde_xdr;
82
83mod error;
84
85pub mod crypto;
86
87mod amount;
88mod account;
89mod asset;
90mod memo;
91mod network;
92mod time_bounds;
93mod operation;
94mod operation_builder;
95mod signature;
96mod transaction;
97mod transaction_builder;
98
99mod xdr;
100
101pub use self::crypto::{init, KeyPair, PublicKey, SecretKey};
102pub use self::error::{Error, Result};
103pub use self::amount::{Amount, Price, Stroops};
104pub use self::account::Account;
105pub use self::asset::{Asset, CreditAsset};
106pub use self::memo::Memo;
107pub use self::network::Network;
108pub use self::time_bounds::{TimeBounds, UnixTimestamp};
109pub use self::operation::{CreateAccountOperation, CreatePassiveOfferOperation, InflationOperation,
110                          ManageDataOperation, ManageOfferOperation, Operation,
111                          PathPaymentOperation, PaymentOperation};
112
113pub use self::operation_builder::{CreateAccountOperationBuilder,
114                                  CreatePassiveOfferOperationBuilder, InflationOperationBuilder,
115                                  ManageDataOperationBuilder, ManageOfferOperationBuilder,
116                                  OperationBuilder, PathPaymentOperationBuilder,
117                                  PaymentOperationBuilder};
118pub use self::signature::{DecoratedSignature, Signature, SignatureHint};
119pub use self::transaction::{SignedTransaction, Transaction};
120pub use self::transaction_builder::TransactionBuilder;
121
122pub use self::xdr::{FromXdr, ToXdr};