Skip to main content

dusk_forge/
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//! Contract building tools for Dusk smart contracts.
8
9#![no_std]
10#![deny(missing_docs)]
11#![deny(rustdoc::broken_intra_doc_links)]
12#![deny(unused_must_use)]
13#![deny(unused_extern_crates)]
14#![deny(clippy::pedantic)]
15#![warn(missing_debug_implementations, unreachable_pub, rustdoc::all)]
16
17/// Contract schema types and utilities.
18pub mod schema;
19
20/// Re-export the contract proc macro.
21pub use dusk_forge_contract::contract;
22
23/// Declares the topics under which an event type is emitted.
24///
25/// Event authors implement this trait once per event struct, then list the
26/// types in the `#[contract(events = [...])]` module attribute. The macro
27/// reads [`TOPICS`](ContractEvent::TOPICS) at compile time to populate the
28/// contract schema and to dispatch `decode_event` in the data driver.
29///
30/// A single struct may carry multiple topics — the topic conveys the
31/// operation while the struct carries the data — so `TOPICS` is a slice.
32///
33/// # Example
34///
35/// ```
36/// use dusk_forge::ContractEvent;
37///
38/// struct OwnershipTransferred;
39///
40/// impl ContractEvent for OwnershipTransferred {
41///     const TOPICS: &'static [&'static str] =
42///         &["ownership_transferred", "ownership_renounced"];
43/// }
44/// ```
45pub trait ContractEvent {
46    /// The topics under which this event type is emitted.
47    const TOPICS: &'static [&'static str];
48}