Skip to content

Commit

Permalink
rusk-abi: introduced raw owner calls
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Jan 24, 2024
1 parent 2be24d3 commit bbb1354
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
34 changes: 31 additions & 3 deletions rusk-abi/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

#[cfg(feature = "abi")]
use crate::OwnerRaw;
use dusk_bytes::Serializable;
#[cfg(feature = "abi")]
use dusk_pki::PublicSpendKey;
#[cfg(feature = "abi")]
use rkyv::{archived_root, Deserialize, Infallible};
// re-export `piecrust-uplink` such that `rusk-abi` is the only crate
pub use piecrust_uplink::*;

/// Compute the blake2b hash of the given bytes, returning the resulting scalar.
Expand Down Expand Up @@ -75,6 +80,29 @@ pub fn payment_info(

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

/// Query owner of a given contract.
#[cfg(feature = "abi")]
pub fn self_owner() -> PublicSpendKey {
let buf = self_owner_raw();
let ret = unsafe { archived_root::<PublicSpendKey>(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; PublicSpendKey::SIZE]> {
piecrust_uplink::owner(contract)
}

/// Query raw self owner.
#[cfg(feature = "abi")]
pub fn self_owner_raw() -> [u8; PublicSpendKey::SIZE] {
piecrust_uplink::self_owner()
}
3 changes: 0 additions & 3 deletions rusk-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ pub mod hash;

use hash::Hasher;

// re-export `piecrust-uplink` such that `rusk-abi` is the only crate
pub use piecrust_uplink::*;

use dusk_bls12_381::BlsScalar;
use dusk_bytes::DeserializableSlice;

Expand Down
4 changes: 0 additions & 4 deletions rusk-abi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar};
use dusk_pki::PublicSpendKey;

use bytecheck::CheckBytes;
use dusk_bytes::Serializable;
use rkyv::{Archive, Deserialize, Serialize};

pub(crate) enum Query {}
Expand Down Expand Up @@ -93,6 +92,3 @@ where
t.clone().into()
}
}

/// Raw form of an owner type
pub type OwnerRaw = [u8; PublicSpendKey::SIZE];
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; PublicSpendKey::SIZE] {
rusk_abi::self_owner()
rusk_abi::self_owner_raw()
}
}

Expand Down

0 comments on commit bbb1354

Please sign in to comment.