Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

Commit 1aa77d4

Browse files
Add input references to runtime and run_prcess_as_root (#279)
* Add input references to runtime and run_prcess_as_root * Fix benchmarking + weights * Update readme * Version bump * Remove todo * Update sqnc-lang to include references and sender root restriciton * Fix comment in example * Loosen requirements for PropToken comparisson to support comparing an input to an input * Add ability to version tokens and fns * Allow specifying version on process create * Add additional test * Update readme * Implement arguments output * Fursther documentation in lang * Fix output of token type and version
1 parent fb32621 commit 1aa77d4

40 files changed

Lines changed: 4860 additions & 1313 deletions

Cargo.lock

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resolver = "2"
44

55
[workspace.package]
66
edition = "2021"
7-
version = "12.5.1"
7+
version = "13.0.0"
88

99
[workspace.dependencies]
1010
##############################

README.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,19 @@ Tokens can be minted/burnt by calling the following extrinsic under `UtxoNFT`:
124124
pub fn run_process(
125125
origin: OriginFor<T>,
126126
process: ProcessId<T>,
127-
inputs: BoundedVec<T::TokenId, T::MaxInputCount>,
128-
outputs: BoundedVec<Output<T>, T::MaxOutputCount>
127+
inputs: BoundedVec<Input<T::TokenId>, T::MaxInputCount>,
128+
outputs: BoundedVec<Output<T>, T::MaxOutputCount>,
129+
) -> DispatchResultWithPostInfo { ... }
130+
```
131+
132+
For processes that must be run as the system privilege (root) there is also:
133+
134+
```rust
135+
pub fn run_process_as_root(
136+
origin: OriginFor<T>,
137+
process: ProcessId<T>,
138+
inputs: BoundedVec<Input<T::TokenId>, T::MaxInputCount>,
139+
outputs: BoundedVec<Output<T>, T::MaxOutputCount>,
129140
) -> DispatchResultWithPostInfo { ... }
130141
```
131142

@@ -156,6 +167,7 @@ Pallet for defining process restrictions. Intended for use with `pallet-utxo-nft
156167
pub fn create_process(
157168
origin: OriginFor<T>,
158169
id: T::ProcessIdentifier,
170+
version: T::ProcessVersion,
159171
program: BoundedVec<
160172
BooleanExpressionSymbol<
161173
T::RoleKey,
@@ -230,25 +242,20 @@ A complete truth table set of binary operators is available when writing a proce
230242

231243
The pallet defines various type of process restrictions that can be applied to a process. These include:
232244

233-
| Restriction | description |
234-
| :-------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
235-
| `None` | Default `Restriction` value that always succeeds |
236-
| `Fail` | `Restriction` value that always fails |
237-
| `Combined` | Requires two specified restrictions combined via a specified operator [`AND`, `OR`, `XOR`, `NAND`, `NOR`] returns `true` |
238-
| `SenderHasInputRole` | Requires that the process `sender` is assigned to a specified role on a specified (by index) input token |
239-
| `SenderHasOutputRole` | Requires that the process `sender` is assigned to a specified role on a specified (by index) output token |
240-
| `OutputHasRole` | Requires that a specified (by index) output token has a role |
241-
| `OutputHasMetadata` | Requires that a specified (by index) output token has a metadata item with a given key |
242-
| `InputHasRole` | Requires that a specified (by index) input token has a role |
243-
| `InputHasMetadata` | Requires that a specified (by index) input token has a metadata item with a given key |
244-
| `MatchInputOutputRole` | Requires that the account of a specified role on a specified (by index) output token matches the account of a specified role on a specified (by index) input token |
245-
| `MatchInputOutputMetadataValue` | Requires that the metadata value of a specified key on a specified (by index) output token matches the metadata value of a specified key on a specified (by index) input token |
246-
| `MatchInputIdOutputMetadataValue` | Requires that the metadata value of a specified key on a specified (by index) output token matches the id of a specified (by index) input token |
247-
| `FixedNumberOfInputs` | Requires that the number of inputs must be a specified integer |
248-
| `FixedNumberOfOutputs` | Requires that the number of outputs must be a specified integer |
249-
| `FixedInputMetadataValue` | Requires that a metadata item of a specified key must have a specified value, on a specified (by index) input token |
250-
| `FixedOutputMetadataValue` | Requires that a metadata item of a specified key must have a specified value, on a specified (by index) output token |
251-
| `FixedOutputMetadataValueType` | Requires that a metadata item of a specified key must have a value of a specified type, on a specified (by index) output token |
245+
| Restriction | description |
246+
| :-------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
247+
| `None` | Default `Restriction` value that always succeeds |
248+
| `Fail` | `Restriction` value that always fails |
249+
| `SenderIsRoot` | Specifies that the caller of the transaction must be the system (root) |
250+
| `SenderHasArgRole` | Requires that the process `sender` is assigned to a specified role on a specified (by index) input, reference or output token |
251+
| `ArgHasRole` | Requires that a specified (by index) input, reference or output token has a role |
252+
| `ArgHasMetadata` | Requires that a specified (by index) input, reference or output token has a metadata item with a given key |
253+
| `MatchArgsRole` | Requires that the account of a specified role on a specified (by index) input, reference or output token matches the account of a specified role on a specified (by index) input, reference or output token |
254+
| `MatchArgsMetadataValue` | Requires that the metadata value of a specified key on a specified (by index) input, reference or output token matches the metadata value of a specified key on a specified (by index) input, reference or output token |
255+
| `MatchArgIdToMetadataValue` | Requires that the metadata value of a specified key on a specified (by index) input, reference or output token matches the id of a specified (by index) input, reference or output token |
256+
| `FixedArgCount` | Requires that the number of input, reference or output tokens must be a specified integer |
257+
| `FixedArgMetadataValue` | Requires that a metadata item of a specified key must have a specified value, on a specified (by index) input, reference or output token |
258+
| `FixedArgMetadataValueType` | Requires that a metadata item of a specified key must have a value of a specified type, on a specified (by index) input, reference or output token |
252259

253260
### IPFSKey pallet
254261

pallets/organisation-data/src/migrations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub mod v1 {
88
use super::*;
99
use frame_support::pallet_prelude::*;
1010

11-
/// Migrate the symmetric-key pallet from V0 to V1.
11+
/// Migrate the org-data pallet from V0 to V1.
1212
pub struct MigrateToV1<T, I>(core::marker::PhantomData<(T, I)>);
1313

1414
impl<T: Config + pallet_membership::Config<I>, I: 'static> OnRuntimeUpgrade for MigrateToV1<T, I> {

pallets/process-validation/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ parity-scale-codec = { workspace = true, features = ["derive"] }
1717
frame-support = { workspace = true }
1818
frame-system = { workspace = true }
1919
frame-benchmarking = { workspace = true, optional = true }
20+
log = { workspace = true }
2021
sp-runtime = { workspace = true, features = ["serde"] }
2122
sp-io = { workspace = true }
2223
sp-std = { workspace = true }

pallets/process-validation/src/benchmarking.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ type ProcessFullyQualifiedId<T> =
2727
sqnc_pallet_traits::ProcessFullyQualifiedId<<T as Config>::ProcessIdentifier, <T as Config>::ProcessVersion>;
2828

2929
fn prepare_program<T: Config>(l: u32) -> BoundedVec<BooleanExpressionSymbol<T>, T::MaxProcessProgramLength> {
30-
let metadata_restriction = Restriction::MatchInputOutputMetadataValue {
31-
input_index: 0u32,
32-
input_metadata_key: Default::default(),
33-
output_index: 0u32,
34-
output_metadata_key: Default::default(),
30+
let metadata_restriction = Restriction::MatchArgsMetadataValue {
31+
left_arg_type: ArgType::Input,
32+
left_index: 0u32,
33+
left_metadata_key: Default::default(),
34+
right_arg_type: ArgType::Input,
35+
right_index: 0u32,
36+
right_metadata_key: Default::default(),
3537
};
3638

3739
let mut program = BoundedVec::<_, _>::with_bounded_capacity(T::MaxProcessProgramLength::get() as usize);
@@ -90,60 +92,45 @@ benchmarks! {
9092
validate_process {
9193
let r in 1 .. (1 + T::MaxProcessProgramLength::get() / 2);
9294

93-
let account_id: T::AccountId = account("owner", 0, 0);
95+
let origin: RawOrigin<T::AccountId> = RawOrigin::Signed(account("owner", 0, 0));
9496
let program = prepare_program::<T>(r);
9597
let process = create_process_fixture::<T>(&program);
9698

97-
let inputs = vec![ProcessIO::<T> {
98-
id: Default::default(),
99-
roles: BTreeMap::new(),
100-
metadata: BTreeMap::from_iter(vec![(Default::default(), Default::default())])
101-
}; 10];
102-
let outputs = vec![ProcessIO::<T> {
99+
let args = vec![ProcessIO::<T> {
103100
id: Default::default(),
104101
roles: BTreeMap::new(),
105102
metadata: BTreeMap::from_iter(vec![(Default::default(), Default::default())])
106103
}; 10];
107104
}: {
108-
let _ = ProcessValidation::<T>::validate_process(&process, &account_id, &inputs, &outputs);
105+
let _ = ProcessValidation::<T>::validate_process(&process, &origin, &args, &args, &args);
109106
}
110107

111108
validate_process_min {
112-
let account_id: T::AccountId = account("owner", 0, 0);
109+
let origin: RawOrigin<T::AccountId> = RawOrigin::Signed(account("owner", 0, 0));
113110
let program = prepare_program::<T>(1);
114111
let process = create_process_fixture::<T>(&program);
115112

116-
let inputs = vec![ProcessIO::<T> {
117-
id: Default::default(),
118-
roles: BTreeMap::new(),
119-
metadata: BTreeMap::from_iter(vec![(Default::default(), Default::default())])
120-
}; 10];
121-
let outputs = vec![ProcessIO::<T> {
113+
let args = vec![ProcessIO::<T> {
122114
id: Default::default(),
123115
roles: BTreeMap::new(),
124116
metadata: BTreeMap::from_iter(vec![(Default::default(), Default::default())])
125117
}; 10];
126118
}: {
127-
let _ = ProcessValidation::<T>::validate_process(&process, &account_id, &inputs, &outputs);
119+
let _ = ProcessValidation::<T>::validate_process(&process, &origin, &args, &args, &args);
128120
}
129121

130122
validate_process_max {
131-
let account_id: T::AccountId = account("owner", 0, 0);
123+
let origin: RawOrigin<T::AccountId> = RawOrigin::Signed(account("owner", 0, 0));
132124
let program = prepare_program::<T>(1 + T::MaxProcessProgramLength::get() / 2);
133125
let process = create_process_fixture::<T>(&program);
134126

135-
let inputs = vec![ProcessIO::<T> {
136-
id: Default::default(),
137-
roles: BTreeMap::new(),
138-
metadata: BTreeMap::from_iter(vec![(Default::default(), Default::default())])
139-
}; 10];
140-
let outputs = vec![ProcessIO::<T> {
127+
let args = vec![ProcessIO::<T> {
141128
id: Default::default(),
142129
roles: BTreeMap::new(),
143130
metadata: BTreeMap::from_iter(vec![(Default::default(), Default::default())])
144131
}; 10];
145132
}: {
146-
let _ = ProcessValidation::<T>::validate_process(&process, &account_id, &inputs, &outputs);
133+
let _ = ProcessValidation::<T>::validate_process(&process, &origin, &args, &args, &args);
147134
}
148135
}
149136

0 commit comments

Comments
 (0)