-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(template-lib)!: improve initial supply api resource builder (#1040)
Description --- Improve API for resource builder with initial supply. Rename XTR2 constant to XTR Add `Bucket::join` Motivation and Context --- Previously if you provided an initial supply for the resource builder and called `build()` a panic would occur. This PR changes `initial_supply` to immediately build and return the bucket preventing the user from making the above error at compile time. Previous API: ```rust let bucket = ResourceBuilder::fungible().initial_supply(1000).build_bucket() ``` ```rust // will panic at runtime let bucket = ResourceBuilder::fungible().build_bucket() ``` New API: ```rust let bucket = ResourceBuilder::fungible().initial_supply(1000); let bucket = ResourceBuilder::non_fungible() .initial_supply((1..=100).map(NonFungibleId::from_u32)); let confidential = ResourceBuilder::confidential() .initial_supply(confidential_supply); ``` How Has This Been Tested? --- Existing engine tests updated What process can a PR reviewer use to test or verify this change? --- Update existing templates to use the new API Breaking Changes --- - [ ] None - [ ] Requires data directory to be deleted - [x] Other - Please specify BREAKING CHANGE: templates that previously built resources with initial supply will no longer compile. The ABI for buckets adds `Join`. Since the integer representation of the ops shifts by 1 after `Join` some bucket operations will be invalid on previous WASM. i.e. WASM needs to be recompiled. --------- Co-authored-by: stringhandler <mikethetike@tari.com>
- Loading branch information
1 parent
9a484a7
commit 8ff9cb6
Showing
34 changed files
with
336 additions
and
287 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,27 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use tari_template_lib::{args, models::ComponentAddress}; | ||
use tari_template_test_tooling::{support::confidential::generate_confidential_proof, TemplateTest}; | ||
|
||
#[test] | ||
fn fungible_join() { | ||
let mut test = TemplateTest::new(vec!["tests/templates/resource"]); | ||
let component: ComponentAddress = test.call_function("ResourceTest", "new", args![], vec![]); | ||
test.call_method::<()>(component, "fungible_join", args![], vec![]); | ||
} | ||
|
||
#[test] | ||
fn non_fungible_join() { | ||
let mut test = TemplateTest::new(vec!["tests/templates/resource"]); | ||
let component: ComponentAddress = test.call_function("ResourceTest", "new", args![], vec![]); | ||
test.call_method::<()>(component, "non_fungible_join", args![], vec![]); | ||
} | ||
|
||
#[test] | ||
fn confidential_join() { | ||
let mut test = TemplateTest::new(vec!["tests/templates/resource"]); | ||
let component: ComponentAddress = test.call_function("ResourceTest", "new", args![], vec![]); | ||
let (output, _, _) = generate_confidential_proof(1000.into(), None); | ||
test.call_method::<()>(component, "confidential_join", args![output], vec![]); | ||
} |
This file contains 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 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 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 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 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 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 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,14 @@ | ||
[workspace] | ||
[package] | ||
name = "hello_world" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tari_template_lib = { path = "../../../../template_lib" } | ||
|
||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] |
Oops, something went wrong.