From 4e6500d4de32526677163f074cae102f534d82ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Tue, 3 Sep 2024 17:40:50 +0200 Subject: [PATCH] alice-contract: add `transfer_to_contract` function --- contracts/alice/src/lib.rs | 5 +++++ contracts/alice/src/state.rs | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/contracts/alice/src/lib.rs b/contracts/alice/src/lib.rs index 975bc2d147..291ae8dc67 100644 --- a/contracts/alice/src/lib.rs +++ b/contracts/alice/src/lib.rs @@ -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)) + } } diff --git a/contracts/alice/src/state.rs b/contracts/alice/src/state.rs index 7d1c9287c5..dfbc23835d 100644 --- a/contracts/alice/src/state.rs +++ b/contracts/alice/src/state.rs @@ -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)] @@ -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"); } }