Skip to main content

Module 0x107a::expiration_unlock_condition

use 0x2::tx_context;

Struct ExpirationUnlockCondition

The Stardust expiration unlock condition.

struct ExpirationUnlockCondition has store

Fields
owner: address

The address who owns the output before the timestamp has passed.

return_address: address

The address that is allowed to spend the locked funds after the timestamp has passed.

unix_time: u32

Before this unix time, Address Unlock Condition is allowed to unlock the output, after that only the address defined in Return Address.

Constants

The output can not be unlocked by the sender error.

const EWrongSender: u64 = 0;

Function unlock

Check the unlock condition.

public fun unlock(condition: expiration_unlock_condition::ExpirationUnlockCondition, ctx: &mut tx_context::TxContext)

Implementation

public fun unlock(condition: ExpirationUnlockCondition, ctx: &mut TxContext) { let unlock_address = condition.can_be_unlocked_by(ctx);

assert!(unlock_address == ctx.sender(), EWrongSender);

let ExpirationUnlockCondition { owner: _, return_address: _, unix_time: _, } = condition; }

Function can_be_unlocked_by

Return the address that can unlock the related output.

public fun can_be_unlocked_by(condition: &expiration_unlock_condition::ExpirationUnlockCondition, ctx: &tx_context::TxContext): address

Implementation

public fun can_be_unlocked_by(condition: &ExpirationUnlockCondition, ctx: &TxContext): address { // Unix time in seconds. let current_time = ((tx_context::epoch_timestamp_ms(ctx) / 1000) as u32);

if (condition.unix_time() <= current_time) { condition.return_address() } else { condition.owner() } }

Function owner

Get the unlock condition's owner.

public fun owner(condition: &expiration_unlock_condition::ExpirationUnlockCondition): address

Implementation

public fun owner(condition: &ExpirationUnlockCondition): address { condition.owner }

Function return_address

Get the unlock condition's return_address.

public fun return_address(condition: &expiration_unlock_condition::ExpirationUnlockCondition): address

Implementation

public fun return_address(condition: &ExpirationUnlockCondition): address { condition.return_address }

Function unix_time

Get the unlock condition's unix_time.

public fun unix_time(condition: &expiration_unlock_condition::ExpirationUnlockCondition): u32

Implementation

public fun unix_time(condition: &ExpirationUnlockCondition): u32 { condition.unix_time }