Skip to content

Commit

Permalink
fix(rpc): Refactor getrawtransaction & RPC error handling (#9049)
Browse files Browse the repository at this point in the history
* clean-up: simplify the def of `MapServerError`

* Use `HexData` instead of `String` for TXIDs

* Remove a redundant test

We don't need such a test anymore because the deserialization is handled
by Serde now.

* Adjust tests for using `HexData`

* Make `height` and `confirmations` optional

* Use legacy error codes

* fmt

* Remove unneeded error codes

* Remove `zebra-rpc/src/constants.rs`

* Rename `MapServerError` to `MapError`

* Rename `OkOrServerError` to `OkOrError`

* Allow specifying error codes when mapping errors

* Allow setting error codes when mapping options

* Use the right error code for `getrawtransaction`

* fmt

* Add docs for the error conversion traits

* Refactor the error handling for `getblock`

* Refactor error handling in `sendrawtransaction`

* Refactor the error handling for `getblock`

* Update the error handling for `getrawtransaction`

* Refactor error handling for `z_gettreestate`

* Refactor the error handling for address parsing

* Refactor the error handling for getrawtransaction

* Update `z_gettreestate` snapshots

* Cosmetics

* Refactor error handling in `getblock`

* Refactor error handling in `getblockheader`

* Simplify `getrawtransaction`

* Check errors for `getrawtransaction`

* fmt

* Simplify proptests

* Fix unit tests for `getaddresstxids`

* Fix unit tests for `getaddressutxos`

* fix docs

* Update snapshots for `getrawtransaction`

* Update zebra-rpc/src/server/error.rs

Co-authored-by: Arya <[email protected]>

* Use `transaction::Hash` instead of `HexData`

* Simplify error handling

* Update zebra-rpc/src/server/error.rs

Co-authored-by: Alfredo Garcia <[email protected]>

* Move a note on performance

* Fix a typo

* Use `String` instead of `transaction::Hash`

* Adjust and add proptests

* Reintroduce snapshots for invalid TXIDs

* Don't derive `Serialize` & `Deserialize` for txids

Deriving `serde::Serialize` & `serde::Deserialize` for
`transaction::Hash` was superfluous, and we didn't need it anywhere in
the code.

---------

Co-authored-by: Arya <[email protected]>
Co-authored-by: Alfredo Garcia <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 13, 2024
1 parent 568b25e commit b0c4d19
Show file tree
Hide file tree
Showing 31 changed files with 762 additions and 875 deletions.
3 changes: 1 addition & 2 deletions zebra-chain/src/transaction/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use std::{fmt, sync::Arc};
use proptest_derive::Arbitrary;

use hex::{FromHex, ToHex};
use serde::{Deserialize, Serialize};

use crate::serialization::{
ReadZcashExt, SerializationError, WriteZcashExt, ZcashDeserialize, ZcashSerialize,
Expand All @@ -56,7 +55,7 @@ use super::{txid::TxIdBuilder, AuthDigest, Transaction};
///
/// [ZIP-244]: https://zips.z.cash/zip-0244
/// [Spec: Transaction Identifiers]: https://zips.z.cash/protocol/protocol.pdf#txnidentifiers
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, Hash)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
pub struct Hash(pub [u8; 32]);

Expand Down
44 changes: 0 additions & 44 deletions zebra-rpc/src/constants.rs

This file was deleted.

1 change: 0 additions & 1 deletion zebra-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![doc(html_root_url = "https://docs.rs/zebra_rpc")]

pub mod config;
pub mod constants;
pub mod methods;
pub mod queue;
pub mod server;
Expand Down
Loading

0 comments on commit b0c4d19

Please sign in to comment.