Skip to content

Commit

Permalink
bob-contract: add recv_transfer function
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Leegwater Simões committed Sep 4, 2024
1 parent 4e6500d commit 3d666e1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/bob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ resolver = "2"
crate-type = ["cdylib", "rlib"]

[dependencies]
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi", features = ["debug"] }
execution-core = { version = "0.1.0", path = "../../execution-core" }
rusk-abi = { version = "0.13.0-rc", path = "../../rusk-abi" }
5 changes: 5 additions & 0 deletions contracts/bob/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ mod wasm {
unsafe fn value(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |()| STATE.value())
}

#[no_mangle]
unsafe fn recv_transfer(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |arg| STATE.recv_transfer(arg))
}
}
12 changes: 11 additions & 1 deletion contracts/bob/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use execution_core::transfer::ReceiveFromContract;

/// Bob contract.
#[derive(Debug, Clone)]
pub struct Bob {
value: u8,
total_dusk: u64,
}

impl Bob {
pub const fn new() -> Self {
Self { value: 0 }
Self {
value: 0,
total_dusk: 0,
}
}

#[allow(dead_code)]
Expand All @@ -35,4 +41,8 @@ impl Bob {
pub fn value(&mut self) -> u8 {
self.value
}

pub fn recv_transfer(&mut self, recv: ReceiveFromContract) {
self.total_dusk += recv.value;
}
}

0 comments on commit 3d666e1

Please sign in to comment.