Crate shuttle_core [−] [src]
shuttle-core
The shuttle-core
crate provides an high-level library to read, write and
sign the XDR structures used in the Stellar Network Protocol.
KeyPair, PublicKey, and Account
In shuttle-core
there are three structures that represent accounts:
KeyPair
contains both public and secret keys and they are used for signing transactionsPublicKey
represents an account public key, that is the addrress starting withG
Account
is a public key with the associated sequence number.
let random_keypair = KeyPair::random().unwrap(); let keypair = KeyPair::from_secret("SDFRU2NGDPXYIY67BVS6L6W4OY33HCFCEJQ73TZZPR3IDYVVI7BVPV5Q").unwrap(); let public_key = keypair.public_key(); // Create public key only let address = PublicKey::from_account_id("GBR6A7TTX6MUYO6WZXZFAX3L2QSLYIHIGKN52EBNVKKB4AN4B6CRD22T").unwrap(); // Create account let account = Account::new(address, 0);
Asset and Amount
The Stellar Network has two different types of assets: native and credit assets.
You can create them with Asset::native
and Asset::credit
.
Amount
represent an amount of the native asset, a.k.a. Lumens.
let xlm = Asset::native(); let btc = Asset::credit("BTC", issuer_key).unwrap(); // Parse string as amount, will error if more than 7 digits let amount = Amount::from_str("123.4567").unwrap();
Creating Transactions
shuttle-core
uses the builder pattern for transactions and operations.
Once you have a SignedTransaction
you can serialize it to the base64 representation
of the transaction envelope and submit it to the network.
Alternatively, you can inspect it in the Stellar Laboraty.
let tx = TransactionBuilder::new(&mut source_account) .operation( OperationBuilder::payment(destination_address, asset, amount).build() ) .with_memo(memo) .build(); let signed_tx = tx.sign(&source_keypair, &network).unwrap(); let encoded = signed_tx.to_base64().unwrap(); // You can decode a transaction as well let new_signed_tx = SignedTransaction::from_base64(&encode).unwrap();
Reexports
pub use self::crypto::init; |
Modules
crypto |
Libsodium wrappers. |
Structs
Account |
Account represents a single account in the Stellar network and its sequence number. |
Amount |
Amount in XLM. |
CreateAccountOperation |
Create and fund a new account. |
CreateAccountOperationBuilder |
|
CreatePassiveOfferOperation |
Create a passive offer. |
CreatePassiveOfferOperationBuilder |
|
CreditAsset |
A non-native asset, identified by asset code/issuer id. |
DecoratedSignature |
A |
InflationOperation |
Generate inflation. |
InflationOperationBuilder |
|
KeyPair |
The secret and public key pair of the account. |
ManageDataOperation |
Add data entry to the ledger. |
ManageDataOperationBuilder |
|
ManageOfferOperation |
Create, update, or delete an offer. |
ManageOfferOperationBuilder |
|
Network |
A Stellar Network. |
OperationBuilder |
Build an |
PathPaymentOperation |
Send the specified asset to the destination account, optionally through a path. |
PathPaymentOperationBuilder |
|
PaymentOperation |
Payment operation. |
PaymentOperationBuilder |
|
Price |
Price in fractional representation. |
PublicKey |
The public key of the account. |
SecretKey |
The secret key of the account. |
Signature |
A signature. |
SignatureHint |
Last 4 bytes of a public key. |
SignedTransaction |
A transaction that was signed. |
Stroops |
Amount in stroops. |
TimeBounds |
A time range for the validity of an operation. |
Transaction |
A transaction containing operations that change the ledger state. |
TransactionBuilder |
|
UnixTimestamp |
Unix timestamp. Number of seconds since epoch. |
Enums
Asset |
Enum representing an asset. |
Error |
The Errors that can occur. |
Memo |
Memo attached to transactions. |
Operation |
An operation that mutates the ledger. |
Traits
FromXdr |
A trait to try and deserialize an XDR object into some type. |
ToXdr |
A trait to try and serialize some type into an XDR object. |
Type Definitions
Result |
A |