-
Notifications
You must be signed in to change notification settings - Fork 162
add ink v6 contract dry run #1740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,12 +15,18 @@ | |
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| import { ContractPromise } from '@polkadot/api-contract'; | ||
| import { hexToU8a } from '@polkadot/util'; | ||
| import { RequestHandler } from 'express'; | ||
| import { BadRequest } from 'http-errors'; | ||
|
|
||
| import { validateAddress } from '../../middleware'; | ||
| import { ContractsInkService } from '../../services'; | ||
| import { IBodyContractMetadata, IContractQueryParam, IPostRequestHandler } from '../../types/requests'; | ||
| import { | ||
| IBodyContractMetadata, | ||
| IContractDryParams, | ||
| IContractQueryParam, | ||
| IPostRequestHandler, | ||
| } from '../../types/requests'; | ||
| import AbstractController from '../AbstractController'; | ||
|
|
||
| export default class ContractsInkController extends AbstractController<ContractsInkService> { | ||
|
|
@@ -34,6 +40,7 @@ export default class ContractsInkController extends AbstractController<Contracts | |
| protected initRoutes(): void { | ||
| this.router.use(this.path, validateAddress); | ||
| this.safeMountAsyncPostHandlers([['/query', this.callContractQuery as RequestHandler]]); | ||
| this.safeMountAsyncGetHandlers([['/dry-run', this.dryRun as RequestHandler]]); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -62,4 +69,26 @@ export default class ContractsInkController extends AbstractController<Contracts | |
| await this.service.fetchContractCall(contract, address, method, argsArray, gasLimit, storageDepositLimit), | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Send a message call to a dry run contract. It defaults to get if nothing is inputted. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Personally this is a bit hard to understand on a first read through. Maybe something like
is better? |
||
| * | ||
| * @param _req | ||
| * @param res | ||
| */ | ||
| private dryRun: IPostRequestHandler<IBodyContractMetadata, IContractDryParams> = async ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we have this.safeMountAsyncGetHandlers([['/dry-run', this.dryRun as RequestHandler]]); |
||
| { params: { address }, query: { caller, payValue = '0', inputData } }, | ||
| res, | ||
| ): Promise<void> => { | ||
| const dryRunResult = await this.api.call.reviveApi.call( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs a check if |
||
| caller, | ||
| address, | ||
| this.api.registry.createType('Balance', BigInt(payValue)), | ||
| null, | ||
| null, | ||
| hexToU8a(inputData) ?? '', | ||
| ); | ||
|
|
||
| ContractsInkController.sanitizedSend(res, dryRunResult.toHuman()); | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,12 @@ export interface IContractQueryParam extends Query { | |
| storageDepositLimit: string; | ||
| } | ||
|
|
||
| export interface IContractDryParams extends Query { | ||
| caller: string; | ||
| payValue: string; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is meant to be optional, based on the default values that is has above. |
||
| inputData: string; | ||
|
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any of these values being validated anywhere which can lead to some bugs and poor UX / hard to debug issues. |
||
| } | ||
|
|
||
| export interface IPalletsConstantsParam extends ParamsDictionary { | ||
| palletId: string; | ||
| constantItemId: string; | ||
|
|
||
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.
But this is returning
IPostRequestHandlerwhile being mounted as a GET handler.Which one is it?