Skip to content
Merged
Show file tree
Hide file tree
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
168 changes: 168 additions & 0 deletions docs/stdlib.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,174 @@
"output_type": "()",
"description": "Assert that two `bool` values are equal.\n\n## Panics\nThe assertion fails."
},
{
"simplicityhl_name": "get_explicit_amount",
"section": "Amount getters",
"input_type": "u32, bool",
"output_type": "u64",
"description": "Returns the explicit amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its amount is confidential."
},
{
"simplicityhl_name": "get_confidential_amount",
"section": "Amount getters",
"input_type": "u32, bool",
"output_type": "Confidential1",
"description": "Returns the confidential amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its amount is explicit."
},
{
"simplicityhl_name": "get_explicit_input_amount",
"section": "Amount getters",
"input_type": "u32",
"output_type": "u64",
"description": "Returns the explicit amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its amount is confidential."
},
{
"simplicityhl_name": "get_confidential_input_amount",
"section": "Amount getters",
"input_type": "u32",
"output_type": "Confidential1",
"description": "Returns the confidential amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its amount is explicit."
},
{
"simplicityhl_name": "get_explicit_output_amount",
"section": "Amount getters",
"input_type": "u32",
"output_type": "u64",
"description": "Returns the explicit amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its amount is confidential."
},
{
"simplicityhl_name": "get_confidential_output_amount",
"section": "Amount getters",
"input_type": "u32",
"output_type": "Confidential1",
"description": "Returns the confidential amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its amount is explicit."
},
{
"simplicityhl_name": "get_explicit_current_amount",
"section": "Amount getters",
"input_type": "()",
"output_type": "u64",
"description": "Returns the explicit input amount at the current_index.\n\n## Panics\nPanics if amount is confidential."
},
{
"simplicityhl_name": "get_confidential_current_amount",
"section": "Amount getters",
"input_type": "()",
"output_type": "Confidential1",
"description": "Returns the confidential input amount at the current_index.\n\n## Panics\nPanics if amount is explicit."
},
{
"simplicityhl_name": "get_explicit_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "u32, bool",
"output_type": "(u256, u64)",
"description": "Returns explicit asset_id and amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id and amount are confidential."
},
{
"simplicityhl_name": "get_confidential_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "u32, bool",
"output_type": "(Confidential1, Confidential1)",
"description": "Returns confidential asset_id and amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id and amount are explicit."
},
{
"simplicityhl_name": "get_explicit_input_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "u32",
"output_type": "(u256, u64)",
"description": "Returns explicit asset_id and amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id and amount are confidential."
},
{
"simplicityhl_name": "get_confidential_input_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "u32",
"output_type": "(Confidential1, Confidential1)",
"description": "Returns confidential asset_id and amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id and amount are explicit."
},
{
"simplicityhl_name": "get_explicit_output_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "u32",
"output_type": "(u256, u64)",
"description": "Returns explicit asset_id and amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id and amount are confidential."
},
{
"simplicityhl_name": "get_confidential_output_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "u32",
"output_type": "(Confidential1, Confidential1)",
"description": "Returns confidential asset_id and amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id and amount are explicit."
},
{
"simplicityhl_name": "get_explicit_current_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "()",
"output_type": "(u256, u64)",
"description": "Returns explicit input asset_id and amount at the current_index.\n\n## Panics\nPanics if asset_id and amount are confidential."
},
{
"simplicityhl_name": "get_confidential_current_asset_id_with_amount",
"section": "AssetId and Amount getters",
"input_type": "()",
"output_type": "(Confidential1, Confidential1)",
"description": "Returns confidential input asset_id and amount at the current_index.\n\n## Panics\nPanics if asset_id and amount are explicit."
},
{
"simplicityhl_name": "get_explicit_asset_id",
"section": "AssetId getters",
"input_type": "u32, bool",
"output_type": "u256",
"description": "Returns the explicit asset_id at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id is confidential."
},
{
"simplicityhl_name": "get_confidential_asset_id",
"section": "AssetId getters",
"input_type": "u32, bool",
"output_type": "Confidential1",
"description": "Returns the confidential asset_id at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id is explicit."
},
{
"simplicityhl_name": "get_explicit_input_asset_id",
"section": "AssetId getters",
"input_type": "u32",
"output_type": "u256",
"description": "Returns the explicit asset_id at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id is confidential."
},
{
"simplicityhl_name": "get_confidential_input_asset_id",
"section": "AssetId getters",
"input_type": "u32",
"output_type": "Confidential1",
"description": "Returns the confidential asset_id at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id is explicit."
},
{
"simplicityhl_name": "get_explicit_output_asset_id",
"section": "AssetId getters",
"input_type": "u32",
"output_type": "u256",
"description": "Returns the explicit asset_id at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id is confidential."
},
{
"simplicityhl_name": "get_confidential_output_asset_id",
"section": "AssetId getters",
"input_type": "u32",
"output_type": "Confidential1",
"description": "Returns the confidential asset_id at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id is explicit."
},
{
"simplicityhl_name": "get_explicit_current_asset_id",
"section": "AssetId getters",
"input_type": "()",
"output_type": "u256",
"description": "Returns the explicit input asset_id at the current_index.\n\n## Panics\nPanics if asset_id is confidential."
},
{
"simplicityhl_name": "get_confidential_current_asset_id",
"section": "AssetId getters",
"input_type": "()",
"output_type": "Confidential1",
"description": "Returns the confidential input asset_id at the current_index.\n\n## Panics\nPanics if asset_id is explicit."
},
{
"simplicityhl_name": "not",
"section": "Binary logic",
Expand Down
80 changes: 80 additions & 0 deletions simf/lib/utxo/getters/amount.simf
Comment thread
aritkulova marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/// Functions for retrieving Amount
///
/// If you need both `Amount` and `AssetId`, it is recommended to use the corresponding
/// function from the `asset_id_with_amount` file, because all `get_amount` functions
/// also return the `AssetId`. Using `get_amount` and `get_asset_id` together results
/// in unnecessary overhead.

/// Returns the explicit amount at the specified input or output.
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn get_explicit_amount(index: u32, is_input_index: bool) -> u64 {
let (
_,
amount
): (Asset1, Amount1) = match is_input_index {
true => unwrap(jet::input_amount(index)),
false => unwrap(jet::output_amount(index)),
};

unwrap_right::<(u1, u256)>(amount)
}

/// Returns the confidential amount at the specified input or output
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn get_confidential_amount(index: u32, is_input_index: bool) -> Confidential1 {
let (
_,
amount
): (Asset1, Amount1) = match is_input_index {
true => unwrap(jet::input_amount(index)),
false => unwrap(jet::output_amount(index)),
};

unwrap_left::<u64>(amount)
}

/// Returns the explicit amount at the specified input
pub fn get_explicit_input_amount(index: u32) -> u64 {
let (_, amount): (Asset1, Amount1) = unwrap(jet::input_amount(index));

unwrap_right::<(u1, u256)>(amount)
}

/// Returns the confidential amount at the specified input
pub fn get_confidential_input_amount(index: u32) -> Confidential1 {
let (_, amount): (Asset1, Amount1) = unwrap(jet::input_amount(index));

unwrap_left::<u64>(amount)
}

/// Returns the explicit amount at the specified output
pub fn get_explicit_output_amount(index: u32) -> u64 {
let (_, amount): (Asset1, Amount1) = unwrap(jet::output_amount(index));

unwrap_right::<(u1, u256)>(amount)
}

/// Returns the confidential amount at the specified output
pub fn get_confidential_output_amount(index: u32) -> Confidential1 {
let (_, amount): (Asset1, Amount1) = unwrap(jet::output_amount(index));

unwrap_left::<u64>(amount)
}

/// Returns the explicit input amount at the current_index
pub fn get_explicit_current_amount() -> u64 {
let (_, amount): (Asset1, Amount1) = jet::current_amount();

unwrap_right::<(u1, u256)>(amount)
}

/// Returns the confidential input amount at the current_index
pub fn get_confidential_current_amount() -> Confidential1 {
let (_, amount): (Asset1, Amount1) = jet::current_amount();

unwrap_left::<u64>(amount)
}
69 changes: 69 additions & 0 deletions simf/lib/utxo/getters/asset_id.simf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// Functions for retrieving AssetId

/// Returns the explicit asset_id at the specified input or output
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn get_explicit_asset_id(index: u32, is_input_index: bool) -> u256 {
let asset: Asset1 = match is_input_index {
true => unwrap(jet::input_asset(index)),
false => unwrap(jet::output_asset(index)),
};

unwrap_right::<(u1, u256)>(asset)
}

/// Returns the confidential asset_id at the specified input or output
///
/// Warning: using this incurs the overhead, and should be used only when the input/output selection
/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly.
pub fn get_confidential_asset_id(index: u32, is_input_index: bool) -> Confidential1 {
let asset: Asset1 = match is_input_index {
true => unwrap(jet::input_asset(index)),
false => unwrap(jet::output_asset(index)),
};

unwrap_left::<u256>(asset)
}

/// Returns the explicit asset_id at the specified input
pub fn get_explicit_input_asset_id(index: u32) -> u256 {
let asset: Asset1 = unwrap(jet::input_asset(index));

unwrap_right::<(u1, u256)>(asset)
}

/// Returns the confidential asset_id at the specified input
pub fn get_confidential_input_asset_id(index: u32) -> Confidential1 {
let asset: Asset1 = unwrap(jet::input_asset(index));

unwrap_left::<u256>(asset)
}

/// Returns the explicit asset_id at the specified output
pub fn get_explicit_output_asset_id(index: u32) -> u256 {
let asset: Asset1 = unwrap(jet::output_asset(index));

unwrap_right::<(u1, u256)>(asset)
}

/// Returns the confidential asset_id at the specified output
pub fn get_confidential_output_asset_id(index: u32) -> Confidential1 {
let asset: Asset1 = unwrap(jet::output_asset(index));

unwrap_left::<u256>(asset)
}

/// Returns the explicit input asset_id at the current_index
pub fn get_explicit_current_asset_id() -> u256 {
let asset: Asset1 = jet::current_asset();

unwrap_right::<(u1, u256)>(asset)
}

/// Returns the confidential input asset_id at the current_index
pub fn get_confidential_current_asset_id() -> Confidential1 {
let asset: Asset1 = jet::current_asset();

unwrap_left::<u256>(asset)
}
Loading
Loading