bitcoindevkit / bitcoindevkit/rust-electrum-client
Unexpected batch behavior
- Lingua principale
- Rust
- Stelle
- 89
- Fork
- 82
- Merge medio
- 2g 3h
- PR unite (30g)
- 1
Descrizione
### 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**
https://github.com/bitcoindevkit/rust-electrum-client/blob/129081999ce96f1ed33877a2aecad4e2550764f3/src/raw_client.rs#L697
### Proposed solution
```rust
fn batch_call(&self, batch: &Batch) -> Result, Error> { todo!() }
pub enum RawResponse {
/// Instead of returning `Err(Error::Protocol)`, we have this.
Error { code: i32, message: String, data: Option },
/// 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, 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
- https://www.jsonrpc.org/specification
- https://electrumx-spesmilo.readthedocs.io/en/latest/protocol-methods.html#blockchain-transaction-get
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia con batch_call in src/raw_client.rs intorno alla riga 697 e confronta il suo comportamento con la specifica JSON-RPC e la documentazione di ElectrumX su transaction-get collegata nell’issue. Traccia il modo in cui le risposte grezze diventano risultati specifici del metodo, quindi definisci e testa l’API batch completa affinché le risposte di errore rimangano disponibili insieme alle risposte riuscite e il comportamento indicato di transaction_get sia coperto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- backend-api-design
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100