Repository navigation
Functions for retrieving AssetId and Amount #61
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
50b3c84
added functions for retrieving the AssetId and Amount
aritkulova 931dc05
renamed asset_id_amount directory to utxo
aritkulova 85bd48f
updated tests to have different amounts for input and output of the s…
aritkulova 3035141
optimised getters
aritkulova bae273b
restructured doc comment;
aritkulova cb2761a
test refactoring:
aritkulova bf337e8
refactoring and typo fixes
aritkulova 05f00be
test refactoring:
aritkulova bbf2dbb
refactored doc comments
aritkulova 9da729a
excess doc commets
aritkulova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.