diff --git a/pallets/fulfillment-receiver/README.md b/pallets/fulfillment-receiver/README.md index 97f2453a..042c2598 100644 --- a/pallets/fulfillment-receiver/README.md +++ b/pallets/fulfillment-receiver/README.md @@ -287,3 +287,87 @@ mod receiver { } } ``` + +## WASM Smart Contract direct integration + +It is also possible to directly fulfill to a WASM smart contract without goign through a pallet first. For example, given the following smart contract: + +```rust +#![cfg_attr(not(feature = "std"), no_std)] + +use ink; + +#[ink::contract] +mod receiver { + + use ink::{ + env::{caller, DefaultEnvironment}, + storage::Mapping, + }; + + #[ink(storage)] + pub struct Receiver { + allowed_processors: Mapping, + price: u128, + } + + impl Receiver { + + #[ink(constructor)] + pub fn default() -> Self { + Self { + allowed_processors: Default::default(), + price: Default::default(), + } + } + + #[ink(message)] + pub fn fulfill(&mut self, price: u128) { + let caller = caller::(); + if self.allowed_processors.contains(&caller) { + self.price = price; + } + } + + #[ink(message)] + pub fn get_price(&self) -> u128 { + self.price + } + + #[ink(message)] + pub fn add_processor(&mut self, processor: AccountId) { + self.allowed_processors.insert(processor, &()); + } + + #[ink(message)] + pub fn remove_processor(&mut self, processor: AccountId) { + self.allowed_processors.remove(&processor); + } + } +} +``` + +It is possible to directly call the fulfill method directly from the processors. The example script below shows how to call the above smart contract deployed on the Shibuya parachain: + +```javascript +const callIndex = '0x4606'; // the call index for the "call" extrinsic of pallet-contracts +const payload = _STD_.chains.substrate.codec.encodeUnsignedNumber(2, 128); // encoding the price value (2) as an u128 +const destination = "XTj3CLB3G6WnwPMgYo1PM2xi9BkDegtGw5WPd7X36G515La"; // the smart contract address +_STD_.chains.substrate.signer.setSigner("SECP256K1"); // select which curve to use for the signature +_STD_.chains.substrate.contract.fulfill( + "https://shibuya-rpc.dwellir.com", // the parachain rpc endpoint + callIndex, + destination, + payload, + { + refTime: "3951114240", + proofSize: "629760", + }, + (opHash) => { + print("Succeeded: " + opHash) + }, + (err) => { + print("Failed: " + err) + }, +) +```