dusk_abi/
lib.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7//! ![Build Status](https://github.com/dusk-network/dusk-abi/workflows/Continuous%20integration/badge.svg)
8//! [![Repository](https://img.shields.io/badge/github-dusk--abi-blueviolet?logo=github)](https://github.com/dusk-network/dusk-abi)
9//! [![Documentation](https://img.shields.io/badge/docs-dusk--abi-blue?logo=rust)](https://docs.rs/dusk-abi/)
10
11//! # Dusk ABI
12//!
13//! The official ABI to develop dusk-network contracts and host module for Rusk
14//! VM
15//!
16//! See [Rusk VM](https://github.com/dusk-network/rusk-vm) for further details,
17//! test cases and usage.
18
19#![warn(missing_docs)]
20#![no_std]
21#![feature(core_intrinsics, lang_items, alloc_error_handler)]
22
23mod types;
24pub use types::contract::{ContractId, ContractState};
25pub use types::query::Query;
26pub use types::return_value::ReturnValue;
27pub use types::transaction::Transaction;
28
29/// The trait that host modules uses to defines their own ID for both host and
30/// hosted environment
31pub trait Module {
32    /// Returns the id that identifies this module
33    fn id() -> ContractId
34    where
35        Self: Sized;
36
37    /// Returns the module's id from the object instance
38    fn module_id(&self) -> ContractId
39    where
40        Self: Sized,
41    {
42        Self::id()
43    }
44}
45
46cfg_if::cfg_if! {
47    if #[cfg(target_arch = "wasm32")] {
48        // re-export WeeAlloc
49        pub use wee_alloc::WeeAlloc;
50
51        #[doc(hidden)]
52        pub mod hosted;
53        pub use hosted::*;
54    } else {
55        #[doc(hidden)]
56        pub mod host;
57        pub use host::*;
58    }
59}