@dashevo/wasm-dpp2 4.2.0-beta.4 → 4.2.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -0
- package/dist/dpp.compressed.js +1 -1
- package/dist/dpp.d.ts +2354 -1913
- package/dist/dpp.js +1 -1
- package/dist/raw/wasm_dpp2.d.ts +2354 -1913
- package/dist/raw/wasm_dpp2.js +233 -21
- package/dist/raw/wasm_dpp2.no_url.js +233 -21
- package/dist/raw/wasm_dpp2_bg.wasm +0 -0
- package/dist/raw/wasm_dpp2_bg.wasm.d.ts +1833 -1825
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,3 +46,45 @@ carried before it is passed to `DocumentCreateTransition` is replaced: the
|
|
|
46
46
|
transition can only carry the id consensus recomputes. For the same reason
|
|
47
47
|
`new Document({...})` refuses an explicit `id` that disagrees with the one its
|
|
48
48
|
`identityContractNonce` derives. No app needs to reimplement the hash.
|
|
49
|
+
|
|
50
|
+
## Checking a contract update
|
|
51
|
+
|
|
52
|
+
A data contract update is refused when it breaks an update rule: the version
|
|
53
|
+
must rise by exactly one, the indexes of an existing document type are fixed,
|
|
54
|
+
a property may be added but not removed, a new required property needs
|
|
55
|
+
`requiredSince`, and so on for every keyword (see the book, *Contract
|
|
56
|
+
Keywords*, the *On update* row of each keyword). `DataContract.validateUpdate`
|
|
57
|
+
runs those rules with the code consensus runs on the update transition
|
|
58
|
+
(`DataContract::validate_update`), so an app, a CI job or a review tool can
|
|
59
|
+
check a proposed contract before paying for a transition the platform would
|
|
60
|
+
refuse:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const version = new PlatformVersion(14);
|
|
64
|
+
const current = DataContract.fromJSON(currentJson, true, version);
|
|
65
|
+
const proposed = DataContract.fromJSON(proposedJson, true, version);
|
|
66
|
+
|
|
67
|
+
const errors = current.validateUpdate(proposed, undefined, version);
|
|
68
|
+
// [] when the update is valid; otherwise ConsensusError objects, e.g.
|
|
69
|
+
// errors[0].code === 10217 when an index of an existing type changed
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Each error is a `ConsensusError` with the `code` a refused transition reaches
|
|
73
|
+
JS with. The second argument is the `BlockInfo` of the block the update would
|
|
74
|
+
be executed in, of which only the time is read (an added token's
|
|
75
|
+
pre-programmed distributions may not start before it); `undefined` uses the
|
|
76
|
+
device clock. The two contracts are compared whatever their ids, as the
|
|
77
|
+
platform compares the stored contract with the proposed one. Build the
|
|
78
|
+
proposed contract with full validation, as above, since the transition's
|
|
79
|
+
structural checks run there. No state is read, so what the platform checks
|
|
80
|
+
against state on top is not covered: that the contract exists, that group
|
|
81
|
+
members, identities named by token configurations and appointed moderators
|
|
82
|
+
exist, that references into other contracts resolve, and the signature, nonce
|
|
83
|
+
and fees.
|
|
84
|
+
|
|
85
|
+
This package is built with the crate's `validation` feature, which the method
|
|
86
|
+
needs. It also makes full validation (`fromJSON(…, true, …)`, `fromObject`,
|
|
87
|
+
`fromBytes`, `new DataContract({ fullValidation: true })`) run the document
|
|
88
|
+
meta-schema, and contract parse errors come back as consensus errors with
|
|
89
|
+
codes. `@dashevo/wasm-sdk` and `@dashevo/evo-sdk` build these bindings without
|
|
90
|
+
it, to keep their size, so they have no `validateUpdate`.
|