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

send_tx bug: RequestValidation error #141

Closed
jaswinder6991 opened this issue Apr 21, 2024 · 1 comment · Fixed by #142
Closed

send_tx bug: RequestValidation error #141

jaswinder6991 opened this issue Apr 21, 2024 · 1 comment · Fixed by #142

Comments

@jaswinder6991
Copy link
Contributor

Problem:
When running the send_tx method, I see the below error:

response: Err(
    ServerError(
        RequestValidationError(
            ParseError {
                error_message: "Unable to parse send request: too many params passed",
            },
        ),
    ),
)

Steps to reproduce:
Run the send_tx example using cargo run --example send_tx

@jaswinder6991
Copy link
Contributor Author

jaswinder6991 commented Apr 21, 2024

After doing some digging, I found out that the params method in send_tx is actually creating an array during serialising the parameters.
See here and below:

fn params(&self) -> Result<serde_json::Value, io::Error> {
        Ok(json!([
            common::serialize_signed_transaction(&self.signed_transaction)?,
            self.wait_until
        ]))
    }

Which is a problem for the RpcServer, see here and below:

impl RpcRequest for RpcSendTransactionRequest {
    fn parse(value: Value) -> Result<Self, RpcParseError> {
        let tx_request = Params::new(value)
            .try_singleton(|value| {
                Ok(RpcSendTransactionRequest {
                    signed_transaction: decode_signed_transaction(value)?,
                    // will be ignored in `broadcast_tx_async`, `broadcast_tx_commit`
                    wait_until: Default::default(),
                })
            })
            .try_pair(|_: String, _: String| {
                // Here, we restrict serde parsing object from the array
                // `wait_until` is a new feature supported only in object
                Err(RpcParseError(
                    "Unable to parse send request: too many params passed".to_string(),
                ))
            })
            .unwrap_or_parse()?;
        Ok(tx_request)
    }
}

As you can see arrays are rejected and the error I see is actually thrown here.

I could locally fix this with below changes to the params function in send_tx method in rpc client:

fn params(&self) -> Result<serde_json::Value, io::Error> {
        Ok(json!({
            "signed_tx_base64": common::serialize_signed_transaction(&self.signed_transaction)?,
            "wait_until": self.wait_until
    }))
    } 

Here is a PR for the fix - #142

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant