Data Trigger#
Data Trigger Overview#
Although data contracts provide much needed constraints on the structure of the data being stored on Dash Platform, there are limits to what they can do. Certain system data contracts may require server-side validation logic to operate effectively. For example, DPNS must enforce some rules to ensure names remain DNS compatible. Dash Platform Protocol (DPP) supports this application-specific custom logic using Data Triggers.
Details#
Since all application data is submitted in the form of documents, data triggers are defined in the context of documents. To provide even more granularity, they also incorporate the document transition action so separate triggers can be created for any document transition action (for example, CREATE, REPLACE, DELETE, TRANSFER, PURCHASE, or UPDATE_PRICE).
When document state transitions are received, DPP checks if there is a trigger associated with the document transition type and action. If there is, it then executes the trigger logic.
Note: Successful execution of the trigger logic is necessary for the document to be accepted and applied to the platform state.
Example#
As an example, DPP contains several data triggers for DPNS as defined in the data trigger bindings (protocol version 15 bindings). The domain document has added constraints for creation, replacement or deletion:
Data Contract |
Document |
Action(s) |
Trigger Description |
|---|---|---|---|
DPNS |
|
Enforces DNS compatibility, validates provided hashes, and restricts top-level domain (TLD) registration (protocol version 14 and earlier only) |
|
DPNS |
|
Restricts top-level domain (TLD) registration and enforces the parent domain’s subdomain rules (protocol version 15+) |
|
—- |
—- |
—- |
—- |
DPNS |
|
Prevents updates to existing documents |
|
DPNS |
|
Prevents deletion of existing documents (protocol version 14 and earlier only) |
|
DPNS |
|
Prevents deletion of contested names (protocol version 15+) |
|
DPNS |
|
Prevents transfer of existing documents (protocol version 12 and earlier only) |
|
DPNS |
|
Prevents purchase of existing documents (protocol version 12 and earlier only) |
|
DPNS |
|
Prevents updating price of existing documents (protocol version 12 and earlier only) |
Starting in protocol version 13, the TRANSFER, PURCHASE and UPDATE_PRICE actions have no DPNS trigger binding. They are validated by the generic document validation paths, which permit them because the DPNS data contract declares transferable: 1 and tradeMode: 1. REPLACE remains rejected, and DELETE remains rejected through protocol version 14.
Starting in protocol version 15, DPNS uses its v3 data contract and the domain CREATE trigger keeps only the checks on the domain’s place in the name hierarchy. The DPNS v3 schema checks the rest of a create with document type keywords: it generates the normalized names from their counterparts (generatedFrom), requires and consumes the creator’s own preorder (creatorRefersTo), and holds records.identity to the owner of a new name (propertyConstraints). A name’s owner may delete the domain document, which frees the name to be registered again under the usual hierarchy and preorder rules, unless the name is contested. A contested name can only be tombstoned. REPLACE is still refused, by the contract’s documentsMutable: false before any trigger runs.
DPNS Trigger Constraints
The following table details the DPNS constraints applied via data triggers. These constraints are in addition to the ones applied directly by the DPNS data contract.
Document |
Action |
Constraint |
|---|---|---|
|
|
Full domain length <= 253 characters (protocol version 14 and earlier only) |
|
|
|
|
|
|
|
|
|
|
|
Only creating a top-level domain with an authorized identity |
|
|
Referenced |
|
|
Subdomain registration for non-top-level domains prevented if the new domain’s |
|
|
Subdomain registration only allowed by the parent domain owner if the parent domain’s |
|
|
Referenced |
|
|
Action not allowed |
|
|
Action not allowed (protocol version 14 and earlier only) |
|
|
Contested names can’t be deleted; they can only be tombstoned (protocol version 15+) |
|
|
Action not allowed (protocol version 12 and earlier only) |
|
|
Action not allowed (protocol version 12 and earlier only) |
|
|
Action not allowed (protocol version 12 and earlier only) |
Note
The trigger for domain CREATE attempts to validate that ownerId matches
records.dashUniqueIdentityId or records.dashAliasIdentityId. However, the
DPNS v1 schema defines only records.identity and sets additionalProperties: false, so neither field can exist in a valid document. Both checks are
therefore permanent no-ops and records.identity is not validated against
ownerId at the trigger level. Starting in protocol version 15, the DPNS v3
schema holds a new name’s records.identity to its owner with a
propertyConstraints rule instead.
Note
Starting in protocol version 13, when a DPNS domain document is transferred or purchased platform rewrites the document’s records.identity to the new owner’s identity ID as part of applying the transition. Name resolution and records.identity queries therefore follow the ownership change. This rewrite is applied outside the data trigger system and is scoped to the DPNS domain document type.
Other System Contract Triggers#
In addition to DPNS, the following system contracts have registered data triggers:
Dashpay
Document |
Action |
Trigger Description |
|---|---|---|
|
|
Validates contact request fields and permissions (protocol version 14 and earlier only) |
|
|
Rejects |
|
|
Same payment address type byte check as |
Starting in protocol version 15, DashPay has no data triggers. The DashPay v3 data contract declares the same checks with document type keywords: a contact request’s toUserId must refer to an identity (refersTo) other than the sender (distinctFrom), and profile rules (propertyConstraints) hold each payment address’s type byte to 0x00 or 0x01.
Masternode Rewards
Document |
Action |
Trigger Description |
|---|---|---|
|
|
Rejected unconditionally (masternodes manage reward shares via internal platform operations) |
|
|
Rejected unconditionally (masternodes manage reward shares via internal platform operations) |
|
|
Rejected unconditionally (masternodes manage reward shares via internal platform operations) |
Withdrawals
Document |
Action |
Trigger Description |
|---|---|---|
|
|
Rejected by data trigger (withdrawal documents cannot be updated) |
|
|
Rejected unless status is |