Repository navigation
feat: add the dash-sdk-contract declaration model, grammar and diagnostics #4719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
8445e18
feat: add the dash-sdk-contract declaration model, grammar and diagno…
DCG-Claude cf98654
build: wire dash-sdk-contract into CI and document the author API
DCG-Claude fd0071a
refactor: merge declarations through an identified-spec trait
DCG-Claude 182a2f8
fix: make declaration merging order independent and bound interface w…
DCG-Claude 6ecf308
fix: keep aggregate options explicit and canonicalize order-insensiti…
DCG-Claude 6ef0251
build: refresh the lock after rebasing onto v4.3-dev and satisfy clip…
DCG-Claude fb37fac
feat: declare required system properties and sharpen wire and ranked …
DCG-Claude 1b0040d
feat: carry the time-range ttl and canonicalize enum values
DCG-Claude 7a79e56
build: refresh the lock for the 4.2.0-beta.3 workspace version
DCG-Claude 6565750
feat: declare no-locking contests, composite terminals and count unde…
DCG-Claude 909aa5e
build: refresh the lock for the 4.2.0-beta.4 workspace version
DCG-Claude 26d83fe
feat: flat index-only indexes, entry payloads and the native property…
DCG-Claude 69cfdd0
feat: implicit owner terminal, range-count countability, optional tok…
DCG-Claude 5ace03a
build: refresh the lock for the 5.0.1 workspace version
DCG-Claude e5c3a9d
fix: natively valid score sketch, entry payload in the index-only dia…
DCG-Claude 4d4779b
feat: integer ranges, skip sets on any index, level rankings for sums…
DCG-Claude afdf0d3
feat: deletion only when consumed, a type-level time to live and the …
DCG-Claude 0eaaacb
test: align the score fixture with the natively valid sketch
DCG-Claude ae85f57
docs: typed-array indexes outside the model and the native prefix ran…
DCG-Claude cd5e9da
fix: report the own faults of declarations set aside by deduplication
DCG-Claude c2da2c0
fix: refuse a disabled interface requested by any collection declaration
DCG-Claude fc0820e
fix: check a repeated attribute option's value as well as reporting t…
DCG-Claude 455f48d
fix: report every malformed entry of an attribute map
DCG-Claude 05821ad
fix: every invalid list choice, one check per equivalence class, and …
DCG-Claude 183dea8
docs: the count promotions as a mirrored exception and codes assigned…
DCG-Claude 34b0698
fix: check module imports as a set and align the rustdoc with count n…
DCG-Claude 2fdadc4
fix: leave the bucket source position to DPP and list the private doc…
DCG-Claude 20176e9
fix: leave system-property terminal eligibility to DPP
DCG-Claude a8b839b
test: fail the book table test on an unreadable chapter inside the re…
DCG-Claude 407d980
fix: leave index-only layout compatibility to DPP
DCG-Claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [package] | ||
| name = "dash-sdk-contract" | ||
| version.workspace = true | ||
| edition = "2021" | ||
| rust-version.workspace = true | ||
| authors = ["Dash Core Team"] | ||
| license = "MIT" | ||
| description = "Contract-author SDK for DashVM: declaration model, attribute grammar, diagnostics and canonical manifest" | ||
|
|
||
| [dependencies] | ||
| thiserror = { version = "2.0.17", default-features = false } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = ["thiserror/std"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # dash-sdk-contract | ||
|
|
||
| Contract-author SDK for DashVM: the declaration model behind `#[persistent]`, | ||
| `#[index]`, `#[rule]` and `#[entry]`, the attribute grammar those macros | ||
| implement, the diagnostics they report, and the canonical manifest a contract | ||
| package publishes. | ||
|
|
||
| ```rust | ||
| use dash_sdk_contract::prelude::*; | ||
| ``` | ||
|
|
||
| This crate specifies the author-facing model. It carries no proc macros, no | ||
| host context and no runtime. It compiles without `std` on `wasm32v1-none`: | ||
|
|
||
| ```bash | ||
| cargo check -p dash-sdk-contract --no-default-features --target wasm32v1-none | ||
| cargo test -p dash-sdk-contract | ||
| cargo test -p dash-sdk-contract --no-default-features | ||
| ``` | ||
|
|
||
| The chapter [Contract Declarations and the Author API](../../book/src/dashvm/contract-declarations.md) | ||
| in the Dash Platform Book describes the grammar, the identity rules, the | ||
| persistence semantics and what the validator checks versus what native | ||
| validation enforces. |
136 changes: 136 additions & 0 deletions
136
packages/rs-dash-sdk-contract/src/declare/capability.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| //! The capability catalogue: what a contract may require, and whether the | ||
| //! native host supports it today. | ||
|
|
||
| use core::fmt; | ||
|
|
||
| use super::collections::TypedCollectionKind; | ||
|
|
||
| /// Support status of a capability in the native host. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub enum CapabilityStatus { | ||
| /// Supported by the native host today; a manifest requesting it can be | ||
| /// deployed. | ||
| Native, | ||
| /// Specified, declarable, but without a native implementation yet. The | ||
| /// validator accepts the declaration; the build crate reports it as a | ||
| /// native gap and refuses to call the manifest deployable. | ||
| PendingNative, | ||
| /// Catalogued but disabled: the declaration is rejected until the | ||
| /// capability's semantics are specified. Today only the private document | ||
| /// store, whose encryption, key control, query visibility and proof | ||
| /// behaviour are not yet specified. | ||
| InterfaceDisabled, | ||
| } | ||
|
|
||
| /// A capability a contract requires, either explicitly (`requires = [...]`) | ||
| /// or derived from its declarations. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub enum CapabilityRequirement { | ||
| /// The native access-control primitive. Explicit. | ||
| Acl, | ||
| /// The native randomness primitive. Explicit. | ||
| Randomness, | ||
| /// `write = "contract"`: only the contract's own code may create | ||
| /// documents. Derived. | ||
| ContractWrites, | ||
| /// A rule with a native guard expression. Derived. | ||
| NativeGuards, | ||
| /// A rule with a read-only WASM predicate. Derived. | ||
| WasmPredicates, | ||
| /// A typed specialized collection of the given kind. Derived. | ||
| TypedCollections(TypedCollectionKind), | ||
| /// `store = "private"`. Derived. | ||
| PrivateStore, | ||
| /// Stored receipts (the default policy). Derived. | ||
| StoredReceipts, | ||
| /// At least one entry, which needs the DashVM runtime. Derived. | ||
| Entries, | ||
| /// More than one module, which needs bundle linking. Derived. | ||
| Modules, | ||
| } | ||
|
|
||
| impl CapabilityRequirement { | ||
| /// Whether the author writes this requirement (as opposed to the validator | ||
| /// deriving it). | ||
| pub fn is_explicit(&self) -> bool { | ||
| matches!( | ||
| self, | ||
| CapabilityRequirement::Acl | CapabilityRequirement::Randomness | ||
| ) | ||
| } | ||
|
|
||
| /// The catalogue status of the requirement. | ||
| pub fn status(&self) -> CapabilityStatus { | ||
| match self { | ||
| CapabilityRequirement::PrivateStore => CapabilityStatus::InterfaceDisabled, | ||
| CapabilityRequirement::Acl | ||
| | CapabilityRequirement::Randomness | ||
| | CapabilityRequirement::ContractWrites | ||
| | CapabilityRequirement::NativeGuards | ||
| | CapabilityRequirement::WasmPredicates | ||
| | CapabilityRequirement::TypedCollections(_) | ||
| | CapabilityRequirement::StoredReceipts | ||
| | CapabilityRequirement::Entries | ||
| | CapabilityRequirement::Modules => CapabilityStatus::PendingNative, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for CapabilityRequirement { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| match self { | ||
| CapabilityRequirement::Acl => f.write_str("acl"), | ||
| CapabilityRequirement::Randomness => f.write_str("randomness"), | ||
| CapabilityRequirement::ContractWrites => f.write_str("contract writes"), | ||
| CapabilityRequirement::NativeGuards => f.write_str("native guards"), | ||
| CapabilityRequirement::WasmPredicates => f.write_str("wasm predicates"), | ||
| CapabilityRequirement::TypedCollections(kind) => { | ||
| write!(f, "typed collections ({kind})") | ||
| } | ||
| CapabilityRequirement::PrivateStore => f.write_str("private store"), | ||
| CapabilityRequirement::StoredReceipts => f.write_str("stored receipts"), | ||
| CapabilityRequirement::Entries => f.write_str("entries"), | ||
| CapabilityRequirement::Modules => f.write_str("modules"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Whether the host stores a receipt for every outer invocation. | ||
| #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub enum ReceiptPolicy { | ||
| /// One bounded receipt per outer invocation, the default. | ||
| #[default] | ||
| Stored, | ||
| /// No receipts. | ||
| Disabled, | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn should_keep_the_private_store_catalogued_but_disabled() { | ||
| assert_eq!( | ||
| CapabilityRequirement::PrivateStore.status(), | ||
| CapabilityStatus::InterfaceDisabled | ||
| ); | ||
| assert!(!CapabilityRequirement::PrivateStore.is_explicit()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn should_mark_acl_and_randomness_explicit_and_pending() { | ||
| for capability in [ | ||
| CapabilityRequirement::Acl, | ||
| CapabilityRequirement::Randomness, | ||
| ] { | ||
| assert!(capability.is_explicit()); | ||
| assert_eq!(capability.status(), CapabilityStatus::PendingNative); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn should_default_receipts_to_stored() { | ||
| assert_eq!(ReceiptPolicy::default(), ReceiptPolicy::Stored); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.