Skip to content
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

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

Merged
merged 11 commits into from
May 6, 2022

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
use subxt::{
rpc::NumberOrHex,
ClientBuilder,
Config,
DefaultConfig,
};

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.

@@ -15,6 +15,17 @@
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

#[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