Crate shuttle_core

Source
Expand description

§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 transactions
  • PublicKey represents an account public key, that is the addrress starting with G
  • 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();

Re-exports§

pub use self::crypto::init;
pub use self::crypto::KeyPair;
pub use self::crypto::PublicKey;
pub use self::crypto::SecretKey;

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
CreateAccountOperation builder.
CreatePassiveOfferOperation
Create a passive offer.
CreatePassiveOfferOperationBuilder
CreatePassiveOfferOperation builder.
CreditAsset
A non-native asset, identified by asset code/issuer id.
DecoratedSignature
A Signature together with the last 4 bytes of the public key.
InflationOperation
Generate inflation.
InflationOperationBuilder
InflationOperation builder.
ManageDataOperation
Add data entry to the ledger.
ManageDataOperationBuilder
ManageDataOperation build
ManageOfferOperation
Create, update, or delete an offer.
ManageOfferOperationBuilder
ManageOfferOperation builder.
Network
A Stellar Network.
OperationBuilder
Build an Operation.
PathPaymentOperation
Send the specified asset to the destination account, optionally through a path.
PathPaymentOperationBuilder
PathPaymentOperation builder.
PaymentOperation
Payment operation.
PaymentOperationBuilder
PaymentOperation builder.
Price
Price in fractional representation.
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
Transaction builder.
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 Aliases§

Result
A Result alias where Error is a shuttle_core::Error.