How to use the @liquality/errors.InvalidProviderResponseError function in @liquality/errors

To help you get started, we’ve selected a few @liquality/errors examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
if (!isString(txHash)) {
      throw new TypeError('Transaction hash should be a string')
    }

    if (!(/^[A-Fa-f0-9]+$/.test(txHash))) {
      throw new TypeError('Transaction hash should be a valid hex string')
    }

    const transaction = await this.client.getMethod('getTransactionByHash')(txHash)

    if (transaction) {
      const valid = this.validateTransaction(transaction)

      if (!valid) {
        const errors = this.validateTransaction.errors
        throw new InvalidProviderResponseError(`Provider returned an invalid transaction: ${errors[0].dataPath} ${errors[0].message}`)
      }
    }

    return transaction
  }
github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
if (!isString(blockHash)) {
      throw new TypeError('Block hash should be a string')
    }

    if (!(/^[A-Fa-f0-9]+$/.test(blockHash))) {
      throw new TypeError('Block hash should be a valid hex string')
    }

    if (!isBoolean(includeTx)) {
      throw new TypeError('Second parameter should be boolean')
    }

    const block = await this.client.getMethod('getBlockByHash')(blockHash, includeTx)

    if (!this.validateBlock(block)) {
      throw new InvalidProviderResponseError('Provider returned an invalid block')
    }

    return block
  }
github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
async generateBlock (numberOfBlocks) {
    if (!isNumber(numberOfBlocks)) {
      throw new TypeError('First argument should be a number')
    }

    const blockHashes = await this.client.getMethod('generateBlock')(numberOfBlocks)

    if (!isArray(blockHashes)) {
      throw new InvalidProviderResponseError('Response should be an array')
    }

    const invalidBlock = find(blockHashes, blockHash => !(/^[A-Fa-f0-9]+$/.test(blockHash)))

    if (invalidBlock) {
      throw new InvalidProviderResponseError('Invalid block(s) found in provider\'s reponse')
    }

    return blockHashes
  }
github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
async generateBlock (numberOfBlocks) {
    if (!isNumber(numberOfBlocks)) {
      throw new TypeError('First argument should be a number')
    }

    const blockHashes = await this.client.getMethod('generateBlock')(numberOfBlocks)

    if (!isArray(blockHashes)) {
      throw new InvalidProviderResponseError('Response should be an array')
    }

    const invalidBlock = find(blockHashes, blockHash => !(/^[A-Fa-f0-9]+$/.test(blockHash)))

    if (invalidBlock) {
      throw new InvalidProviderResponseError('Invalid block(s) found in provider\'s reponse')
    }

    return blockHashes
  }
github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
async getBlockByNumber (blockNumber, includeTx = false) {
    if (!isNumber(blockNumber)) {
      throw new TypeError('Invalid Block number')
    }

    if (!isBoolean(includeTx)) {
      throw new TypeError('Second parameter should be boolean')
    }

    const block = await this.client.getMethod('getBlockByNumber')(blockNumber, includeTx)

    const valid = this.validateBlock(block)

    if (!valid) {
      const errors = this.validateBlock.errors
      throw new InvalidProviderResponseError(`Provider returned an invalid block, ${errors[0].dataPath} ${errors[0].message}`)
    }

    return block
  }
github liquality / chainabstractionlayer / packages / client / lib / Wallet.js View on Github external
async getAddresses (startingIndex = 0, numAddresses = 1, change = false) {
    const addresses = await this.client.getMethod('getAddresses')(startingIndex, numAddresses, change)

    if (!isArray(addresses)) {
      throw new InvalidProviderResponseError('Provider returned an invalid response')
    }

    return addresses
  }
github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
async getBalance (addresses) {
    if (!isArray(addresses)) {
      addresses = [ addresses ]
    }

    const balance = await this.client.getMethod('getBalance')(addresses)

    if (!BigNumber.isBigNumber(balance)) {
      throw new InvalidProviderResponseError('Provider returned an invalid response')
    }

    return balance
  }
github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
async getBlockHeight () {
    const blockHeight = await this.client.getMethod('getBlockHeight')()

    if (!isNumber(blockHeight)) {
      throw new InvalidProviderResponseError('Provider returned an invalid block height')
    }

    return blockHeight
  }
github liquality / chainabstractionlayer / packages / client / lib / Chain.js View on Github external
async sendRawTransaction (rawTransaction) {
    const txHash = await this.client.getMethod('sendRawTransaction')(rawTransaction)

    if (!isString(txHash)) {
      throw new InvalidProviderResponseError('sendRawTransaction method should return a transaction id string')
    }

    return txHash
  }

@liquality/errors

[![Build Status](https://travis-ci.com/liquality/chainabstractionlayer.svg?branch=master)](https://travis-ci.com/liquality/chainabstractionlayer) [![Coverage Status](https://coveralls.io/repos/github/liquality/chainabstractionlayer/badge.svg?branch=master

MIT
Latest version published 2 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages