Skip to content

Commit

Permalink
multi-contract
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Oct 16, 2023
1 parent 5b5bd8c commit e463bb9
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 1 deletion.
11 changes: 11 additions & 0 deletions multicontract.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[settings]
main = "main"

[contracts.main]
name = "workshop"
add-unlabelled = true

[contracts.workshop-ev]
add-labels = ["ev"]
external-view = true

8 changes: 8 additions & 0 deletions src/workshop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ pub trait Workshop {
fn perform_add(&self, value: BigUint) {
self.sum().update(|sum| *sum += value);
}

/// The sum, but squared. An expensive operation.
#[view]
#[label("ev")]
fn sum_squared(&self) -> BigUint {
let s = self.sum().get();
s.clone() * s
}
}
219 changes: 219 additions & 0 deletions wasm-workshop-ev/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions wasm-workshop-ev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "workshop-ev-wasm"
version = "0.0.0"
authors = ["Andrei Marinica <[email protected]>"]
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
[profile.release]
codegen-units = 1
opt-level = "z"
lto = true
debug = false
panic = "abort"
[dependencies.workshop]
path = ".."

[dependencies.multiversx-sc-wasm-adapter]
version = "0.43.4"

[workspace]
members = ["."]
30 changes: 30 additions & 0 deletions wasm-workshop-ev/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 1
// Async Callback (empty): 1
// Total number of exported functions: 3

#![no_std]

// Configuration that works with rustc < 1.73.0.
// TODO: Recommended rustc version: 1.73.0 or newer.
#![feature(lang_items)]

multiversx_sc_wasm_adapter::allocator!();
multiversx_sc_wasm_adapter::panic_handler!();

multiversx_sc_wasm_adapter::external_view_init! {}

multiversx_sc_wasm_adapter::external_view_endpoints! {
workshop
(
sum_squared => sum_squared
)
}

multiversx_sc_wasm_adapter::async_callback_empty! {}
4 changes: 3 additions & 1 deletion wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
// Total number of exported functions: 4

#![no_std]
#![allow(internal_features)]

// Configuration that works with rustc < 1.73.0.
// TODO: Recommended rustc version: 1.73.0 or newer.
#![feature(lang_items)]

multiversx_sc_wasm_adapter::allocator!();
Expand Down

0 comments on commit e463bb9

Please sign in to comment.