Skip to content

Commit

Permalink
updated dry run controller
Browse files Browse the repository at this point in the history
  • Loading branch information
filvecchiato committed Oct 17, 2024
1 parent b7bf451 commit 24f3b70
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
23 changes: 20 additions & 3 deletions src/controllers/transaction/TransactionDryRunController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { BadRequest } from 'http-errors';
import { TransactionDryRunService } from '../../services';
import { IPostRequestHandler, ITx } from '../../types/requests';
import AbstractController from '../AbstractController';
// TODO: update this readme
/**
* Dry run an transaction.
*
Expand All @@ -29,10 +28,20 @@ import AbstractController from '../AbstractController';
* - `hash`: The block's hash.
* - `height`: The block's height.
* - `result`:
* - Successfull dry run:
* - `actualWeight`: The actual weight of the transaction.
* - `paysFee`: The fee to be paid.
* - Failed dry run:
* - error reason.
* - Dry run not possible to run:
* - `isUnimplemented`: The dry run is not implemented.
* - `isVersionedConversionFailed`: The versioned conversion failed.
* - `type`: 'Unimplemented' | 'VersionedConversionFailed';.
*
* References:
* - `UnknownTransaction`: https://crates.parity.io/sp_runtime/transaction_validity/enum.UnknownTransaction.html
* - `InvalidTransaction`: https://crates.parity.io/sp_runtime/transaction_validity/enum.InvalidTransaction.html
* - `DispatchError`: https://docs.rs/sp-runtime/39.0.1/sp_runtime/enum.DispatchError.html
* - `PostDispatchInfo`: https://docs.rs/frame-support/38.0.0/frame_support/dispatch/struct.PostDispatchInfo.html
* - `Error Type`: https://paritytech.github.io/polkadot-sdk/master/xcm_runtime_apis/dry_run/enum.Error.html
*
* Note: If you get the error `-32601: Method not found` it means that the node sidecar
* is connected to does not expose the `system_dryRun` RPC. One way to resolve this
Expand All @@ -56,6 +65,14 @@ export default class TransactionDryRunController extends AbstractController<Tran
throw new BadRequest('Missing field `tx` on request body.');
}

if (!at) {
throw new BadRequest('Missing field `at` on request body.');
}

if (!senderAddress) {
throw new BadRequest('Missing field `senderAddress` on request body.');
}

const hash = await this.getHashFromAt(at);

TransactionDryRunController.sanitizedSend(res, await this.service.dryRuntExtrinsic(hash, senderAddress, tx));
Expand Down
9 changes: 1 addition & 8 deletions src/services/transaction/TransactionDryRunService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2024 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -30,8 +27,6 @@ export type SignedOriginCaller = {
};
};

export type Format = 'payload' | 'call' | 'submittable';

export class TransactionDryRunService extends AbstractService {
async dryRuntExtrinsic(
hash: BlockHash,
Expand All @@ -47,8 +42,6 @@ export class TransactionDryRunService extends AbstractService {
},
};

// const promises: Promise<Result<CallDryRunEffects, XcmDryRunApiError> | Header>[] = [];

const [dryRunResponse, header] = await Promise.all([
api.call.dryRunApi.dryRunCall(originCaller, transaction),
api.rpc.chain.getHeader(hash),
Expand Down

0 comments on commit 24f3b70

Please sign in to comment.