use std::fmt;
use nostr::event::builder;
use nostr::nips::{nip04, nip44, nip46};
use nostr::PublicKey;
use nostr_relay_pool::pool;
use tokio::sync::SetError;
#[derive(Debug)]
pub enum Error {
Builder(builder::Error),
NIP04(nip04::Error),
NIP44(nip44::Error),
NIP46(nip46::Error),
Pool(pool::Error),
SetUserPublicKey(SetError<PublicKey>),
Response(String),
SignerPublicKeyNotFound,
Timeout,
UnexpectedUri,
PublicKeyNotMatchAppKeys,
UserPublicKeyNotMatch {
expected: Box<PublicKey>,
local: Box<PublicKey>,
},
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Builder(e) => e.fmt(f),
Self::NIP04(e) => e.fmt(f),
Self::NIP44(e) => e.fmt(f),
Self::NIP46(e) => e.fmt(f),
Self::Pool(e) => e.fmt(f),
Self::SetUserPublicKey(e) => e.fmt(f),
Self::Response(e) => e.fmt(f),
Self::SignerPublicKeyNotFound => f.write_str("signer public key not found"),
Self::Timeout => f.write_str("timeout"),
Self::UnexpectedUri => f.write_str("unexpected URI"),
Self::PublicKeyNotMatchAppKeys => f.write_str("public key not match app keys"),
Self::UserPublicKeyNotMatch { expected, local } => write!(
f,
"user public key not match: expected={expected}, local={local}"
),
}
}
}
impl From<builder::Error> for Error {
fn from(e: builder::Error) -> Self {
Self::Builder(e)
}
}
impl From<nip04::Error> for Error {
fn from(e: nip04::Error) -> Self {
Self::NIP04(e)
}
}
impl From<nip44::Error> for Error {
fn from(e: nip44::Error) -> Self {
Self::NIP44(e)
}
}
impl From<nip46::Error> for Error {
fn from(e: nip46::Error) -> Self {
Self::NIP46(e)
}
}
impl From<pool::Error> for Error {
fn from(e: pool::Error) -> Self {
Self::Pool(e)
}
}
impl From<SetError<PublicKey>> for Error {
fn from(e: SetError<PublicKey>) -> Self {
Self::SetUserPublicKey(e)
}
}