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 |
Evaluates a description of Fincontract, actual evaluation is delegated to EvaluatorVisitor. |
Public Constructors
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.
Return:
Promise | resolves promise if evaluation succeeded with {Array} of currency intervals or rejects with Error if it failed |