pub struct FinishResult(/* private fields */);Expand description
Return type for Smart Feature entry points.
Wraps the i32 the host inspects after a Smart Feature’s WASM function
returns:
- positive (
> 0) → the Smart Feature allows the native transaction to proceed 0→ the Smart Feature blocks the transaction (no specific error)- negative (
< 0) → the Smart Feature blocks and propagates an error code
Both 0 and negative values are rejections (per XLS-100: a return value
greater than zero allows the operation, otherwise it is blocked). The
distinction is purely for diagnostic purposes: 0 is a clean rejection, while a
negative value carries an error code whose meaning is defined by the contract author.
For example, -6 might represent the result of a failed host call, but the same
value could carry a different contract-defined meaning.
Construct with FinishResult::succeed / FinishResult::reject for the
common cases, or FinishResult::succeed_with / FinishResult::reject_with
for a custom code. From<i32> is also implemented so error codes from host
calls (e.g. e.code()) can be propagated directly:
return e.code().into();
Implementations§
Source§impl FinishResult
impl FinishResult
Sourcepub fn succeed_with<const N: i32>() -> Self
pub fn succeed_with<const N: i32>() -> Self
Allow the Smart Feature with a custom positive code.
N must be a positive compile-time constant; passing a non-positive value
is a compile-time error. The code is recorded in the WasmReturnCode
ledger metadata field and can be used for diagnostics.
let result = FinishResult::succeed_with::<42>();
assert_eq!(i32::from(result), 42);Sourcepub fn reject_with<const N: i32>() -> Self
pub fn reject_with<const N: i32>() -> Self
Block the Smart Feature with a custom non-positive error code.
N must be non-positive (≤ 0) at compile time; passing a positive value
is a compile-time error. The code is recorded in the WasmReturnCode
ledger metadata field and can be used for diagnostics.
let result = FinishResult::reject_with::<-5>();
assert_eq!(i32::from(result), -5);Trait Implementations§
Source§impl Clone for FinishResult
impl Clone for FinishResult
Source§fn clone(&self) -> FinishResult
fn clone(&self) -> FinishResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more