-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update monetary to latest 0.7.3 * feat(transaction): dry-run transaction before submission and revert execution if dry-running fails * test: mock submittable extrinsic * refactor: rename to dryRun and document functionality * refactor: move submission code to separate folder
- Loading branch information
1 parent
12b9271
commit f563370
Showing
5 changed files
with
77 additions
and
30 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
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,36 @@ | ||
import { SubmittableExtrinsic } from '@polkadot/api/types'; | ||
|
||
import { getErrorMessage } from './error'; | ||
|
||
/** | ||
* Dry-run signed submittable extrinsic if dry-running is enabled on RPC node. | ||
* | ||
* @throws If extrinsic execution failed during dry running. | ||
* @param signedExtrinsic Extrinsic to be dry run. | ||
* @returns {SubmittableExtrinsic} Dry-ran extrinsic. | ||
*/ | ||
|
||
const dryRun = async (signedExtrinsic: SubmittableExtrinsic<'promise'>): Promise<SubmittableExtrinsic<'promise'>> => { | ||
// Dry-run if enabled on RPC node. | ||
// Source: Polkadot.js, https://github.com/polkadot-js/api/blob/319535a1e938e89522ff18ef2d1cef66a5af597c/packages/api/src/submittable/createClass.ts#L110 | ||
if (signedExtrinsic.hasDryRun) { | ||
const dryRunResult = await window.bridge.api.rpc.system.dryRun(signedExtrinsic.toHex()); | ||
|
||
// If dry-running fails, code execution throws and extrinsic is not submitted. | ||
if (dryRunResult.isErr) { | ||
const error = dryRunResult.asErr; | ||
const errMessage = error.toString(); | ||
throw new Error(errMessage); | ||
} | ||
|
||
// Handle dry-run result nested error. | ||
if (dryRunResult.isOk && dryRunResult.asOk.isErr) { | ||
const error = dryRunResult.asOk.asErr; | ||
const errMessage = getErrorMessage(window.bridge.api, error); | ||
throw new Error(errMessage); | ||
} | ||
} | ||
return signedExtrinsic; | ||
}; | ||
|
||
export { dryRun }; |
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,23 @@ | ||
import { ApiPromise } from '@polkadot/api'; | ||
import { DispatchError } from '@polkadot/types/interfaces'; | ||
|
||
const getErrorMessage = (api: ApiPromise, dispatchError: DispatchError): string => { | ||
const { isModule, asModule, isBadOrigin } = dispatchError; | ||
|
||
// Runtime error in one of the parachain modules | ||
if (isModule) { | ||
// for module errors, we have the section indexed, lookup | ||
const decoded = api.registry.findMetaError(asModule); | ||
const { docs, name, section } = decoded; | ||
return `The error code is ${section}.${name}. ${docs.join(' ')}.`; | ||
} | ||
|
||
// Bad origin | ||
if (isBadOrigin) { | ||
return `The error is caused by using an incorrect account. The error code is BadOrigin ${dispatchError}.`; | ||
} | ||
|
||
return `The error is ${dispatchError}.`; | ||
}; | ||
|
||
export { getErrorMessage }; |
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
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
f563370
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-interlay-testnet – ./
interbtc-ui-interlay-testnet-interlay.vercel.app
testnet.interlay.io
interbtc-ui-interlay-testnet.vercel.app
interbtc-ui-interlay-testnet-git-master-interlay.vercel.app
f563370
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
interbtc-ui-kintsugi-testnet – ./
interbtc-ui-kintsugi-testnet-git-master-interlay.vercel.app
interbtc-ui.vercel.app
kintnet.interlay.io
interbtc-ui-kintsugi-testnet-interlay.vercel.app