ckb_ssri_sdk/lib.rs
1#![no_std]
2//! # CKB SSRI SDK
3//!
4//! A comprehensive framework for implementing SSRI-compliant smart contracts on the Nervos CKB blockchain.
5//!
6//! ## Overview
7//!
8//! The SSRI (Standard Smart Contract Runtime Interface) SDK provides a standardized way to develop
9//! smart contracts that are compliant with the SSRI protocol. This enables better interoperability
10//! and a more consistent development experience across the CKB ecosystem.
11//!
12//! ## Features
13//!
14//! - **Public Traits**: Pre-defined interfaces that receive first-class support within the ecosystem
15//! - **Utility Functions**: Helper functions for SSRI-VM syscalls and data handling
16//! - **Procedural Macros**: Simplify contract development with automatic SSRI method generation
17//! - **No Standard Library**: Designed for the constrained smart contract environment
18//!
19//! ## Usage
20//!
21//! Add this to your `Cargo.toml`:
22//! ```toml
23//! [dependencies]
24//! ckb_ssri_sdk = "0.1.0"
25//! ```
26//!
27//! ## Example
28//!
29//! ```rust,no_run
30//! use ckb_ssri_sdk::prelude::*;
31//! use ckb_ssri_sdk::public_module_traits::udt::UDT;
32//!
33//! // Implement a basic UDT (User-Defined Token)
34//! #[derive(Default)]
35//! struct MyToken;
36//!
37//! impl UDT for MyToken {
38//! type Error = ();
39//! // ... implement required methods
40//! }
41//! ```
42
43pub mod public_module_traits;
44pub mod prelude;
45pub mod utils;
46pub mod macros;
47
48// Re-export proc macros at crate root for convenience
49pub use macros::*;
50
51extern crate alloc;
52
53// macro_rules! ssri_entry {
54// ( $( $module:path ),* $(,)? ) => {
55// pub fn unified_dispatch(namespace_and_function: &str, args: Vec<&str>) -> Result<String, crate::error::DispatchError> {
56// $(
57// let argv = ckb_std::env::argv();
58// if argv.is_empty() {
59// return fallback::fallback().map(|_| ());
60// }
61
62// if vm_version() != u64::MAX {
63// return Err(Error::InvalidVmVersion);
64// }
65
66// set_content(&res)?;
67// if $module::EXPOSED_FUNCTIONS.contains(&namespace_and_function) {
68// return $module::dispatch_function(namespace_and_function, args);
69// }
70// )*
71// Err(crate::error::DispatchError::FunctionNotFound)
72// }
73
74// pub fn get_methods() -> Vec<&'static str> {
75// let mut methods = Vec::new();
76// $(
77// methods.extend_from_slice($module::EXPOSED_FUNCTIONS);
78// )*
79// methods
80// }
81// };
82// }
83
84#[repr(i8)]
85#[derive(Debug)]
86/// Represents possible errors that can occur during SSRI method execution
87///
88/// This enum provides a standardized set of errors that can occur when executing
89/// SSRI methods. These errors help identify issues with method discovery,
90/// argument validation, implementation status, and environment compatibility.
91///
92/// # Examples
93///
94/// ```rust
95/// use ckb_ssri_sdk::SSRIError;
96///
97/// fn example_handler() -> Result<(), SSRIError> {
98/// // Method implementation missing
99/// Err(SSRIError::SSRIMethodsNotImplemented)
100/// }
101/// ```
102pub enum SSRIError {
103 /// The requested SSRI method was not found in the contract
104 SSRIMethodsNotFound,
105 /// The arguments provided to the SSRI method were invalid
106 SSRIMethodsArgsInvalid,
107 /// The requested SSRI method is not implemented
108 SSRIMethodsNotImplemented,
109 /// The method requires a higher execution environment level
110 SSRIMethodRequireHigherLevel,
111 /// The CKB VM version is not compatible with this implementation
112 InvalidVmVersion
113}