1 unstable release

Uses old Rust 2015

0.1.0 Jan 26, 2018

#20 in #submit

Apache-2.0 and GPL-3.0 licenses

25KB
584 lines

shuttle-sdk

shuttle-sdk provides a way to communicate with a Stellar Horizon Server.

Get Started

  1. Grab the latest version crates.io
  2. Read the documentation

License

Copyright 2018 Francesco Ceccon francesco@ceccon.me

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


lib.rs:

shuttle-sdk

The shuttle-sdk crate provides a way to communicate with a Stellar Horizon Server.

It provides a way to submit requests to the Horizon instance, and to build, sign, and submit transactions to the network.

Example Usage

Create and fund a new account

use shuttle_sdk::{KeyPair, Server};

const TESTNET_URL: &'static str = "https://horizon-testnet.stellar.org";

let keypair = KeyPair::random()?;
let account_id = keypair.public_key();

let server = Server::new(TESTNET_URL)?;
let response = server.friendbot(&account_id)?.send()?;
println!("response = {:?}", response);

Get a list of available assets

use shuttle_sdk::{KeyPair, Server};

const TESTNET_URL: &'static str = "https://horizon-testnet.stellar.org";

let keypair = KeyPair::random()?;
let account_id = keypair.public_key();

let server = Server::new(TESTNET_URL)?;
let response = server.assets().for_code("MOBI").send()?;
println!("response = {:?}", response);

Create and Submit transaction

use std::str::FromStr;
use shuttle_sdk::{Account, KeyPair, Network, Server};
use shuttle_sdk::{Amount, OperationBuilder, TransactionBuilder};

const TESTNET_URL: &'static str = "https://horizon-testnet.stellar.org";

let keypair = KeyPair::random()?;
let account_id = keypair.public_key();
let new_keypair = KeyPair::random()?;

let server = Server::new(TESTNET_URL)?;
let network = Network::test_network();

let account_details = server.accounts().account_id(&account_id)?.send()?;
let mut account = Account::new(account_id.clone(), account_details.sequence);
let tx = TransactionBuilder::new(&mut account)
    .operation(
        OperationBuilder::create_account(
            new_keypair.public_key().clone(),
            Amount::from_str("20.0")?,
        ).build(),
    ).build();
let signed_tx = tx.sign(&keypair, &network)?;
let response = server.submit_transaction(&signed_tx)?.send()?;
println!("response = {:?}", response);

Dependencies

~43MB
~546K SLoC