diff --git a/piecrust-uplink/CHANGELOG.md b/piecrust-uplink/CHANGELOG.md index b951a591..c4a11650 100644 --- a/piecrust-uplink/CHANGELOG.md +++ b/piecrust-uplink/CHANGELOG.md @@ -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] @@ -169,6 +170,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - First `piecrust-uplink` release +[#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 diff --git a/piecrust-uplink/src/abi/state.rs b/piecrust-uplink/src/abi/state.rs index b1a76616..46896dec 100644 --- a/piecrust-uplink/src/abi/state.rs +++ b/piecrust-uplink/src/abi/state.rs @@ -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(); } } @@ -292,6 +294,37 @@ pub fn owner(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 { + 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::>(&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::>(&buf[..arg_pos]); + ret.deserialize(&mut Infallible).expect("Infallible") + }), + } + } +} + /// Returns the current contract's owner. pub fn self_owner() -> [u8; N] { unsafe { ext::owner(ptr::null()) };