Module 0x2::timelock
A timelock implementation.
- Resource
TimeLock
- Constants
- Function
lock
- Function
lock_with_label
- Function
lock_and_transfer
- Function
lock_with_label_and_transfer
- Function
unlock
- Function
unlock_with_clock
- Function
join
- Function
join_vec
- Function
split
- Function
split_balance
- Function
transfer_to_sender
- Function
system_pack
- Function
system_unpack
- Function
type_name
- Function
expiration_timestamp_ms
- Function
is_locked
- Function
remaining_time
- Function
is_locked_with_clock
- Function
remaining_time_with_clock
- Function
locked
- Function
label
- Function
is_labeled_with
- Function
pack
- Function
unpack
- Function
transfer
- Function
remaining_time_with_timestamp
use 0x1::ascii;
use 0x1::option;
use 0x1::string;
use 0x1::type_name;
use 0x2::balance;
use 0x2::clock;
use 0x2::labeler;
use 0x2::object;
use 0x2::system_admin_cap;
use 0x2::transfer;
use 0x2::tx_context;
Resource TimeLock
TimeLock
struct that holds a locked object.
struct TimeLock<T: store> has key
Fields
Constants
For when trying to join two time-locked balances with different expiration time.
const EDifferentExpirationTime: u64 = 2;
For when trying to join two time-locked balances with different labels.
const EDifferentLabels: u64 = 3;
The lock has not expired yet.
const ENotExpiredYet: u64 = 1;
Function lock
Function to lock an object till a unix timestamp in milliseconds.
public fun lock<T: store>(locked: T, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
Implementation
Function lock_with_label
Function to lock a labeled object till a unix timestamp in milliseconds.
public fun lock_with_label<T: store, L>(_: &labeler::LabelerCap<L>, locked: T, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
Implementation
Function lock_and_transfer
Function to lock an object obj
until expiration_timestamp_ms
and transfer it to address to
.
Since Timelock<T>
does not support public transfer, use this function to lock an object to an address.
public fun lock_and_transfer<T: store>(obj: T, to: address, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext)
Implementation
Function lock_with_label_and_transfer
Function to lock a labeled object obj
until expiration_timestamp_ms
and transfer it to address to
.
Since Timelock<T>
does not support public transfer, use this function to lock a labeled object to an address.
public fun lock_with_label_and_transfer<T: store, L>(labeler: &labeler::LabelerCap<L>, obj: T, to: address, expiration_timestamp_ms: u64, ctx: &mut tx_context::TxContext)
Implementation
Function unlock
Function to unlock the object from a TimeLock
based on the epoch start time.
public fun unlock<T: store>(self: timelock::TimeLock<T>, ctx: &tx_context::TxContext): T
Implementation
Function unlock_with_clock
Function to unlock the object from a TimeLock
based on the Clock
object.
public fun unlock_with_clock<T: store>(self: timelock::TimeLock<T>, clock: &clock::Clock): T
Implementation
Function join
Join two TimeLock<Balance<T>>
together.
public fun join<T>(self: &mut timelock::TimeLock<balance::Balance<T>>, other: timelock::TimeLock<balance::Balance<T>>)
Implementation
Function join_vec
Join everything in others
with self
.
public fun join_vec<T>(self: &mut timelock::TimeLock<balance::Balance<T>>, others: vector<timelock::TimeLock<balance::Balance<T>>>)
Implementation
Function split
Split a TimeLock<Balance<T>>
and take a sub balance from it.
public fun split<T>(self: &mut timelock::TimeLock<balance::Balance<T>>, value: u64, ctx: &mut tx_context::TxContext): timelock::TimeLock<balance::Balance<T>>
Implementation
Function split_balance
Split the given TimeLock<Balance<T>>
into two parts, one with principal value
,
and transfer the newly split part to the sender address.
public entry fun split_balance<T>(self: &mut timelock::TimeLock<balance::Balance<T>>, value: u64, ctx: &mut tx_context::TxContext)
Implementation
Function transfer_to_sender
A utility function to transfer a TimeLock
to the sender.
public fun transfer_to_sender<T: store>(lock: timelock::TimeLock<T>, ctx: &tx_context::TxContext)
Implementation
Function system_pack
A utility function to pack a TimeLock
that can be invoked only by a system package.
public fun system_pack<T: store>(_: &system_admin_cap::IotaSystemAdminCap, locked: T, expiration_timestamp_ms: u64, label: option::Option<string::String>, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
Implementation
Function system_unpack
An utility function to unpack a TimeLock
that can be invoked only by a system package.
public fun system_unpack<T: store>(_: &system_admin_cap::IotaSystemAdminCap, lock: timelock::TimeLock<T>): (T, u64, option::Option<string::String>)
Implementation
Function type_name
Return a fully qualified type name with the original package IDs that is used as type related a label value.
public fun type_name<L>(): string::String
Implementation
Function expiration_timestamp_ms
Function to get the expiration timestamp of a TimeLock
.
public fun expiration_timestamp_ms<T: store>(self: &timelock::TimeLock<T>): u64
Implementation
Function is_locked
Function to check if a TimeLock
is locked based on the epoch start time.
public fun is_locked<T: store>(self: &timelock::TimeLock<T>, ctx: &tx_context::TxContext): bool
Implementation
Function remaining_time
Function to get the remaining time of a TimeLock
based on the epoch start time.
Returns 0 if the lock has expired.
public fun remaining_time<T: store>(self: &timelock::TimeLock<T>, ctx: &tx_context::TxContext): u64
Implementation
Function is_locked_with_clock
Function to check if a TimeLock
is locked based on the Clock
object.
public fun is_locked_with_clock<T: store>(self: &timelock::TimeLock<T>, clock: &clock::Clock): bool
Implementation
Function remaining_time_with_clock
Function to get the remaining time of a TimeLock
based on the Clock
object.
Returns 0 if the lock has expired.
public fun remaining_time_with_clock<T: store>(self: &timelock::TimeLock<T>, clock: &clock::Clock): u64
Implementation
Function locked
Function to get the locked object of a TimeLock
.
public fun locked<T: store>(self: &timelock::TimeLock<T>): &T
Implementation
Function label
Function to get the label of a TimeLock
.
public fun label<T: store>(self: &timelock::TimeLock<T>): option::Option<string::String>
Implementation
Function is_labeled_with
Check if a TimeLock
is labeled with the type L
.
public fun is_labeled_with<T: store, L>(self: &timelock::TimeLock<T>): bool
Implementation
Function pack
A utility function to pack a TimeLock
.
fun pack<T: store>(locked: T, expiration_timestamp_ms: u64, label: option::Option<string::String>, ctx: &mut tx_context::TxContext): timelock::TimeLock<T>
Implementation
Function unpack
An utility function to unpack a TimeLock
.
fun unpack<T: store>(lock: timelock::TimeLock<T>): (T, u64, option::Option<string::String>)
Implementation
Function transfer
A utility function to transfer a TimeLock
to a receiver.
fun transfer<T: store>(lock: timelock::TimeLock<T>, receiver: address)
Implementation
Function remaining_time_with_timestamp
An utility function to get the remaining time of a TimeLock
.
fun remaining_time_with_timestamp<T: store>(self: &timelock::TimeLock<T>, current_timestamp_ms: u64): u64