-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathlock_with_energy_module.rs
More file actions
49 lines (41 loc) · 1.42 KB
/
lock_with_energy_module.rs
File metadata and controls
49 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::energy_factory_lock_proxy;
multiversx_sc::imports!();
#[multiversx_sc::module]
pub trait LockWithEnergyModule {
#[only_owner]
#[endpoint(setLockingScAddress)]
fn set_locking_sc_address(&self, new_address: ManagedAddress) {
require!(
self.blockchain().is_smart_contract(&new_address),
"Invalid SC Address"
);
self.locking_sc_address().set(&new_address);
}
#[only_owner]
#[endpoint(setLockEpochs)]
fn set_lock_epochs(&self, lock_epochs: u64) {
self.lock_epochs().set(lock_epochs);
}
fn lock_virtual(
&self,
token_id: TokenIdentifier,
amount: BigUint,
dest_address: ManagedAddress,
energy_address: ManagedAddress,
) -> EsdtTokenPayment {
let lock_epochs = self.lock_epochs().get();
let locking_sc_address = self.locking_sc_address().get();
self.tx()
.to(locking_sc_address)
.typed(energy_factory_lock_proxy::SimpleLockEnergyProxy)
.lock_virtual(token_id, amount, lock_epochs, dest_address, energy_address)
.returns(ReturnsResult)
.sync_call()
}
#[view(getLockingScAddress)]
#[storage_mapper("lockingScAddress")]
fn locking_sc_address(&self) -> SingleValueMapper<ManagedAddress>;
#[view(getLockEpochs)]
#[storage_mapper("lockEpochs")]
fn lock_epochs(&self) -> SingleValueMapper<u64>;
}