Options
All
  • Public
  • Public/Protected
  • All
Menu
description

This factory class can used to re-build contracts from their JSON payloads or directly from the transactions that included them.

Use this factory whenever you would like to create a contract instance from its' JSON payload or transaction content.

example

Using the Factory class

// re-creates the `Auth` contract
const contract1: Auth = Factory.createFromJSON({
contract: "elevate:auth",
version: 1,
challenge: "abcdef12",
});

// re-creates the `Referral` contract
const contract2: Referral = Factory.createFromJSON({
contract: "elevate:referral",
version: 1,
refCode: "MY-REF-CODE",
});



Other links

Contract | Auth | Earn | Referral | Welcome

since

v0.3.0

Hierarchy

  • Factory

Index

Constructors

  • Constructs an instance of this Factory class.

    Note that you should not use this method directly, please refer to the static API methods instead.

    access

    protected

    Parameters

    • parameters: NetworkParameters = ...

      (Optional) A configuration object that is used to overwrite the default network parameters.

    Returns Factory

Methods

  • This method parses the contract signature and creates a new instance of a child class of Contract, attaching the version, the inputs and network parameters to it, i.e. this method may return instances from classes that include, but are not limited to: Auth, Earn, Referral or Welcome.

    Given an invalid {@link contract} signature, this method will trigger the UnknownContractError to be thrown.

    This method is used internally to create a matching contract's child class instance using the correct inputs, version and parameters.

    access

    protected

    Parameters

    • contract: string

      A contract signature that consists of the dApp identifier and the contract identifier.

    • version: number

      A contract version that consists of a number set to identify the version of the contract implementation.

    • inputs: ContractParameters

      A set of inputs that are/were passed to the contract during runtime and that are attached to its JSON payload.

    • parameters: NetworkParameters

      The network parameters ("connection details") as present in the factory.

    Returns Contract

    An instance of a child class of Contract that has been built using the {@link contractJSON} JSON payload, e.g. Auth, Earn, Welcome.

  • This method parses a contract's JSON payload to create an object of type ObjectLiteral. This is necessary to further secure the processes that manipulate this created object.

    Invalid JSON errors will trigger the InvalidContractError exception to be thrown.

    This method is used internally to transform a string JSON payload into an ObjectLiteral by making sure that the JSON payload uses valid JSON formatting rules.

    access

    protected

    throws

    {InvalidContractError} Given contract JSON payload that contains invalid JSON and could not get parsed into a contract.

    Parameters

    Returns ObjectLiteral

    A parsed contract consists of an object of type ObjectLiteral.

  • This method parses a contract's JSON payload to create an object of type ObjectLiteral. This is necessary to further secure the processes that manipulate this created object. Note that we use the Contract.fromTransaction method to parse JSON payloads from transaction objects as presented on dHealth Network.

    Invalid JSON errors will trigger the InvalidContractError exception to be thrown.

    This method is used internally to transform a Transaction object into an ObjectLiteral by making sure that the JSON payload uses valid JSON formatting rules and lives inside either of: the transfer transaction message or the aggregate bundle's first transfer transaction's message.

    access

    protected

    throws

    {InvalidContractError} Given no contract JSON payload is found or given a contract JSON payload that contains invalid JSON and could not get parsed into a contract.

    Parameters

    • transaction: Transaction

      A transaction object that contains the full definition of the executed contract.

    Returns ObjectLiteral

    A parsed contract consists of an object of type ObjectLiteral.

  • This static factory method creates a contract instance using its' JSON payload as present on dHealth Network in transfer transaction messages.

    Note that JSON payloads must contain a contract field, as well as a version field. Additionally, for some contracts it is possible that other fields are required, as defined by their Contract.body implementation.

    As for the dApp identifier, that is attached in the contract field, we authorize the use of uppercase characters just to prevent unnecessary errors from happening due toinconsistent end-user inputs, i.e. on-chain it is OK to use `"ELEvATE:auTH", but we of course recommend not to do that and to rather prefer using this library for creating contract, instead.

    access

    public

    static
    throws

    {MissingContractFieldError} Given missing one or more obligatory field(s) in the contract JSON payload.

    throws

    {InvalidContractError} Given contract JSON payload that contains invalid JSON and could not get parsed into a contract.

    throws

    {UnknownContractError} Given contract JSON payload that could not get parsed into a valid contract that extends Contract.

    Parameters

    • contractJSON: string | ObjectLiteral

      A string or ObjectLiteral object that contains the full JSON payload of the contract.

    • parameters: NetworkParameters = ...

      (Optional) A configuration object that is used to overwrite the default network parameters.

    Returns Contract

    An instance of a child class of Contract that has been built using the {@link contractJSON} JSON payload, e.g. Auth, Earn, Welcome.

  • This static factory method creates a contract instance using a dHealth Transaction, as present on dHealth Network in transfer transaction messages OR in the first transfer transaction of an aggregate bundle.

    Refer to the Factory.createFromJSON factory for more details about how this library parses the JSON payloads.

    access

    public

    static
    throws

    {MissingContractFieldError} Given missing one or more obligatory field(s) in the contract JSON payload.

    throws

    {InvalidContractError} Given no contract JSON payload is found or given a contract JSON payload that contains invalid JSON and could not get parsed into a contract.

    throws

    {UnknownContractError} Given contract JSON payload that could not get parsed into a valid contract that extends Contract.

    Parameters

    • transaction: Transaction

      A transaction object that contains the full definition of the executed contract.

    • parameters: NetworkParameters = ...

      (Optional) A configuration object that is used to overwrite the default network parameters.

    Returns Contract

    An instance of a child class of Contract that has been built using the {@link transaction}, e.g. Auth, Earn, Welcome.

Generated using TypeDoc