plugins: lsps: add router compatible lsps2 service handler
This commit copys and adapts the lsps2 service handlers to match the slim router handlers Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
This commit is contained in:
committed by
madelinevibes
parent
ffc05ddcf0
commit
461065aff7
1545
plugins/lsps-plugin/src/core/lsps2/handler.rs
Normal file
1545
plugins/lsps-plugin/src/core/lsps2/handler.rs
Normal file
File diff suppressed because it is too large
Load Diff
2
plugins/lsps-plugin/src/core/lsps2/mod.rs
Normal file
2
plugins/lsps-plugin/src/core/lsps2/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod handler;
|
||||
pub mod service;
|
||||
39
plugins/lsps-plugin/src/core/lsps2/service.rs
Normal file
39
plugins/lsps-plugin/src/core/lsps2/service.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use crate::{
|
||||
core::{router::JsonRpcRouterBuilder, server::LspsProtocol},
|
||||
proto::{
|
||||
jsonrpc::RpcError,
|
||||
lsps2::{Lsps2BuyRequest, Lsps2BuyResponse, Lsps2GetInfoRequest, Lsps2GetInfoResponse},
|
||||
},
|
||||
register_handler,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use bitcoin::secp256k1::PublicKey;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[async_trait]
|
||||
pub trait Lsps2Handler: Send + Sync + 'static {
|
||||
async fn handle_get_info(
|
||||
&self,
|
||||
request: Lsps2GetInfoRequest,
|
||||
) -> std::result::Result<Lsps2GetInfoResponse, RpcError>;
|
||||
|
||||
async fn handle_buy(
|
||||
&self,
|
||||
peer_id: PublicKey,
|
||||
request: Lsps2BuyRequest,
|
||||
) -> Result<Lsps2BuyResponse, RpcError>;
|
||||
}
|
||||
|
||||
impl<H> LspsProtocol for Arc<H>
|
||||
where
|
||||
H: Lsps2Handler + Send + Sync + 'static,
|
||||
{
|
||||
fn register_handler(&self, router: &mut JsonRpcRouterBuilder) {
|
||||
register_handler!(router, self, "lsps2.get_info", handle_get_info);
|
||||
register_handler!(router, self, "lsps2.buy", handle_buy, with_peer);
|
||||
}
|
||||
|
||||
fn protocol(&self) -> u8 {
|
||||
2
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod client;
|
||||
pub mod lsps2;
|
||||
pub mod router;
|
||||
pub mod server;
|
||||
pub mod transport;
|
||||
|
||||
Reference in New Issue
Block a user