The normal layout
The SDK writes one text for a document, whatever layout its author typed. Two documents are the same document when their normal texts are equal. Comments, blank lines, indent width, quote style, flow style, and the key order inside a rule make no difference to the normal text. The engine also reads a rule by its parsed content, not by its bytes. The commitment covers the exact bytes that you commit. Normalize a document before you stage it, so the text that you show, compare, store and commit is one text. The normal layout:- prints maps in block style, and lists of scalars in flow style (
[mon, tue]); - prints the keys inside a rule in this order:
type,trigger,actions,account,to,value,recipients,in,out,channel,message,timestamps,day_of_week,day_of_month,time_of_day,timezone,start,expiry, then any other key in document order; - keeps the top-level keys, and the keys outside rules, in document order;
- prints a string plain when it is an identifier that the engine reads as a string, and in double quotes in all other cases;
- prints a number from its source text, a null as
null, and a boolean astrueorfalse; - has no comments.
normalizeDocument
reason is a sentence for the author. The function never throws for a bad document.
It refuses:
- YAML with any parser error or warning: a duplicate key, a tab in an indent, an unknown tag, two documents in one text;
- a raw U+000D with no U+000A after it, and a raw U+0085, U+2028 or U+2029, anywhere;
- a raw U+FEFF anywhere except as the first character;
- a
%YAMLversion other than 1.2, and a%TAGdirective; - an anchor or an alias;
- any tag except
!!str; - a double-quoted value that escapes a line break;
- a
|or>block value with no-in its header and no line break after its last line; - a
|or>block value with an indent digit in its header; - a top level that is not a map, and a
rulesvalue that is not a map; - a rule name that is not a string or a 64-bit integer, and two rules with one name.
printRuleDocument
global: map before rules:. Every builder of rule builders prints through it.
PlainScalarKind
normalTextWithGlobalMap
value under global.<key>. A null value removes the key, and removes global: when it becomes empty. A document with no global: gets one as its first key. It throws an Error with the refusal reason for a text with no normal layout, and for a global that is not a map.
Split and assemble
A document can hold many rules. The functions below let an editor own one rule at a time and still commit one document. The non-rule parts of the document survive: the preamble (the top-level keys aboverules, such as global:) and the trailer (the top-level keys after it).
splitDocument
null for a text that normalizeDocument refuses. For a document with no rules key, rules is empty and hasRulesKey is false.
assembleDocument
splitDocument: the preamble, then rules: and the rule bodies, then the trailer. With no rules and hasRulesKey: true, it prints rules: {}, a valid document with nothing to run. With nothing at all, it prints {}.
Single-rule helpers
Fee token
readFeesMethod
global.fees_method when it is exactly { type: fixed_token, token: <RoutingToken> }. Returns null for no fee method, any other shape, an unknown token, and text with no normal layout.
documentWithFeesMethod
global.fees_method set to method, or removed for null. It throws for text with no normal layout.
What a document names
documentActionTokens
value of each send_one, the value of each send_batch row, and the in of each exchange:
- A literal
"AMOUNT TOKEN"namesTOKEN. "trigger.value"and"trigger.value * N%"name the token at the end of thevaluerange of theincoming_txoroutgoing_txtrigger of the rule.- Any other value names no token, and the answer is
unnamedwith the rule and the action kind.
spentTokens holds each token one time, in first-seen order. feeToken is the token of global.fees_method, or null. The ERC20Allow leg computes tokens(D) from this answer (see ERC20Allow).
For the Builder example of rule builders:
anyTx condition and a percent payee, the trigger has no range, so the share names no token:
documentDestinations
to key inside the actions of each rule: the to of a send_one and of each send_batch row. The bank details of an off_ramp are a map, not an address, and are not listed. The to filter of an outgoing_tx trigger is not listed: it pays nothing. A to: inside a string is text and is not listed. A number is listed as its decimal text. Returns null for text with no normal layout. Use it to check every payee before the owner signs.
documentTransferFilterAddresses
account and from of an incoming_tx, and the account and to of an outgoing_tx. Returns null for text with no normal layout.
documentHasOffRampAction
true when any rule has an off_ramp action. false for text with no normal layout.
documentNotificationEmail and documentWithNotificationEmail
documentNotificationEmail returns global.notification_email as the document spells it, or null.
documentWithNotificationEmail returns the normal text with global.notification_email set. canonicalEmail must already be canonical (canonicalNotificationEmail), else it throws Error("notification email must already be canonical"). A document whose email has the same canonical form keeps its own spelling. It throws an Error with the refusal reason for text with no normal layout.
notification_email is not the verified inbox of the account. See notification email.
Commitment
dslCommitment
salt must be exactly 0x and 64 hex characters, else it throws. AnafiDslRegistry.commitments(aa).hash holds this value after a commit. The stage and the commit methods check the engine echo against it.
dslUploadPayload, dslStagePayload) is on low-level helpers.