tari-project / tari-dan

BSD 3-Clause "New" or "Revised" License
5 stars 14 forks source link

fix(template-lib)!: improve initial supply api resource builder #1040

Closed sdbondi closed 1 month ago

sdbondi commented 2 months ago

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:

let bucket = ResourceBuilder::fungible().initial_supply(1000).build_bucket()
// will panic at runtime
let bucket = ResourceBuilder::fungible().build_bucket()

New API:

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

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.

github-actions[bot] commented 2 months ago

Test Results (CI)

544 tests  +3   544 :white_check_mark: +3   3h 11m 22s :stopwatch: + 1h 24m 1s  64 suites +1     0 :zzz: ±0    2 files   ±0     0 :x: ±0 

Results for commit 72aa818c. ± Comparison against base commit ad490ae3.

:recycle: This comment has been updated with latest results.