MCPcopy Create free account
hub / github.com/dharmaprotocol/dharmaOS / determineConditionalActions

Method determineConditionalActions

src/encoder.js:531–561  ·  view source on GitHub ↗
(action)

Source from the content-addressed store, hash-verified

529 }
530
531 determineConditionalActions(action) {
532 if (!(typeof action === 'object' && 'if' in action)) {
533 throw new Error("Attempting to branch on a non-conditional action.");
534 }
535
536 const splitCondition = action.if.condition.split(" ");
537 const conditionalVariable = splitCondition[0];
538 const comparisonVariable = splitCondition[2];
539
540 let conditionTrue;
541
542 if (comparisonVariable === 'true') {
543 conditionTrue = !!this.variables[conditionalVariable];
544 } else if (comparisonVariable === 'false') {
545 conditionTrue = !this.variables[conditionalVariable];
546 } else {
547 const tokenToReplaceAddress = this.contracts[conditionalVariable].address;
548
549 conditionTrue = (
550 comparisonVariable === 'ETHER' &&
551 tokenToReplaceAddress === ETHER_ADDRESS
552 ) || (
553 tokenToReplaceAddress === (
554 this.contracts[comparisonVariable] &&
555 this.contracts[comparisonVariable].address
556 )
557 );
558 }
559
560 return action.if[conditionTrue ? 'then' : 'else'] || [];
561 }
562
563 flatten(actions) {
564 const flatActions = [];

Callers 1

flattenMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected