2 releases

0.1.1 Apr 26, 2024
0.1.0 Apr 26, 2024

#860 in #sdk

27 downloads per month

Apache-2.0

35KB
642 lines

Zephyr Rust SDK


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

~12–16MB
~334K SLoC