How to use the @liquality/utils.sleep function in @liquality/utils

To help you get started, we’ve selected a few @liquality/utils 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 / bitcoin-swap-provider / lib / BitcoinSwapProvider.js View on Github external
let blockNumber = startBlock || await this.getMethod('getBlockHeight')() // TODO: Are mempool TXs possible?
    let swapTransaction = null
    let arrivedAtTip = false
    while (!swapTransaction) {
      let block
      try {
        block = await this.getMethod('getBlockByNumber')(blockNumber, true)
      } catch (e) {
        arrivedAtTip = true
      }
      if (block) {
        swapTransaction = block.transactions.find(predicate)
        blockNumber++
      }
      if (arrivedAtTip) {
        await sleep(5000)
      }
    }
    return swapTransaction
  }
github liquality / chainabstractionlayer / packages / ethereum-swap-provider / lib / EthereumSwapProvider.js View on Github external
this.doesTransactionMatchSwapParams(
            transaction,
            value,
            recipientAddress,
            refundAddress,
            secretHash,
            expiration
          )
        )

        blockNumber++
      } else {
        arrivedAtTip = true
      }

      if (arrivedAtTip) { await sleep(5000) }
    }

    return initiateSwapTransaction
  }
github liquality / chainabstractionlayer / packages / ethereum-swap-provider / lib / EthereumSwapProvider.js View on Github external
async findSwapTransaction (value, recipientAddress, refundAddress, secretHash, expiration, startBlock, predicate) {
    let blockNumber = startBlock || await this.getMethod('getBlockHeight')()
    let swapTransaction = false

    while (!swapTransaction) {
      const block = await this.getMethod('getBlockByNumber')(blockNumber, true)

      if (block) {
        swapTransaction = block.transactions.find(predicate)
        blockNumber++
      }

      await sleep(5000)
    }

    return swapTransaction
  }
github liquality / chainabstractionlayer / packages / bitcoin-bitcoinjs-lib-swap-provider / lib / BitcoinBitcoinJsLibSwapProvider.js View on Github external
async findSwapTransaction (recipientAddress, refundAddress, secretHash, expiration, predicate) {
    let blockNumber = await this.getMethod('getBlockHeight')()
    let swapTransaction = null
    while (!swapTransaction) {
      let block
      try {
        block = await this.getMethod('getBlockByNumber')(blockNumber, true)
      } catch (e) { }
      if (block) {
        swapTransaction = block.transactions.find(predicate)
        blockNumber++
      }
      await sleep(5000)
    }
    return swapTransaction
  }
github liquality / chainabstractionlayer / packages / ethereum-swap-provider / lib / EthereumSwapProvider.js View on Github external
if (block && initiationTransaction) {
        const transaction = block.transactions.find(
          transaction => transaction.to === initiationTransaction.contractAddress
        )

        if (transaction) {
          const transactionReceipt = await this.getMethod('getTransactionReceipt')(transaction.hash)
          if (transactionReceipt.status === '1' && transaction.input !== '') claimSwapTransaction = transaction
        }

        blockNumber++
      } else {
        arrivedAtTip = true
      }

      if (arrivedAtTip) { await sleep(5000) }
    }
    claimSwapTransaction.secret = await this.getSwapSecret(claimSwapTransaction.hash)

    return claimSwapTransaction
  }
github liquality / chainabstractionlayer / packages / ethereum-erc20-swap-provider / lib / EthereumErc20SwapProvider.js View on Github external
async initiateSwap (value, recipientAddress, refundAddress, secretHash, expiration) {
    const bytecode = this.createSwapScript(recipientAddress, refundAddress, secretHash, expiration)
    const txHash = await this.getMethod('sendTransaction')(null, 0, bytecode)
    let initiationTransactionReceipt = null

    while (initiationTransactionReceipt === null) {
      initiationTransactionReceipt = await this.getMethod('getTransactionReceipt')(txHash)
      await sleep(5000)
    }

    await this.getMethod('sendTransaction')(initiationTransactionReceipt.contractAddress, value)
    return txHash
  }

@liquality/utils

[![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 3 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages