Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support expiration policy #6833

Draft
wants to merge 1 commit into
base: feature/zk-opcodes
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions sway-lib-std/src/tx.sw
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub const GTF_POLICY_TIP = 0x501;
pub const GTF_POLICY_WITNESS_LIMIT = 0x502;
pub const GTF_POLICY_MATURITY = 0x503;
pub const GTF_POLICY_MAX_FEE = 0x504;
pub const GTF_POLICY_EXPIRATION = 0x505;

/// A transaction type.
pub enum Transaction {
Expand Down Expand Up @@ -130,6 +131,7 @@ const TIP_POLICY: u32 = 1u32 << 0;
const WITNESS_LIMIT_POLICY: u32 = 1u32 << 1;
const MATURITY_POLICY: u32 = 1u32 << 2;
const MAX_FEE_POLICY: u32 = 1u32 << 3;
const EXPIRATION_POLICY: u32 = 1u32 << 4;

/// Returns policies bits. It can be used to identify which policies are set.
fn policies() -> u32 {
Expand Down Expand Up @@ -256,6 +258,31 @@ pub fn tx_max_fee() -> Option<u64> {
}
}

/// Get the expiration for the transaction, if it is set.
///
/// # Returns
///
/// * [Option<u32>] - The expiration for the transaction.
///
/// # Examples
///
/// ```sway
/// use std::tx::tx_expiration;
///
/// fn foo() {
/// let expiration = tx_expiration().unwrap();
/// log(expiration);
/// }
/// ```
pub fn tx_expiration() -> Option<u32> {
let bits = policies();
if bits & EXPIRATION_POLICY > 0 {
Some(__gtf::<u32>(0, GTF_POLICY_EXPIRATION))
} else {
None
}
}

/// Get the length of the script for the transaction.
///
/// # Returns
Expand Down
Loading