Crate odra

Crate odra 

Source
Expand description

A Rust library for writing smart contracts for the Casper Blockchain.

§Example

The following example is a simple counter smart contract. The contract stores a single value, which can be incremented or decremented. The counter value can be initialized at contract creation time.

use odra::prelude::*;

#[odra::module]
struct Counter {
    count: Var<u32>,
}

#[odra::module]
impl Counter {
    pub fn init(&mut self, count: u32) {
        self.count.set(count);
    }

    pub fn increment(&mut self) {
        self.count.set(self.count.get_or_default() + 1);
    }

    pub fn decrement(&mut self) {
        self.count.set(self.count.get_or_default() - 1);
    }

    pub fn get_count(&self) -> u32 {
        self.count.get_or_default()
    }
}

Re-exports§

pub use odra_core::casper_event_standard;
pub use odra_core::casper_types;
pub use odra_schema as schema;

Modules§

args
This module provides types and traits for working with entrypoint arguments.
contract_def
Encapsulates a set of structures that abstract out a smart contract layout.
entry_point_callback
A module that contains structs representing entry points and entry point callers.
host
A module that provides the interface for interacting with the host environment.
module
Module definition and implementation.
named_keys
Macros for creating Odra modules that store values in named keys or dictionaries.
prelude
Common API for no_std and std to access alloc and core crate types.
uints
Unsigned integer utilities.
utils
General purpose utilities.

Structs§

CallDef
Represents a call definition, which includes the method name, runtime arguments, attached value, and mutability flag.
ContractCallResult
Represents the result of a contract call.
ContractEnv
Represents the environment accessible in the contract context.
ExecutionEnv
Represents the environment accessible in the contract execution context.
GasReport
A Vector of deploy reports makes a full gas report.

Enums§

AddressError
Error that can occur while operating on an Address.
CollectionError
Error that can occur while operating on a collection.
DeployReport
Represents a deploy report, which includes the gas used and the deploy details.
EventError
Event-related errors.
VmError
An internal virtual machine error

Traits§

ContractContext
Trait representing the context of a smart contract.
ContractRef
Trait that needs to be implemented by all contract refs.
OdraContract
The contract trait.

Attribute Macros§

event
This macro is used to implement the boilerplate code for the event and contract schema.
external_contract
Provides implementation of a reference to an external contract.
module
Core element of the Odra framework, entry point for writing smart contracts.
odra_error
Implements Into<OdraError> for an error enum.
odra_type
Implements boilerplate for a type to be used in an Odra module.

Derive Macros§

Event
IntoRuntimeArgs
Implements Into<odra::casper_types::RuntimeArgs> for a struct.