Home Reference Source Repository
public class | source

Evaluator

Evaluator class is used for performing different evaluation methods on a Fincontracts' descriptions.

Example:

import Fetcher from './fincontract-fetcher';
import Evaluator from './fincontract-evaluator';
import Currency from './currency';
const f = new Fetcher(marketplace);
const e = new Evaluator(web3, gateway);
const method = 'estimate';
const id = '<32 byte address of a deployed Fincontract>';
try {
  const fincontract = await f.pullFincontract(id);
  const evaluated   = await e.evaluate(fincontract.rootDescription, {method});
  const currencies  = Currency.convertToJSON(evaluated);
  const exchanged   = await Currency.changeAllCurrencies('USD', currencies);
  console.log(JSON.stringify(evaluated));
  console.log(JSON.stringify(exchanged));
} catch (err) {
  console.log(error(err));
}

Constructor Summary

Public Constructor
public

constructor(web3: Web3, gateway: Gateway)

Constructs the Evaluator object with a web3 instance and a Gateway smart contract instance not connected to any address

Method Summary

Public Methods
public

async evaluate(description: FincNode, options: Object): Promise

Evaluates a description of Fincontract, actual evaluation is delegated to EvaluatorVisitor.

Public Constructors

public constructor(web3: Web3, gateway: Gateway) source

Constructs the Evaluator object with a web3 instance and a Gateway smart contract instance not connected to any address

Params:

NameTypeAttributeDescription
web3 Web3

a web3 instance connected to Ethereum node

gateway Gateway

a gateway instance not connected to any address

Public Methods

public async evaluate(description: FincNode, options: Object): Promise source

Evaluates a description of Fincontract, actual evaluation is delegated to EvaluatorVisitor. This method implements two options: direct and estimate evaluation. direct updates Gateways in all FincScaleObsNode and FincIfNode nodes before performing evaluation. It then later calls these Gateways to get the latest values. On the other hand estimate evaluation needs an interval for FincScaleObsNode and FincIfNode nodes are treated like FincOrNode, by assuming that both sub-fincontracts are equally likely.

Params:

NameTypeAttributeDescription
description FincNode

root of FincNode tree for evaluation

options Object
options.method String

Method for evaluating the description tree

Return:

Promise

resolves promise if evaluation succeeded with {Array} of currency intervals or rejects with Error if it failed