From 635107e141f1790da63c8fb012418e385a6172cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Tue, 3 Sep 2024 17:41:16 +0200 Subject: [PATCH] bob-contract: add `recv_transfer` function --- contracts/bob/Cargo.toml | 2 +- contracts/bob/src/lib.rs | 5 +++++ contracts/bob/src/state.rs | 12 +++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/contracts/bob/Cargo.toml b/contracts/bob/Cargo.toml index 812a98cacc..c19b43d0ea 100644 --- a/contracts/bob/Cargo.toml +++ b/contracts/bob/Cargo.toml @@ -8,8 +8,8 @@ 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" } rkyv = { version = "0.7", default-features = false, features = ["size_32"] } bytecheck = { version = "0.6", default-features = false } dusk-bytes = "0.1" diff --git a/contracts/bob/src/lib.rs b/contracts/bob/src/lib.rs index 77e2cf6f26..5e1beb0e56 100644 --- a/contracts/bob/src/lib.rs +++ b/contracts/bob/src/lib.rs @@ -54,4 +54,9 @@ mod wasm { unsafe fn nonce(arg_len: u32) -> u32 { rusk_abi::wrap_call(arg_len, |()| STATE.nonce()) } + + #[no_mangle] + unsafe fn recv_transfer(arg_len: u32) -> u32 { + rusk_abi::wrap_call(arg_len, |arg| STATE.recv_transfer(arg)) + } } diff --git a/contracts/bob/src/state.rs b/contracts/bob/src/state.rs index 5c173f63e7..cf1e37d6c8 100644 --- a/contracts/bob/src/state.rs +++ b/contracts/bob/src/state.rs @@ -10,6 +10,7 @@ use bytecheck::CheckBytes; use dusk_bytes::Serializable; use execution_core::{ signatures::bls::{PublicKey as BlsPublicKey, Signature as BlsSignature}, + transfer::ReceiveFromContract, ContractId, }; use rkyv::{Archive, Deserialize, Serialize}; @@ -28,11 +29,16 @@ pub struct OwnerMessage { pub struct Bob { value: u8, nonce: u64, + total_dusk: u64, } impl Bob { pub const fn new() -> Self { - Self { value: 0, nonce: 0 } + Self { + value: 0, + nonce: 0, + total_dusk: 0, + } } #[allow(dead_code)] @@ -91,4 +97,8 @@ impl Bob { pub fn nonce(&mut self) -> u64 { self.nonce } + + pub fn recv_transfer(&mut self, recv: ReceiveFromContract) { + self.total_dusk += recv.value; + } }