Skip to content

Commit

Permalink
Add docs to ConvertTransaction and NoTransactionConverter (#977)
Browse files Browse the repository at this point in the history
* Add docs to ConvertTransaction and NoTransactionConverter

* Update lib.rs
  • Loading branch information
sorpaas authored Aug 1, 2023
1 parent ff8bd85 commit c020c05
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion primitives/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,20 @@ sp_api::decl_runtime_apis! {
}
}

/// Fallback transaction converter when the `ConvertTransactionRuntimeApi` is not available. For almost all
/// non-legacy cases, you can instantiate this type as `NoTransactionConverter`.
pub trait ConvertTransaction<E> {
fn convert_transaction(&self, transaction: ethereum::TransactionV2) -> E;
}

/// No fallback transaction converter is available.
// `NoTransactionConverter` is a non-instantiable type (an enum with no variants),
// so we are guaranteed at compile time that `NoTransactionConverter` can never be instantiated.
pub enum NoTransactionConverter {}
impl<E> ConvertTransaction<E> for NoTransactionConverter {
// `convert_transaction` is a method taking `&self` as a parameter, so it can only be called via an instance of type Self,
// so we are guaranteed at compile time that this method can never be called.
fn convert_transaction(&self, _transaction: ethereum::TransactionV2) -> E {
unreachable!()
match *self {}
}
}
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let
rev = "78e723925daf5c9e8d0a1837ec27059e61649cb6";
});
nixpkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
rust-nightly = with nixpkgs; ((rustChannelOf { date = "2022-11-15"; channel = "nightly"; }).rust.override {
rust-nightly = with nixpkgs; ((rustChannelOf { date = "2023-07-23"; channel = "nightly"; }).rust.override {
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
});
Expand Down

0 comments on commit c020c05

Please sign in to comment.