Compare commits

...

1 Commits

Author SHA1 Message Date
Jonathan Underwood
4bbfc612d5
feat: add-peer
Some checks failed
CI / Test (1.75.0) (push) Has been cancelled
CI / Test (stable) (push) Has been cancelled
CI / Rust fmt (push) Has been cancelled
CI / Rust clippy (push) Has been cancelled
2026-01-30 23:48:43 +09:00
4 changed files with 44 additions and 0 deletions

View File

@ -172,6 +172,13 @@ where
(**self).server_features()
}
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
where
S: serde::Serialize,
{
(**self).server_add_peer(features)
}
fn ping(&self) -> Result<(), Error> {
(**self).ping()
}
@ -398,6 +405,11 @@ pub trait ElectrumApi {
/// Returns the capabilities of the server.
fn server_features(&self) -> Result<ServerFeaturesRes, Error>;
/// Announce a server to get it listed in the peer list.
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
where
S: serde::Serialize;
/// Pings the server. This method can also be used as a "dummy" call to trigger the processing
/// of incoming block header or script notifications.
fn ping(&self) -> Result<(), Error>;
@ -607,6 +619,13 @@ mod test {
unreachable!()
}
fn server_add_peer<S>(&self, _: &S) -> Result<bool, crate::Error>
where
S: serde::Serialize,
{
unreachable!()
}
fn ping(&self) -> Result<(), super::Error> {
unreachable!()
}

View File

@ -367,6 +367,14 @@ impl ElectrumApi for Client {
impl_inner_call!(self, ping)
}
#[inline]
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
where
S: serde::Serialize,
{
impl_inner_call!(self, server_add_peer, features)
}
#[inline]
#[cfg(feature = "debug-calls")]
fn calls_made(&self) -> Result<usize, Error> {

View File

@ -1179,6 +1179,21 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
Ok(serde_json::from_value(result)?)
}
fn server_add_peer<S>(&self, features: &S) -> Result<bool, Error>
where
S: serde::Serialize,
{
let json = serde_json::to_value(features)?;
let req = Request::new_id(
self.last_id.fetch_add(1, Ordering::SeqCst),
"server.add_peer",
vec![Param::Json(json)],
);
let result = self.call(req)?;
Ok(serde_json::from_value(result)?)
}
fn ping(&self) -> Result<(), Error> {
let req = Request::new_id(
self.last_id.fetch_add(1, Ordering::SeqCst),

View File

@ -33,6 +33,8 @@ pub enum Param {
Bool(bool),
/// Bytes array parameter
Bytes(Vec<u8>),
/// JSON parameter
Json(serde_json::Value),
}
#[derive(Serialize, Clone)]