Skip to content

Commit

Permalink
rusk-abi: new ABIs owner_raw, self_owner_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed May 7, 2024
1 parent ef56116 commit 8cb1cb2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rusk-abi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Memoize the `verify_proof` function [#1228]
- New ABIs: `owner_raw`, `self_owner_raw` [#1710]

### Changed

Expand Down Expand Up @@ -198,6 +199,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add LICENSE
- Add README.md

[#1710]: https://github.com/dusk-network/rusk/issues/1710
[#1609]: https://github.com/dusk-network/rusk/issues/1609
[#1371]: https://github.com/dusk-network/rusk/issues/1371
[#1228]: https://github.com/dusk-network/rusk/issues/1228
Expand Down
36 changes: 36 additions & 0 deletions rusk-abi/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

#[cfg(feature = "abi")]
use dusk_bytes::Serializable;
#[cfg(feature = "abi")]
use phoenix_core::PublicKey;
#[cfg(feature = "abi")]
use rkyv::{archived_root, Deserialize, Infallible};

pub use piecrust_uplink::*;

/// Compute the blake2b hash of the given bytes, returning the resulting scalar.
Expand Down Expand Up @@ -70,3 +77,32 @@ pub fn payment_info(
) -> Result<crate::PaymentInfo, ContractError> {
call(contract, "payment_info", &())
}

/// Query owner of a given contract.
#[cfg(feature = "abi")]
pub fn owner(contract: ContractId) -> Option<PublicKey> {
owner_raw(contract).map(|buf| {
let ret = unsafe { archived_root::<PublicKey>(buf.as_slice()) };
ret.deserialize(&mut Infallible).expect("Infallible")
})
}

/// Query owner of a given contract.
#[cfg(feature = "abi")]
pub fn self_owner() -> PublicKey {
let buf = self_owner_raw();
let ret = unsafe { archived_root::<PublicKey>(buf.as_slice()) };
ret.deserialize(&mut Infallible).expect("Infallible")
}

/// Query raw owner of a given contract.
#[cfg(feature = "abi")]
pub fn owner_raw(contract: ContractId) -> Option<[u8; PublicKey::SIZE]> {
piecrust_uplink::owner(contract)
}

/// Query raw self owner.
#[cfg(feature = "abi")]
pub fn self_owner_raw() -> [u8; PublicKey::SIZE] {
piecrust_uplink::self_owner()
}
2 changes: 1 addition & 1 deletion rusk-abi/tests/contracts/host_fn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl HostFnTest {
}

pub fn owner(&self) -> [u8; PublicKey::SIZE] {
rusk_abi::self_owner()
rusk_abi::self_owner_raw()
}
}

Expand Down

0 comments on commit 8cb1cb2

Please sign in to comment.