burnt_glue/lib.rs
1//! A library that enables composability and reuse withing CosmWasm contracts.
2//!
3//! ## Creating Module
4//! To create a reusable module, one must create a struct that implements the
5//! [Module][crate::module::Module] trait. Simply define the associated types
6//! and provide implementations for [instantiate][crate::module::Module::instantiate],
7//! [execute][crate::module::Module::execute], and
8//! [query][crate::module::Module::query] and you will have a module ready to
9//! use with the manager.
10//!
11//! By convention, it's acceptable for modules to take references to other
12//! modules from their constructors. This allows modules to compose easily.
13//!
14//! ## Using Modules
15//! The [Manager][crate::manager::Manager] is a struct used to dynamically
16//! dispatch messages to their corresponding modules. Create a new Manager
17//! with [Manager::new][crate::manager::Manager::new] and then register
18//! modules for dynamic dispatch with [register][crate::manager::Manager::register].
19//!
20//! When implementing the entrypoints for contracts built with glue, you can
21//! simply call the corresponding functions: `execute`, `query`, and `instantiate`.
22//!
23//! Entities interacting with your contract may follow a simple convention for
24//! addressing messages to a specific module withing your contract. For
25//! `execute` and `query` calls, the `Manager` expects an object structured as
26//! follows:
27//!
28//! ```javascript
29//! { "module_name": { /* payload object to be sent to the module */ } }
30//! ```
31//!
32//! **NOTE**: The root object must contain a single key. If you attempt to
33//! address more than one module in an `execute` call, it will fail.
34//!
35//! The `Manager` will automatically strip away the root object and forward the
36//! payload object to the relevant module. The response object returned by the
37//! module will be returned directly.
38//!
39//! The `instantiate` method is only marginally different. Whereas the calls to
40//! `execute` and `query` require that caller to send a root object with only a
41//! single key, the object sent to the `instantiate` entrypoint may contain a
42//! key for each module registered with the manager, e.g.:
43//!
44//! ```javascript
45//! {
46//! "module_one": { /* payload for module one instantiation */ },
47//! "module_two": { /* payload for module two instantiation */ },
48//! /* and so on */
49//! }
50//! ```
51
52pub mod error;
53pub mod manager;
54pub mod module;
55pub mod response;
56
57#[cfg(test)]
58mod tests {
59 #[test]
60 fn it_works() {
61 let result = 2 + 2;
62 assert_eq!(result, 4);
63 }
64}