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: odra::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§

Modules§

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

Structs§

  • Represents a call definition, which includes the method name, runtime arguments, attached value, and mutability flag.
  • Represents the result of a contract call.
  • Represents the environment accessible in the contract context.
  • Represents the environment accessible in the contract execution context.
  • A module component that is a reference to an external contract.
  • A Vector of deploy reports makes a full gas report.
  • Data structure for an indexed, iterable collection.
  • An iterator over the elements of a List.
  • Data structure for storing key-value pairs.
  • A module that stores a single value in the storage that can be read or incremented.
  • A wrapper struct for a module implementing the Module trait.
  • Data structure for storing a single value.

Enums§

Traits§

Type Aliases§

  • Represents the result of a contract call.

Attribute Macros§

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

Derive Macros§