Skip to content

Commit

Permalink
uplink: metadata support for free hint and price hint
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 29, 2024
1 parent f65a0a4 commit 6a68f92
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions piecrust-uplink/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add support for metadata elements: free limit and free price hint [#357]
- Add contract charge setting method [#353]
- Add contract allowance setting method and a corresponding passing mechanism [#350]

Expand Down Expand Up @@ -169,6 +170,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First `piecrust-uplink` release

<!-- ISSUES -->
[#357]: https://github.com/dusk-network/piecrust/issues/357
[#353]: https://github.com/dusk-network/piecrust/issues/353
[#350]: https://github.com/dusk-network/piecrust/issues/350
[#324]: https://github.com/dusk-network/piecrust/issues/324
Expand Down
33 changes: 33 additions & 0 deletions piecrust-uplink/src/abi/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ mod ext {
pub fn limit() -> u64;
pub fn spent() -> u64;
pub fn owner(contract_id: *const u8) -> i32;
pub fn free_limit(contract_id: *const u8) -> i32;
pub fn free_price_hint(contract_id: *const u8) -> i32;
pub fn self_id();
}
}
Expand Down Expand Up @@ -292,6 +294,37 @@ pub fn owner<const N: usize>(contract: ContractId) -> Option<[u8; N]> {
}
}

/// Returns given contract's free limit, if the contract exists and if it
/// has a free limit set.
pub fn free_limit(contract: ContractId) -> Option<u64> {
let contract_id_ptr = contract.as_bytes().as_ptr();
unsafe {
match ext::free_limit(contract_id_ptr) as usize {
0 => None,
arg_pos => with_arg_buf(|buf, _| {
let ret = archived_root::<Option<u64>>(&buf[..arg_pos]);
ret.deserialize(&mut Infallible).expect("Infallible")
}),
}
}
}

/// Returns given contract's free gas price hint, if the contract exists and
/// if it has a free price hint set.
pub fn free_price_hint(contract: ContractId) -> Option<(u64, u64)> {
let contract_id_ptr = contract.as_bytes().as_ptr();

unsafe {
match ext::free_price_hint(contract_id_ptr) as usize {
0 => None,
arg_pos => with_arg_buf(|buf, _| {
let ret = archived_root::<Option<(u64, u64)>>(&buf[..arg_pos]);
ret.deserialize(&mut Infallible).expect("Infallible")
}),
}
}
}

/// Returns the current contract's owner.
pub fn self_owner<const N: usize>() -> [u8; N] {
unsafe { ext::owner(ptr::null()) };
Expand Down

0 comments on commit 6a68f92

Please sign in to comment.