Skip to content

Unexpected batch behavior #95

Description

@evanlinjin

The problem

If we do a batch request where the response array contains a response object which is an error, ElectrumClient will return Err(Error::Protocol) and the response objects will be discarded. This is not ideal as in most instances, we still want the response objects.

For example, a single request to method blockchain.transaction.get may return an response object with error if the transaction does not exist. Doing a batch of blockchain.transaction.get requests where we have a single transaction that the electrum server is not aware of (yet), will result in us not seeing any of the other response objects.

This is the current API for a batch request

fn batch_call(&self, batch: &Batch) -> Result<Vec<serde_json::Value>, Error> {

Proposed solution

fn batch_call(&self, batch: &Batch) -> Result<Vec<RawResponse>, Error> { todo!() }

pub enum RawResponse {
    /// Instead of returning `Err(Error::Protocol)`, we have this.
    Error { code: i32, message: String, data: Option<serde::Value> },

    /// The successful result, as usual.
    Result(serde::Value),
}

The RawResponse can be used to transform into a non-raw response depending on the method invoked.

For example, client.transaction_get() can return Result<Option<Transaction>, Error>.

Questions

  • The electrum server API docs does not provide error codes for error responses. Is there a standard for these? For example, if a transaction is not found.

Reference

Activity

  1. added this to the milestone on Nov 12, 2023
  2. modified the milestones: , on Dec 12, 2023
  3. removed this from the milestone on Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions