Skip to content

Fix --dry-run error deserialization and report error details#534

Merged
ascjones merged 11 commits intomasterfrom
aj/rpc-dispatch-error
May 6, 2022
Merged

Fix --dry-run error deserialization and report error details#534
ascjones merged 11 commits intomasterfrom
aj/rpc-dispatch-error

Conversation

@ascjones
Copy link
Collaborator

@ascjones ascjones commented Apr 27, 2022

Closes #533.

This now parameterizes the RPC results with the generated DispatchError type from subxt so the types line up with the latest contracts node for deserializataion.

This also allows us to retrieve the DispatchError details from the metadata so we can map to a user friendly error:

image

@ascjones ascjones marked this pull request as ready for review May 3, 2022 08:22

type ContractExecResult = pallet_contracts_primitives::ContractExecResult<Balance>;
type ContractExecResult =
ContractResult<result::Result<ExecReturnValue, RuntimeDispatchError>, Balance>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the crux of the change, it is using the subxt generated RuntimeDispatchError instead of the default sp_runtime::DispatchError. This means it is using the same DispatchError type as would be returned in case of an error on calling the extrinsic.

#[subxt::subxt(
runtime_metadata_path = "src/cmd/extrinsics/runtime_api/contracts_runtime.scale"
runtime_metadata_path = "src/cmd/extrinsics/runtime_api/contracts_runtime.scale",
derive_for_type(type = "sp_runtime::DispatchError", derive = "::serde::Deserialize"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these derives to these generated types is necessary so that they can be used to deserialize the RPC --dry-run error responses.

Copy link
Contributor

@athei athei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ascjones ascjones merged commit 2961428 into master May 6, 2022
@ascjones ascjones deleted the aj/rpc-dispatch-error branch May 6, 2022 12:11
@ascjones ascjones mentioned this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModuleError out of sync, fails to deserialize --dry-run error

2 participants