2个版本

0.1.1 2024年4月26日
0.1.0 2024年4月26日

#826 in #SDK

Apache-2.0

35KB
642

Zephyr Rust SDK


lib.rs:

Zephyr Rust SDK

zephyr rust sdk帮助开发者为Zephyr虚拟机编写程序。

Hello Ledger 示例

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)
   }
}

依赖项

~12–16MB
~317K SLoC