Skip to content

Commit

Permalink
alice-contract: add transfer_to_contract 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 452c019 commit 4e6500d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions contracts/alice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ mod wasm {
unsafe fn deposit(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |arg| STATE.deposit(arg))
}

#[no_mangle]
unsafe fn transfer_to_contract(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |arg| STATE.transfer_to_contract(arg))
}
}
15 changes: 13 additions & 2 deletions contracts/alice/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use execution_core::transfer::{withdraw::Withdraw, TRANSFER_CONTRACT};
use execution_core::transfer::{
withdraw::Withdraw, TransferToContract, TRANSFER_CONTRACT,
};

/// Alice contract.
#[derive(Debug, Clone)]
Expand All @@ -22,6 +24,15 @@ impl Alice {

pub fn deposit(&mut self, value: u64) {
let _: () = rusk_abi::call(TRANSFER_CONTRACT, "deposit", &value)
.expect("Transparent withdrawal transaction should succeed");
.expect("Transparent deposit transaction should succeed");
}

pub fn transfer_to_contract(&mut self, transfer: TransferToContract) {
let _: () = rusk_abi::call(
TRANSFER_CONTRACT,
"transfer_to_contract",
&transfer,
)
.expect("Transferring to contract should succeed");
}
}

0 comments on commit 4e6500d

Please sign in to comment.