Using the popCapsule Oracle
popCapsule
is used for passing artbitrary data. We have not yet included this in Aztec.nr, so it is a bit more complex than the other oracles. You can follow this how-to:
1. Define the pop_capsule function
In a new file on the same level as your main.nr
, implement an unconstrained function that calls the pop_capsule oracle:
pop_capsule
#[oracle(popCapsule)]
unconstrained fn pop_capsule_oracle<N>() -> [Field; N] {}
// A capsule is a "blob" of data that is passed to the contract through an oracle.
unconstrained pub fn pop_capsule<N>() -> [Field; N] {
pop_capsule_oracle()
}
Source code: noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/capsule.nr#L3-L11
2. Import this into your smart contract
If it lies in the same directory as your smart contract, you can import it like this:
import_pop_capsule
use crate::capsule::pop_capsule;
Source code: noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/main.nr#L21-L23
3. Use it as any other oracle
Now it becomes a regular oracle you can call like this:
pop_capsule
let packed_public_bytecode: [Field; MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS] = pop_capsule();
Source code: noir-projects/noir-contracts/contracts/contract_class_registerer_contract/src/main.nr#L30-L32