8 releases

new 0.1.6 Jun 12, 2024
0.1.5 May 28, 2024
0.1.5-rc1 Jun 12, 2024

#632 in #sdk

Download history 232/week @ 2024-04-27 96/week @ 2024-05-04 5/week @ 2024-05-11 118/week @ 2024-05-18 119/week @ 2024-05-25 13/week @ 2024-06-01

258 downloads per month

Apache-2.0

63KB
1.5K SLoC

Zephyr Rust SDK

Implementation of the Zephyr SDK for Rust. The Zephyr SDK lets you build Zephyr programs for the Mercury Cloud Execution environment.

Examples can be found at the zephyr-examples repository.

For any bugs or feature requests, please open an issue in this repository.


lib.rs:

Zephyr Rust SDK

The zephyr rust sdk aids developers in writing programs for the Zephyr Virtual Machine.

Hello Ledger Example

use rs_zephyr_sdk::{bincode, log, stellar_xdr::next::{Limits, WriteXdr}, Condition, DatabaseDerive, DatabaseInteract, EnvClient, ZephyrVal};

#[derive(DatabaseDerive, Clone)]
#[with_name("curr_seq")]
struct Sequence {
    pub current: u32,
}

#[no_mangle]
pub extern "C" fn on_close() {
   let env = EnvClient::new();
   let reader = env.reader();

   let sequence = Sequence {
       current: reader.ledger_sequence()
   };

   if let Some(last) = Sequence::read_to_rows(&env).iter().find(|x| x.current == sequence.current - 1) {
       sequence.update(&env, &[Condition::ColumnEqualTo("current".into(), bincode::serialize(&ZephyrVal::U32(last.current)).unwrap())]);
   } else {
       sequence.put(&env)
   }
}

Dependencies

~17MB
~328K SLoC