Options
All
  • Public
  • Public/Protected
  • All
Menu

This class's purpose is to be an abstraction for interacting with the Blockchain, and in particular, the UserDescriptors Smart Contract. This class implements methods that are in the smart contract and executes it on behalf of the invoker of this class. The actual smart contract can be found in ./contracts/UserDescriptors.sol

We want to create a class like this for every smart contract.

Hierarchy

  • UserDescriptorService

Index

Constructors

constructor

Properties

Private DECIMAL_OFFSET

DECIMAL_OFFSET: number = Math.pow(10, 4)

Private contract

contract: UserDescriptors

Local Smart Contract object that we can invoke methods on which will automatically invoke methods on the actual Smart Contract in the blockchain.

Private web3Client

web3Client: Web3

Web3 is the main JavaScript client that allows us to interact with nodes in the blockchain. It is what Truffle uses in the backend, but we can invoke it directly to get more control and not rely too much on the Truffle framework. https://web3js.readthedocs.io/en/v1.2.0/getting-started.html

Static Private USER_DESCRIPTOR_ABI_PATH

USER_DESCRIPTOR_ABI_PATH: "build/contracts/UserDescriptors.json" = "build/contracts/UserDescriptors.json"

USER_DESCRIPTOR_ABI_PATH is the path to the JSON that has information about the SmartContract that web3js can read. This allows Web3JS to add methods to a contract object that we can invoke from JavaScript.

Methods

getAccountAtIndex

  • getAccountAtIndex(index: number): Promise<string>
  • Gets all the accounts in the blockchain and returns the ID of the account at a certain index in the returned array.

    Parameters

    • index: number

    Returns Promise<string>

getAllAvailableUnitsForUser

  • getAllAvailableUnitsForUser(accountId: string, gas?: number): Promise<string[]>
  • Abstraction for UserDescriptors (smart contract) method, getAllAvailableUnitForUser(): string[] See ./contracts/UserDescriptors.sol for the actual contract method

    Parameters

    • accountId: string

      ID of the account sending the request (Local blockchain autogenerates 10 accounts to use)

    • Default value gas: number = 5000000

      Optional paramter, defaults to 5,000,000. Need gas to perform any sort of operation.

    Returns Promise<string[]>

getAllValuesRecordedForUnit

  • getAllValuesRecordedForUnit(accountId: string, unit: string, gas?: number): Promise<IDescriptor[]>
  • Abstraction for UserDescriptors (smart contract) method, getAllValuesRecordedForUnit(unit: string): number[] See ./contracts/UserDescriptors.sol for the actual contract method

    Parameters

    • accountId: string

      ID of the account sending the request (Local blockchain autogenerates 10 accounts to use)

    • unit: string

      A unit such as lb, cm, miles, kilometer, etc

    • Default value gas: number = 5000000

      Optional paramter, defaults to 5,000,000. Need gas to perform any sort of operation.

    Returns Promise<IDescriptor[]>

Private getContractAbi

  • getContractAbi(): any[]
  • This allows Web3JS to add methods to a contract object that we can invoke for our using the JSON ABI (Application Binary Interface). The JSON ABI has the contract methods that can be invoked with input paramters/types, and output paramters/types.

    Returns any[]

getLatestValueForUnit

  • getLatestValueForUnit(accountId: string, unit: string, gas?: number): Promise<number>
  • Abstraction for UserDescriptors (smart contract) method, getLatestValueForUnit(unit: string): number See ./contracts/UserDescriptors.sol for the actual contract method

    Parameters

    • accountId: string

      ID of the account sending the request (Local blockchain autogenerates 10 accounts to use)

    • unit: string

      A unit such as lb, cm, miles, kilometer, etc

    • Default value gas: number = 5000000

      Optional paramter, defaults to 5,000,000. Need gas to perform any sort of operation.

    Returns Promise<number>

getPaginatedValuesRecordedForUnit

  • getPaginatedValuesRecordedForUnit(accountId: string, unit: string, start?: number, count?: number, gas?: number): Promise<IDescriptor[]>

insertValue

  • insertValue(accountId: string, value: object, gas?: number): Promise<void>
  • Abstraction for UserDescriptors (smart contract) method, insertValue(unit: string, value: number) See ./contracts/UserDescriptors.sol for the actual contract method

    Parameters

    • accountId: string

      ID of the account sending the request (Local blockchain autogenerates 10 accounts to use)

    • value: object

      Data needed to enter itno blockchain

      • latitude: number | null
      • longitude: number | null
      • unit: string
      • value: number
    • Default value gas: number = 5000000

      Optional paramter, defaults to 5,000,000. Need gas to perform any sort of operation.

    Returns Promise<void>

Static Private BNToNumber

  • BNToNumber(val: BN): number

Generated using TypeDoc