solui
  • Getting Started
  • Docs
  • Github
  • Twitter
  • Telegram

@solui/processor

Parser and processor for solUI:

  • Parses and validates UI specs with on-chain checking.
  • Renders UI specs with platform-agnostic render callbacks.
  • Executes UI specs with on-chain interaction.

Installation

npm install @solui/processor

Example usage

Execute a panel programmatically:

const Web3 = require('web3')
const { executePanel } = require('@solui/processor')

const spec = require('./contracts/ui.json')

const artifacts = {
  Token: require('./build/contracts/Token.json')
}

const web3 = new Web3('https://mainnet.infura.io?token=MYTOKEN')

const panelId - 'id-of-a-panel-in-the-group'

const inputs = {
  contractAddress: '0x.....',
  anotherInputValue: 'foo bar',
  ...
}

const outputs = await executePanel({
  spec,
  artifacts,
  web3,
  panelId,
  inputs,
})

console.log(outputs)

Read full documentation.

## License

Copyright 2019 solUI Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DEFAULT_CALLBACKS

Default dummy callbacks for processor.

Type: Object

startUi

Processing of the spec has started.

Returns Promise

endUi

Processing of the spec has ended.

Returns Promise

startGroup

Processing of a UI group has started.

Returns Promise

endGroup

Processing of a UI group has ended.

Returns Promise

startPanel

Processing of a panel has started.

Returns Promise

endPanel

Processing of a panel has ended.

Returns Promise

processInput

Process given user input field and get its current value.

Returns Promise

deployContract

Deploy a contract.

Returns Promise

callMethod

Call a contract method - eth_call.

Returns Promise

sendTransaction

Call a contract method via a transaction - eth_sendTransaction.

Returns Promise

RootContext

Extends Context

Processor context object.

Context objects are reponsible for propagating input values and previous execution outputs along the various stages of spec processing. They also collect errors which occur during processing for retrievel later on.

Parameters

  • id
  • $1 Object
    • $1.network (optional, default {})
    • $1.artifacts
    • $1.callbacks

process

Process a UI spec.

This is the core parser/processor function. Use this to parse a spec and operate on its components in any custom manner you desire.

Parameters

  • params Object Parameters.
    • params.spec Object The UI specification.
    • params.artifacts Object Contract artifacts.
    • params.network Network? Network connection. Makes on-chain validation possible.
  • callbacks Object Processor callbacks. (optional, default {})

Returns Promise<RootContext>

assertSpecValid

Validate a UI spec.

Parameters

  • params Object Parameters.
    • params.spec Object The UI specification.
    • params.artifacts Object Contract artifacts.
    • params.network Network? Network connection. Makes on-chain validation possible.

Returns Promise

getUsedContracts

Get names of contracts which are referenced in the given UI spec.

Parameters

  • params Object Parameters.
    • params.spec Object The UI specification.

Returns Array List of canonical contract names.

validatePanel

Validate panel inputs.

Parameters

  • params Object Parameters.
    • params.artifacts Object Contract artifacts.
    • params.spec Object The UI specification.
    • params.panelId String Id of panel.
    • params.inputs Object The user input values.
    • params.network Network? Network connection. Makes on-chain validation possible.

Returns Promise

executePanel

Execute a panel.

This will validate the inputs and make the configured on-chain calls, executing all tasks until outputs are obtained.

Parameters

  • params Object Parameters.
    • params.artifacts Object Contract artifacts.
    • params.spec Object The UI specification.
    • params.panelId String Id of panel.
    • params.inputs Object The user input values.
    • params.network Network Network connection.
    • params.progressCallback Function? Progress callback.

Returns Promise<Object> Key-value pair of output values according to the outputs configured for the panel.