Demos Network Specifications
  • Introduction
    • What is Demos Network
    • Demos Network Architecture
  • FAQ
  • Cookbook
    • Project setup
      • Run the project (MacOS)
      • Run the project (Windows)
        • WSL 2 Setup on Windows (10 and 11 only)
        • Issue Troubleshooting
      • Run the project (Ubuntu)
  • SDK
    • Getting Started
    • WebSDK
      • Authentication
        • FIDO2 Passkeys
          • Under the Hood: FIDO2 Passkeys
      • NodeCalls
      • Transactions
        • Creating a transaction
        • Signing a transaction
        • Broadcasting a transaction
      • L2PS SDK
        • The l2ps module
        • Interacting with the L2PS
        • L2PS Messaging System
      • Instant Messaging
        • What is the Instant Messaging Protocol?
        • Architecture Overview
        • Encryption
        • Quickstart
        • Message Types
        • API Reference
        • FAQ
    • Cross Chain
      • General layout of the XM SDKs
      • EVM
      • BTC
      • Solana
      • MultiversX (EGLD)
      • NEAR
      • IBC
      • TON
      • XRPL
      • The XMScript
      • Identities
    • Demoswork
    • Cookbook
      • Demoswork
        • Creating work steps
        • Conditional Operation
        • Base Operation
        • Signing and broadcasting
      • Transactions
        • Crosschain Transaction
        • Native Transactions
      • SWAP
        • Crosschain SWAP
    • Web2
      • Quick Start
      • DAHR API Reference
        • Types
      • Making Requests
      • Identities
        • Twitter
        • GitHub
    • API Reference
    • Bridges
      • Rubic Bridge Test
    • Post Quantum Cryptography
  • Backend
    • Internal Mechanisms
      • Network Time Synchronization
      • Cross Context Identities
    • Global Change Registry
      • GCR Structure
      • How is GCR Synced?
    • Consensus Mechanism
      • Unparalleled Scalability
      • Decentralization in PoR-BFT
      • Enhanced Security
      • Comparative Advantage
      • Addressing Potential Criticisms
      • Conclusion
    • Communications Stack
    • L2PS (Subnet) Framework
      • How are L2PS transactions handled?
    • Miscellaneous
      • Browsing the Postgres DB via psql
    • Bridges
      • Rubic Bridge
    • Developers Testbed
      • Setting up the environment
      • Setting up the repository
      • Installing dependencies
      • Node Configuration
      • Running the node
  • Frontend
    • Demos Providers Discovery Mechanism
Powered by GitBook
On this page
  • Work steps
  • Operations
  • Conditional Operation
  • Base Operation
  • The Operation Order
  1. SDK

Demoswork

PreviousIdentitiesNextCookbook

Last updated 5 months ago

DemosWork is a module that helps you create a script (DemosScript) that can be executed on the omniweb.

A DemosScript is made up of these components:

  1. Work steps - A step is a single action that can be executed on the omniweb.

  2. Operations - An operation is a group of steps or a conditional.

  3. The operation order - This is an ordered list of operation UIDs. It dictates the order in which the operations in a script are supposed to be executed.

DemosWork is implemented as a class that looks like this:

@/demoswork/work.ts

class DemosWork {
    script: DemoScript = {
        steps: {},
        operations: {},
        operationOrder: new Set<string>(),
    }

    push(operation: DemosWorkOperation)
    toJSON()
}

The push method adds an operation to the DemoScript.

API Reference:

Work steps

A work step is a single action that can be executed on the omniweb. It can either be a web2, xm or a native transaction. Say for example, sending tokens on Ethereum or calling a web2 API.

A work step is implemented as follows:

class WorkStep {
    id: string = "step_" + UID
    context: "xm" | "web2" | "native"
    content: WorkStepInput // payload specific to the context
    output: {
        [key: string]: StepOutputKey
    }
    description: string
    timestamp: number = Date.now()
    
    critical: boolean
    depends_on: string[]
}

The critical property is used to stop the execution of the DemoScript if this step fails. The depends_on array is a list of work steps or operations that should be executed successfully before this step is executed.

The output of a workstep indicated above is not the result of executing the step. Since we don't have that value yet, the output is represented as objects that operations can use to refer to the future/actual output of the step.

The output of a workstep indicated above is not the result of executing the step. Since we don't have that value yet, the output is represented as objects that operations can use to refer to the future/actual output of the step.

When executing an operation that needs an output of a step, that step will be executed and its result parsed using the key specified to get the value.

Operations

An operation controls the execution of steps therefore enabling scripting on the omniweb. An operation can be a group of steps or a conditional.

An operation is implemented as follows:

abstract class DemosWorkOperation {
    id: string = "op_" + UID
    abstract type: string

    steps: Record<string, WorkStep> = {}
    operations: Set<DemosWorkOperation> = new Set()
    output: any // specific to the operation type
    
    operationScript: OperationScript
    critical: boolean
    depends_on: string[]

    addWork(work: WorkStep | DemosWorkOperation): void
}

The critical property is used to stop the execution of the DemoScript if a step fails. The depends_on array is a list of worksteps or operations that should be executed successfully before an operation is executed.

The operation class indexes the steps and operations it contains in the steps and operations fields. The operationScript field is specific to the operation type and is copied into the main script when the operation is added to the work instance.

The addWork method is used to add steps and operations to the operation (where applicable). If the work passed is an operation, its steps and operations are copied into the current operation.

Conditional Operation

A conditional operation now builds on top of that:

@/demoswork/operations/conditional/index.ts

class Condition {
    id: string
    action: WorkStep | DemosWorkOperation = null
    value_a: Condition | Operand = null
    value_b: Condition | Operand = null
    work: Map<string, WorkStep | DemosWorkOperation> = new Map()
}

class ConditionalOperation extends DemosWorkOperation {
    type = "conditional"
    override operationScript: ConditionalOperationScript = {
        id: this.id,
        operationType: "conditional",
        conditions: new Map(),
        order: [],
    }

    constructor(...conditions: Condition[]): void

    if(value_a, operator, value_b)
    then(step: WorkStep | DemosWorkOperation)
    else(step: WorkStep | DemosWorkOperation)
}

A conditional operation is created by passing in conditions to the constructor. The if, then and else methods are helpers that can be used to build a conditional operation by chaining them together.

Base Operation

The base operation groups steps and operations together without any additional logic.

The base operation is implemented as follows:

@/demoswork/operations/baseoperation.ts

class BaseOperation extends DemosWorkOperation {
    type = "base"
    operationScript: BaseOperationScript = {
        id: this.id,
        operationType: "base",
        order: [],
    }

    constructor(...work: Array<WorkStep | DemosWorkOperation>)
    override addWork(...work: Array<WorkStep | DemosWorkOperation>): void
}

Work can be added to the base operation by passing in the work to the constructor or using the addWork method.

The Operation Order

This is an ordered list of Operation UID strings. It dictates the order in which the operations in a script are supposed to be executed.

API Reference:

API Reference:

API Reference:

https://kynesyslabs.github.io/demosdk-api-ref/classes/demoswork.DemosWork.html
https://kynesyslabs.github.io/demosdk-api-ref/classes/demoswork.WorkStep.html
https://kynesyslabs.github.io/demosdk-api-ref/classes/demoswork.ConditionalOperation.html
https://kynesyslabs.github.io/demosdk-api-ref/classes/demoswork.BaseOperation.html