forked from RGB-WG/rgb-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
128 lines (107 loc) · 3.88 KB
/
error.rs
File metadata and controls
128 lines (107 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// RGB node providing smart contracts functionality for Bitcoin & Lightning.
//
// Written in 2022 by
// Dr. Maxim Orlovsky <orlovsky@lnp-bp.org>
//
// Copyright (C) 2022 by LNP/BP Standards Association, Switzerland.
//
// You should have received a copy of the MIT License along with this software.
// If not, see <https://opensource.org/licenses/MIT>.
use commit_verify::lnpbp4;
use internet2::presentation;
use microservices::rpc::ServerError;
use microservices::{esb, rpc, LauncherError};
use rgb_rpc::{FailureCode, RpcMsg};
use storm::ContainerId;
use crate::bucketd::{FinalizeError, StashError};
use crate::bus::{ServiceBus, ServiceId};
use crate::rgbd::Daemon;
#[derive(Clone, Debug, Display, Error, From)]
#[display(doc_comments)]
pub enum LaunchError {
/// error setting up ESB controller; can't connect one of message buses
BusSetupFailure,
/// can't connect to store service. Details: {0}
#[from]
StoreConnection(ServerError<store_rpc::FailureCode>),
/// can't connect to electrum server
ElectrumConnectivity,
}
impl microservices::error::Error for LaunchError {}
#[derive(Debug, Display, Error, From)]
#[display(doc_comments)]
pub(crate) enum DaemonError {
/// data encoding error. Details: {0}
#[from]
#[display(inner)]
Encoding(strict_encoding::Error),
/// ESB error: {0}
#[from]
Esb(esb::Error<ServiceId>),
/// invalid storm message encoding. Details: {0}
#[from]
StormEncoding(presentation::Error),
/// launching bucket daemon. Details: {0}
#[from]
BucketLauncher(LauncherError<Daemon>),
/// storage error. Details: {0}
#[from]
Store(ServerError<store_rpc::FailureCode>),
#[display(inner)]
#[from]
#[from(lnpbp4::LeafNotKnown)]
#[from(rgb::bundle::RevealError)]
Stash(StashError),
#[display(inner)]
#[from]
#[from(rgb::psbt::KeyError)]
#[from(bp::dbc::anchor::Error)]
Finalize(FinalizeError),
/// electrum connectivity error. Details: {0}
ElectrumConnectivity(String),
/// the container which was requested to be processed is absent in sthe store
NoContainer(ContainerId),
/// request `{1}` is not supported on {0} message bus
RequestNotSupported(ServiceBus, String),
// /// request `{1}` is not supported on {0} message bus for service {2}
// SourceNotSupported(ServiceBus, String, ServiceId),
}
impl microservices::error::Error for DaemonError {}
impl From<DaemonError> for esb::Error<ServiceId> {
fn from(err: DaemonError) -> Self { esb::Error::ServiceError(err.to_string()) }
}
impl From<DaemonError> for RpcMsg {
fn from(err: DaemonError) -> Self {
let code = match err {
DaemonError::StormEncoding(_) | DaemonError::Encoding(_) => FailureCode::Encoding,
DaemonError::Esb(_) => FailureCode::Esb,
DaemonError::RequestNotSupported(_, _) /* | DaemonError::SourceNotSupported(_, _, _) */ => {
FailureCode::UnexpectedRequest
}
DaemonError::Store(_) => FailureCode::Store,
DaemonError::BucketLauncher(_) => FailureCode::Launcher,
DaemonError::Stash(_) => FailureCode::Stash,
DaemonError::Finalize(_) => FailureCode::Finalize,
DaemonError::ElectrumConnectivity(_) => FailureCode::ElectrumConnectivity,
DaemonError::NoContainer(_) => FailureCode::Store,
};
RpcMsg::Failure(rpc::Failure {
code: code.into(),
info: err.to_string(),
})
}
}
impl DaemonError {
pub(crate) fn wrong_esb_msg(bus: ServiceBus, message: &impl ToString) -> DaemonError {
DaemonError::RequestNotSupported(bus, message.to_string())
}
/*
pub(crate) fn wrong_esb_msg_source(
bus: ServiceBus,
message: &impl ToString,
source: ServiceId,
) -> DaemonError {
DaemonError::SourceNotSupported(bus, message.to_string(), source)
}
*/
}