This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
waitForStateTransactionResult
checks existing result (#341)
- Loading branch information
Showing
21 changed files
with
595 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 0 additions & 54 deletions
54
...derdash/blockchainListener/waitForTransactionToBeProvable/waitForTransactionCommitment.js
This file was deleted.
Oops, something went wrong.
69 changes: 0 additions & 69 deletions
69
...lockchainListener/waitForTransactionToBeProvable/waitForTransactionToBeProvableFactory.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const BlockchainListener = require('./BlockchainListener'); | ||
|
||
/** | ||
* @param {BlockchainListener} blockchainListener | ||
*/ | ||
function waitForHeightFactory(blockchainListener) { | ||
let currentHeight = 0; | ||
|
||
blockchainListener.on(BlockchainListener.EVENTS.NEW_BLOCK, (message) => { | ||
currentHeight = parseInt(message.data.value.block.header.height, 10); | ||
}); | ||
|
||
/** | ||
* @typedef {waitForHeight} | ||
* @param {number} height | ||
* @return {Promise<void>} | ||
*/ | ||
function waitForHeight(height) { | ||
return new Promise((resolve) => { | ||
if (currentHeight >= height) { | ||
resolve(); | ||
|
||
return; | ||
} | ||
|
||
const handler = () => { | ||
if (currentHeight >= height) { | ||
blockchainListener.off(BlockchainListener.EVENTS.NEW_BLOCK, handler); | ||
|
||
resolve(); | ||
} | ||
}; | ||
|
||
blockchainListener.on(BlockchainListener.EVENTS.NEW_BLOCK, handler); | ||
}); | ||
} | ||
|
||
return waitForHeight; | ||
} | ||
|
||
module.exports = waitForHeightFactory; |
45 changes: 45 additions & 0 deletions
45
lib/externalApis/tenderdash/waitForTransactionToBeProvable/getExistingTransactionResult.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const TransactionOkResult = require('./transactionResult/TransactionOkResult'); | ||
const TransactionErrorResult = require('./transactionResult/TransactionErrorResult'); | ||
const RPCError = require('../../../rpcServer/RPCError'); | ||
|
||
/** | ||
* @param {RpcClient} rpcClient | ||
* @return {getExistingTransactionResult} | ||
*/ | ||
function getExistingTransactionResultFactory(rpcClient) { | ||
/** | ||
* @typedef {getExistingTransactionResult} | ||
* @param {string} hashString | ||
* @return {Promise<TransactionOkResult|TransactionErrorResult>} | ||
*/ | ||
async function getExistingTransactionResult(hashString) { | ||
const hash = Buffer.from(hashString, 'hex'); | ||
|
||
const params = { hash: hash.toString('base64') }; | ||
|
||
const { result, error } = await rpcClient.request('tx', params); | ||
|
||
// Handle JSON RPC error | ||
if (error) { | ||
throw new RPCError( | ||
error.code || -32602, | ||
error.message || 'Internal error', | ||
error.data, | ||
); | ||
} | ||
|
||
const TransactionResultClass = result.tx_result.code === 0 | ||
? TransactionOkResult | ||
: TransactionErrorResult; | ||
|
||
return new TransactionResultClass( | ||
result.tx_result, | ||
parseInt(result.height, 10), | ||
Buffer.from(result.tx, 'base64'), | ||
); | ||
} | ||
|
||
return getExistingTransactionResult; | ||
} | ||
|
||
module.exports = getExistingTransactionResultFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.