Skip to content

Commit

Permalink
Merge pull request #162 from liquality/eth-swap-block-scanning
Browse files Browse the repository at this point in the history
Swap: add startBlock parameter to find functions
  • Loading branch information
monokh committed Mar 28, 2019
2 parents 7b45120 + 728ce2c commit 1bbae33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,11 @@ export default class Client {
* @param {!string} refundAddress - Refund address
* @param {!string} secretHash - Secret hash
* @param {!string} expiration - Expiration time
* @param {number} [startBlock] - The block number to start finding from (Optional)
* @return {Promise<string>} Resolves with a transaction identifier.
*/
async findInitiateSwapTransaction (value, recipientAddress, refundAddress, secretHash, expiration) {
return this.getMethod('findInitiateSwapTransaction')(value, recipientAddress, refundAddress, secretHash, expiration)
async findInitiateSwapTransaction (value, recipientAddress, refundAddress, secretHash, expiration, startBlock = null) {
return this.getMethod('findInitiateSwapTransaction')(value, recipientAddress, refundAddress, secretHash, expiration, startBlock)
}

/**
Expand All @@ -385,10 +386,11 @@ export default class Client {
* @param {!string} refundAddress - Refund address
* @param {!string} secretHash - Secret hash
* @param {!string} expiration - Expiration time
* @param {number} [startBlock] - The block number to start finding from (Optional)
* @return {Promise<string>} Resolves with a transaction identifier.
*/
async findClaimSwapTransaction (initiationTxHash, recipientAddress, refundAddress, secretHash, expiration) {
return this.getMethod('findClaimSwapTransaction')(initiationTxHash, recipientAddress, refundAddress, secretHash, expiration)
async findClaimSwapTransaction (initiationTxHash, recipientAddress, refundAddress, secretHash, expiration, startBlock = null) {
return this.getMethod('findClaimSwapTransaction')(initiationTxHash, recipientAddress, refundAddress, secretHash, expiration, startBlock)
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/providers/ethereum/EthereumSwapProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export default class EthereumSwapProvider extends Provider {
return transactionMatchesSwapParams && initiationTransactionReceipt.status === '1'
}

async findInitiateSwapTransaction (value, recipientAddress, refundAddress, secretHash, expiration) {
let blockNumber = await this.getMethod('getBlockHeight')()
async findInitiateSwapTransaction (value, recipientAddress, refundAddress, secretHash, expiration, startBlock) {
let blockNumber = startBlock || await this.getMethod('getBlockHeight')()
let initiateSwapTransaction = null
while (!initiateSwapTransaction) {
const block = await this.getMethod('getBlockByNumber')(blockNumber, true)
Expand All @@ -119,8 +119,8 @@ export default class EthereumSwapProvider extends Provider {
return initiateSwapTransaction
}

async findClaimSwapTransaction (initiationTxHash) {
let blockNumber = await this.getMethod('getBlockHeight')()
async findClaimSwapTransaction (initiationTxHash, recipientAddress, refundAddress, secretHash, expiration, startBlock) {
let blockNumber = startBlock || await this.getMethod('getBlockHeight')()
let claimSwapTransaction = null
while (!claimSwapTransaction) {
const initiationTransaction = await this.getMethod('getTransactionReceipt')(initiationTxHash)
Expand Down

0 comments on commit 1bbae33

Please sign in to comment.