Substrate Integration
The Acurast Receiver Pallet allows a Substrate based chain to integrate the Acurast functionality to be able to securly receive real world data posted by the Acurast Processors.
Introduction
The Acurast Fullfilment Receiver Pallet, in combination with the Acurast P256 crypto package, allows a Parachain to accepts direct fulfillments from Acurast Processors.
The Pallet exposes one extrinsic.
fulfill
Allows to post the [Fulfillment] of a job. The fulfillment structure consists of:
- The ipfs url of the
script
executed. - The
payload
bytes representing the output of thescript
.
Parachain Integration
Implement pallet_acurast_fulfillment_receiver::Config
for your Runtime
and add the Pallet:
frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0,
AcurastFulfillmentReceiver: crate::{Pallet, Call, Event<T>}
}
);
impl pallet_acurast_fulfillment_receiver::Config for Runtime {
type Event = Event;
type OnFulfillment = FulfillmentHandler;
type WeightInfo = ();
}
pub struct FulfillmentHandler;
impl OnFulfillment<Runtime> for FulfillmentHandler {
fn on_fulfillment(
from: <Runtime as frame_system::Config>::AccountId,
_fulfillment: pallet_acurast_fulfillment_receiver::Fulfillment,
) -> sp_runtime::DispatchResultWithInfo<frame_support::weights::PostDispatchInfo> {
/// check if origin is a valid Acurast Processor AccountId
if !is_valid(&from) {
return Err(DispatchError::BadOrigin.into());
}
/// if valid, then fulfillment can be used
Ok(().into())
}
}
Provide and implementation of [OnFulfillment] to handle the received fulfillment. The implementation should check that the fulfillment is from a known Acurast Processor account id.
P256 crypto
This crate provides types that allow to add P256 (a.k.a secp256r1) signature verification support to substrate based chains.
Setup
Add the following dependency to your Cargo manifest:
[dependencies]
acurast-p256-crypto = { git = "https://github.com/Acurast/acurast-core.git" }
Integration
Use the acurast_p256_crypto::MultiSignature
as your parachain Signature
type:
use acurast_p256_crypto::MultiSignature;
pub type Signature = MultiSignature;
pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
...
impl frame_system::Config for Runtime {
type AccountId = AccountId;
...
}
Acurast Proxy Pallet
The Acurast Proxy Pallet is an additional feature and not needed to be implemented yet without the Acurast Marketplace being live on it's own Parachain.
The Pallet is meant to be integrated by other parachains to interact with the Acurast parachain and the marketplace.
Introduction
The Acurast Proxy pallet serves to call the extrinsics of the main pallet on the acurast parachain, from any other parachain. It uses the XCMP protocol and XCM format for transmitting and interpreting messages.
register
Allows the registration of a job. A registration consists of:
- An ipfs URL to a
script
(written in Javascript).- The script will be run in the Acurast Trusted Virtual Machine that uses a Trusted Execution Environment (TEE) on the Acurast Processors.
- An optional
allowedSources
list of allowed sources.- A list of
AccountId
s that are allowed tofulfill
the job. If no list is provided, all sources are accepted.
- A list of
- An
allowOnlyVerifiedSources
boolean indicating if only verified source can fulfill the job.- A verified source is one that has provided a valid key attestation.
- An
extra
structure that can be used to provide custom parameters.
Registrations are saved per AccountId
and script
, meaning that register
is called twice from the same AccountId
with the same script
value, the previous registration is overwritten.
deregister
Allows the de-registration of a job.
updateAllowedSources
Allows to update the list of allowed sources for a previously registered job.
fulfill
Allows to post the fulfillment of a registered job. The fulfillment structure consists of:
- The ipfs url of the
script
executed. - The
payload
bytes representing the output of thescript
.
In addition to the fulfillment
structure, fulfill
expects the AccountId
of the requester
of the job.
Setup
Add the following dependency to your Cargo manifest:
[dependencies]
acurast-proxy = { git = "https://github.com/Acurast/acurast-core", default-features = false, branch = "feat/proxy-pallet" }
Parachain Integration
To integrate the acurast proxy in a parachain, there is some runtime setup needed. First we need to add the pallet to the construct_runtime macro as following:
construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0,
...
AcurastProxy: acurast_proxy::{Pallet, Call, Event<T>} = 34,
}
);
Then we have to add some parameter types to be used in the pallet config. Specifically the pallet id of the marketplace pallet and the parachain id of acurast parachain. The parachain id is used to route correctly the xcm messages from cumulus to acurast. The pallet id is needed to properly encode the call that we want to execute into the xcm message.
parameter_types! {
pub const AcurastParachainId: u32 = 2000;
pub const AcurastPalletId: u8 = 41;
}
the parachain id should be found in the chainspec of acurast, and the pallet id in the definition inside the construct_runtime macro (e.g "ExamplePallet: pallet_example = 42" would mean the pallet id is 42)
Lastly we need to configure the pallet with the parameter types defined before, and some default values like Event and (). The XcmRouter is defined in xcm_config, and we are also using the default one, but whoever integrates this pallet should make sure that the router is able to send XCMP messages.
impl acurast_proxy::Config for Runtime {
type Event = Event;
type AcurastParachainId = AcurastParachainId;
type AcurastPalletId = AcurastPalletId;
type XcmSender = XcmRouter;
type RegistrationExtra = JobRequirements<AcurastAsset>;
}