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

domain

CREATE

Enforces DNS compatibility, validates provided hashes, and restricts top-level domain (TLD) registration (protocol version 14 and earlier only)

DPNS

domain

CREATE

Restricts top-level domain (TLD) registration and enforces the parent domain’s subdomain rules (protocol version 15+)

—-

—-

—-

—-

DPNS

domain

REPLACE

Prevents updates to existing documents

DPNS

domain

DELETE

Prevents deletion of existing documents (protocol version 14 and earlier only)

DPNS

domain

DELETE

Prevents deletion of contested names (protocol version 15+)

DPNS

domain

TRANSFER

Prevents transfer of existing documents (protocol version 12 and earlier only)

DPNS

domain

PURCHASE

Prevents purchase of existing documents (protocol version 12 and earlier only)

DPNS

domain

UPDATE_PRICE

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

domain

CREATE

Full domain length <= 253 characters (protocol version 14 and earlier only)

domain

CREATE

normalizedLabel matches homograph-safe conversion of label (lowercase with character substitutions: o→0, l/i→1) (protocol version 14 and earlier only)

domain

CREATE

normalizedParentDomainName matches homograph-safe conversion of parentDomainName (protocol version 14 and earlier only)

domain

CREATE

ownerId validation against records identity fields is a no-op (see note below) (protocol version 14 and earlier only)

domain

CREATE

Only creating a top-level domain with an authorized identity

domain

CREATE

Referenced normalizedParentDomainName must be an existing parent domain

domain

CREATE

Subdomain registration for non-top-level domains prevented if the new domain’s subdomainRules.allowSubdomains is true

domain

CREATE

Subdomain registration only allowed by the parent domain owner if the parent domain’s subdomainRules.allowSubdomains is false

domain

CREATE

Referenced preorder document must exist (protocol version 14 and earlier only)

domain

REPLACE

Action not allowed

domain

DELETE

Action not allowed (protocol version 14 and earlier only)

domain

DELETE

Contested names can’t be deleted; they can only be tombstoned (protocol version 15+)

domain

TRANSFER

Action not allowed (protocol version 12 and earlier only)

domain

PURCHASE

Action not allowed (protocol version 12 and earlier only)

domain

UPDATE_PRICE

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

contactRequest

CREATE

Validates contact request fields and permissions (protocol version 14 and earlier only)

profile

CREATE

Rejects corePaymentAddress or platformPaymentAddress values whose first byte is not 0x00 (P2PKH) or 0x01 (P2SH) (protocol version 14 only)

profile

REPLACE

Same payment address type byte check as CREATE (protocol version 14 only)

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

rewardShare

CREATE

Rejected unconditionally (masternodes manage reward shares via internal platform operations)

rewardShare

REPLACE

Rejected unconditionally (masternodes manage reward shares via internal platform operations)

rewardShare

DELETE

Rejected unconditionally (masternodes manage reward shares via internal platform operations)

Withdrawals

Document

Action

Trigger Description

withdrawal

REPLACE

Rejected by data trigger (withdrawal documents cannot be updated)

withdrawal

DELETE

Rejected unless status is COMPLETE or, from protocol version 14, FAILED (an expired withdrawal whose amount is below Core’s dust threshold)