Skip to content

Commit

Permalink
add submit txn rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
daltoncoder committed Jul 14, 2023
1 parent ea30248 commit 286f03e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions core/rpc/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use axum::{Extension, Json};
use draco_interfaces::{
types::{CommodityServed, EpochInfo, NodeInfo, ProtocolParams, TotalServed},
types::{CommodityServed, EpochInfo, NodeInfo, ProtocolParams, TotalServed, UpdateRequest},
SyncQueryRunnerInterface,
};
use fleek_crypto::{EthAddress, NodePublicKey};
Expand Down Expand Up @@ -73,7 +73,8 @@ impl RpcServer {
)
.with_method("flk_is_valid_node", is_valid_node_handler::<Q>)
.with_method("flk_get_node_registry", get_node_registry_handler::<Q>)
.with_method("flk_get_reputation", get_reputation_handler::<Q>);
.with_method("flk_get_reputation", get_reputation_handler::<Q>)
.with_method("flk_send_txn", send_txn::<Q>);

RpcServer(server.finish())
}
Expand Down Expand Up @@ -224,3 +225,14 @@ pub async fn get_node_registry_handler<Q: SyncQueryRunnerInterface>(
) -> Result<Vec<NodeInfo>> {
Ok(data.0.query_runner.get_node_registry())
}

pub async fn send_txn<Q: SyncQueryRunnerInterface>(
data: Data<Arc<RpcData<Q>>>,
Params(param): Params<UpdateRequest>,
) -> Result<()> {
data.0
.mempool_socket
.run(param)
.await
.map_err(Error::internal)
}
4 changes: 2 additions & 2 deletions core/rpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Rpc<Q: SyncQueryRunnerInterface> {

pub struct RpcData<Q: SyncQueryRunnerInterface> {
pub query_runner: Q,
pub _mempool_address: MempoolSocket,
pub mempool_socket: MempoolSocket,
}

impl<Q: SyncQueryRunnerInterface> Rpc<Q> {
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<Q: SyncQueryRunnerInterface + Send + Sync + 'static> RpcInterface<Q> for Rp
) -> anyhow::Result<Self> {
Ok(Self {
data: Arc::new(RpcData {
_mempool_address: mempool,
mempool_socket: mempool,
query_runner,
}),
config,
Expand Down

0 comments on commit 286f03e

Please sign in to comment.