diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template/proposal.rs b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template/proposal.rs index bbbca5231..cf4471d5a 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template/proposal.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_block_template/proposal.rs @@ -2,7 +2,7 @@ //! //! `ProposalResponse` is the output of the `getblocktemplate` RPC method in 'proposal' mode. -use std::{error::Error, num::ParseIntError, str::FromStr, sync::Arc}; +use std::{num::ParseIntError, str::FromStr, sync::Arc}; use zebra_chain::{ block::{self, Block, Height}, @@ -42,23 +42,21 @@ pub enum ProposalResponse { impl ProposalResponse { /// Return a rejected response containing an error kind and detailed error info. - pub fn rejected(kind: S, error: BoxError) -> Self { - let kind = kind.to_string(); + /// + /// Note: Error kind is currently ignored to match zcashd error format (`kebab-case` string). + pub fn rejected(_kind: S, error: BoxError) -> Self { + // Make error `kebab-case` to match zcashd format. + let error_kebab1 = format!("{error:?}") + .replace(|c: char| !c.is_alphanumeric(), "-") + .to_ascii_lowercase(); + // Remove consecutive duplicated `-` characters. + let mut error_v: Vec = error_kebab1.chars().collect(); + error_v.dedup_by(|a, b| a == &'-' && b == &'-'); + let error_kebab2: String = error_v.into_iter().collect(); + // Trim any leading or trailing `-` characters. + let final_error = error_kebab2.trim_matches('-'); - // Pretty-print the detailed error for now - ProposalResponse::Rejected(format!("{kind}: {error:#?}")) - } - - /// Return a rejected response containing just the detailed error information. - pub fn error(error: BoxError) -> Self { - // Pretty-print the detailed error for now - ProposalResponse::Rejected(format!("{error:#?}")) - } -} - -impl From for ProposalResponse { - fn from(error: E) -> Self { - Self::error(error.into()) + ProposalResponse::Rejected(final_error.to_string()) } } diff --git a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@mainnet_10.snap b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@mainnet_10.snap index 6d80c4277..a5f573ed1 100644 --- a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@mainnet_10.snap +++ b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@mainnet_10.snap @@ -2,4 +2,4 @@ source: zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs expression: block_template --- -"invalid proposal format: Io(\n Error {\n kind: UnexpectedEof,\n message: \"failed to fill whole buffer\",\n },\n)" +"io-error-kind-unexpectedeof-message-failed-to-fill-whole-buffer" diff --git a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@testnet_10.snap b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@testnet_10.snap index 6d80c4277..a5f573ed1 100644 --- a/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@testnet_10.snap +++ b/zebra-rpc/src/methods/tests/snapshot/snapshots/get_block_template_invalid-proposal@testnet_10.snap @@ -2,4 +2,4 @@ source: zebra-rpc/src/methods/tests/snapshot/get_block_template_rpcs.rs expression: block_template --- -"invalid proposal format: Io(\n Error {\n kind: UnexpectedEof,\n message: \"failed to fill whole buffer\",\n },\n)" +"io-error-kind-unexpectedeof-message-failed-to-fill-whole-buffer"