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 69aa51f commit 635107e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/bob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 5 additions & 0 deletions contracts/bob/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
12 changes: 11 additions & 1 deletion contracts/bob/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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)]
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 635107e

Please sign in to comment.