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:
KeyPaircontains both public and secret keys and they are used for signing transactionsPublicKeyrepresents an account public key, that is the addrress starting withGAccountis 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.
- Create
Account Operation - Create and fund a new account.
- Create
Account Operation Builder CreateAccountOperationbuilder.- Create
Passive Offer Operation - Create a passive offer.
- Create
Passive Offer Operation Builder CreatePassiveOfferOperationbuilder.- Credit
Asset - A non-native asset, identified by asset code/issuer id.
- Decorated
Signature - A
Signaturetogether with the last 4 bytes of the public key. - Inflation
Operation - Generate inflation.
- Inflation
Operation Builder InflationOperationbuilder.- Manage
Data Operation - Add data entry to the ledger.
- Manage
Data Operation Builder ManageDataOperationbuild- Manage
Offer Operation - Create, update, or delete an offer.
- Manage
Offer Operation Builder ManageOfferOperationbuilder.- Network
- A Stellar Network.
- Operation
Builder - Build an
Operation. - Path
Payment Operation - Send the specified asset to the destination account, optionally through a path.
- Path
Payment Operation Builder PathPaymentOperationbuilder.- Payment
Operation - Payment operation.
- Payment
Operation Builder PaymentOperationbuilder.- Price
- Price in fractional representation.
- Signature
- A signature.
- Signature
Hint - Last 4 bytes of a public key.
- Signed
Transaction - A transaction that was signed.
- Stroops
- Amount in stroops.
- Time
Bounds - A time range for the validity of an operation.
- Transaction
- A transaction containing operations that change the ledger state.
- Transaction
Builder Transactionbuilder.- Unix
Timestamp - 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
Resultalias whereErroris ashuttle_core::Error.