thruput-sdk 0.58.0

Thruput smart-contract SDK for Rust (rv32 guest runtime and native test harness)
Documentation
use crate::re_throw::OrSyscallThrow;
use crate::sys::{self, SyscallNo};
use thruput_xdr::types::{BlockHeight, NetworkHash, SHA256Hash, TimePoint};

/// The height of the block the current transaction executes in.
///
/// Throws a syscall exception (aborting the frame) if the host call fails.
pub fn get_block_height() -> BlockHeight {
    let mut block: BlockHeight = 0i64.into();
    sys::raw_GetBlockHeight(&mut block)
        .or_syscall_throw(SyscallNo::kGetBlockHeight);
    block
}

/// The hash of the network name -- the identifier separating this network's
/// blocks from every other network's. Constant for the life of the network.
///
/// Transaction signatures already commit to this value, so a contract can bind
/// its own off-chain signed messages to this network the same way, and a
/// message signed for one network cannot be replayed against a contract at the
/// same address on another.
///
/// Throws a syscall exception (aborting the frame) if the host call fails.
pub fn get_network_hash() -> NetworkHash {
    let mut network_hash: NetworkHash = SHA256Hash::default().into();
    sys::raw_GetNetworkHash(&mut network_hash)
        .or_syscall_throw(SyscallNo::kGetNetworkHash);
    network_hash
}

/// The timepoint of the block the current transaction executes in, as Unix
/// nanoseconds.
///
/// Fixed by the coordinator before execution begins and carried in the block's
/// header, so every node executing this block sees the same value. It is not
/// the time this call is made.
///
/// Throws a syscall exception (aborting the frame) if the host call fails.
pub fn get_block_timepoint() -> TimePoint {
    let mut timepoint: TimePoint = 0u64.into();
    sys::raw_GetBlockTimepoint(&mut timepoint)
        .or_syscall_throw(SyscallNo::kGetBlockTimepoint);
    timepoint
}