-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #943 from carver/refactor-history-content-proxy
refactor: reuse logic to fetch history content
- Loading branch information
Showing
3 changed files
with
49 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// Fetch data from related Portal networks | ||
use serde_json::Value; | ||
use tokio::sync::mpsc; | ||
|
||
use ethportal_api::types::jsonrpc::endpoints::HistoryEndpoint; | ||
use ethportal_api::types::jsonrpc::request::HistoryJsonRpcRequest; | ||
|
||
use crate::errors::RpcServeError; | ||
|
||
pub async fn proxy_query_to_history_subnet( | ||
network: &mpsc::UnboundedSender<HistoryJsonRpcRequest>, | ||
endpoint: HistoryEndpoint, | ||
) -> Result<Value, RpcServeError> { | ||
let (resp_tx, mut resp_rx) = mpsc::unbounded_channel::<Result<Value, String>>(); | ||
let message = HistoryJsonRpcRequest { | ||
endpoint, | ||
resp: resp_tx, | ||
}; | ||
let _ = network.send(message); | ||
|
||
match resp_rx.recv().await { | ||
Some(val) => match val { | ||
Ok(result) => Ok(result), | ||
Err(msg) => Err(RpcServeError::Message(msg)), | ||
}, | ||
None => Err(RpcServeError::Message( | ||
"Internal error: No response from chain history subnetwork".to_string(), | ||
)), | ||
} | ||
} |
This file contains 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
This file contains 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