[REFACTOR][RPC] Centralize RPC traits and method names#1067
Open
moisesPompilio wants to merge 7 commits into
Open
[REFACTOR][RPC] Centralize RPC traits and method names#1067moisesPompilio wants to merge 7 commits into
moisesPompilio wants to merge 7 commits into
Conversation
ed4a6ff to
2443380
Compare
3 tasks
Replace hardcoded method name strings with a single source of truth. The RpcMethods enum provides FromStr, to_string(), and as_str() for type-safe method name handling, preventing divergence across codebase.
Split RPC methods into category-specific traits (Blockchain, Wallet, Network, RawTransaction, Control) for better code organization, segregation, and flexible implementation across RPC and CLI.
2443380 to
c357d5a
Compare
Introduce maybe_async procedural macro to NetworkRpc trait to support both async and sync implementations. This allows: - Shared trait definitions between floresta-node (async) and floresta-rpc (sync) - Consistent interface across different implementations - NetworkRpc trait now implemented in floresta-node to ensure network operations are compatible between floresta-node and floresta-rpc Fix build compatibility issue: - maybe_async feature conflicts when building entire workspace - Adjusted justfile to compile individual crates by path instead of workspace super-set to prevent async feature leaking into floresta-cli - floresta-cli now builds without async feature to preserve RPC implementation
Add maybe_async support to WalletRpc trait enabling async/sync flexibility. WalletRpc now implemented in floresta-node to ensure consistency.
…a-node Enable async/sync flexibility for ControlRpc trait with maybe_async. Provides unified interface for control operations (get_memory_info, get_rpc_info, stop, uptime) across floresta-node and floresta-rpc.
…esta-node Enable async/sync flexibility for BlockchainRpc trait with maybe_async. Provides unified interface for blockchain operations across floresta-node and floresta-rpc, completing the RPC trait migration pattern.
Enable async/sync flexibility for RawTransactionRpc trait with maybe_async. Remove corepc_types dependency from floresta-node, centralizing all RPC types in floresta-rpc as single source of truth.
c357d5a to
167b5c2
Compare
Collaborator
Author
|
167b5c2 I rebased |
| self.call("loaddescriptor", &[Value::String(descriptor)]) | ||
| } | ||
|
|
||
| fn get_block_filter(&self, height: u32) -> Result<String> { |
Member
There was a problem hiding this comment.
You removed get_block_filter?
| @@ -0,0 +1,156 @@ | |||
| use core::fmt::Debug; | |||
Member
There was a problem hiding this comment.
SPDX headers and module-level docs
| use core::fmt::Debug; | ||
| use std::str::FromStr; | ||
|
|
||
| macro_rules! define_rpc_methods { |
Member
There was a problem hiding this comment.
Docs for this macro would be nice!
| Methods::GetBlockCount => serde_json::to_string_pretty(&client.get_block_count()?)?, | ||
| Methods::GetTxOut { txid, vout } => { | ||
| serde_json::to_string_pretty(&client.get_tx_out(txid, vout)?)? | ||
| serde_json::to_string_pretty(&client.get_tx_out(txid, vout, false)?)? |
| /// Returns the transaction, assuming it is cached by our watch only wallet | ||
| #[command(name = "gettransaction")] | ||
| GetTransaction { txid: Txid, verbose: Option<bool> }, | ||
| GetTransaction { txid: Txid, verbose: Option<u32> }, |
| script: String, | ||
| height_hint: u32, | ||
| ) -> Result<Value> { | ||
| height: u32, |
Comment on lines
+98
to
+100
| if result.is_null() { | ||
| return Err(Error::TxOutNotFound); | ||
| } |
Member
There was a problem hiding this comment.
Is this right? Shouldn't this be handled at server side?
Comment on lines
+48
to
+55
| #!/usr/bin/env bash | ||
| set -e | ||
| CRATES=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.source == null and (.targets | map(.kind | contains(["lib"])) | any)) | .name' | tr '\n' ' ') | ||
| echo "Building docs for crates: $CRATES" | ||
| for crate in $CRATES; do | ||
| echo "Running cargo doc for: $crate" | ||
| RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo +nightly doc -p "$crate" --no-deps --lib --all-features --document-private-items || exit 1 | ||
| done |
Member
There was a problem hiding this comment.
Hmm, we need to make sure we can build docs for https://docs.gefloresta.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description and Notes
The RPC trait and method definitions were centralized so that
floresta-rpcandfloresta-nodestay aligned and compatible.At the moment,
floresta-rpcimplements RPC methods that are consumed by the node, whilefloresta-nodeexposes the server-side implementation that serves the same methods. To avoid inconsistencies between both crates, this change introduces shared RPC traits that define the contract for these methods in a single place.The main challenge is that
floresta-rpcneeds synchronous traits, whilefloresta-nodeneeds asynchronous ones. To solve this, this change introduces themaybe-asyncmacro, which allows the same trait definitions to support both sync and async implementations through a single code path.In addition to the trait unification, the RPC macros were reorganized into categories similar to Bitcoin Core:
walletblockchaincontrolnetworkutilrawtransactionsIt also introduces
RpcMethods, an enum that acts as the single source of truth for all RPC method names. It providesto_string(),as_str(), andFromStrimplementations so bothfloresta-rpcandfloresta-nodecan use the same method definitions safely. This prevents spelling mismatches and avoids duplicating method names across the codebase.How to verify the changes you have done?
floresta-rpcandfloresta-nodeto confirm the shared RPC traits compile correctly in both sync and async contexts.RpcMethodscan be converted withto_string(),as_str(), andFromStr.walletblockchaincontrolnetworkutilrawtransactionsmaybe-asyncintegration and the crate-by-crate build adjustment.