Skip to content

Commit c571136

Browse files
committed
Harmonize and reorder error variants
1 parent 1b52437 commit c571136

File tree

3 files changed

+55
-55
lines changed

3 files changed

+55
-55
lines changed

bindings/ldk_node.udl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,26 @@ enum NodeError {
6666
"NotRunning",
6767
"OnchainTxCreationFailed",
6868
"ConnectionFailed",
69-
"AddressInvalid",
70-
"PublicKeyInvalid",
71-
"PaymentHashInvalid",
72-
"PaymentPreimageInvalid",
73-
"PaymentSecretInvalid",
74-
"NonUniquePaymentHash",
75-
"InvalidAmount",
76-
"InvalidInvoice",
7769
"InvoiceCreationFailed",
78-
"InsufficientFunds",
7970
"PaymentFailed",
80-
"ChannelIdInvalid",
81-
"NetworkInvalid",
8271
"PeerInfoParseFailed",
8372
"ChannelCreationFailed",
8473
"ChannelClosingFailed",
8574
"PersistenceFailed",
8675
"WalletOperationFailed",
8776
"WalletSigningFailed",
8877
"TxSyncFailed",
78+
"InvalidAddress",
79+
"InvalidPublicKey",
80+
"InvalidPaymentHash",
81+
"InvalidPaymentPreimage",
82+
"InvalidPaymentSecret",
83+
"InvalidAmount",
84+
"InvalidInvoice",
85+
"InvalidChannelId",
86+
"InvalidNetwork",
87+
"NonUniquePaymentHash",
88+
"InsufficientFunds",
8989
};
9090

9191
[Enum]

src/error.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,10 @@ pub enum Error {
1111
OnchainTxCreationFailed,
1212
/// A network connection has been closed.
1313
ConnectionFailed,
14-
/// The given address is invalid.
15-
AddressInvalid,
16-
/// The given public key is invalid.
17-
PublicKeyInvalid,
18-
/// The given payment hash is invalid.
19-
PaymentHashInvalid,
20-
/// The given payment preimage is invalid.
21-
PaymentPreimageInvalid,
22-
/// The given payment secret is invalid.
23-
PaymentSecretInvalid,
24-
/// Payment of the given invoice has already been intiated.
25-
NonUniquePaymentHash,
26-
/// The given amount is invalid.
27-
InvalidAmount,
28-
/// The given invoice is invalid.
29-
InvalidInvoice,
3014
/// Invoice creation failed.
3115
InvoiceCreationFailed,
32-
/// There are insufficient funds to complete the given operation.
33-
InsufficientFunds,
3416
/// An attempted payment has failed.
3517
PaymentFailed,
36-
/// The given channel ID is invalid.
37-
ChannelIdInvalid,
38-
/// The given network is invalid.
39-
NetworkInvalid,
4018
/// A given peer info could not be parsed.
4119
PeerInfoParseFailed,
4220
/// A channel could not be opened.
@@ -51,6 +29,28 @@ pub enum Error {
5129
WalletSigningFailed,
5230
/// A transaction sync operation failed.
5331
TxSyncFailed,
32+
/// The given address is invalid.
33+
InvalidAddress,
34+
/// The given public key is invalid.
35+
InvalidPublicKey,
36+
/// The given payment hash is invalid.
37+
InvalidPaymentHash,
38+
/// The given payment preimage is invalid.
39+
InvalidPaymentPreimage,
40+
/// The given payment secret is invalid.
41+
InvalidPaymentSecret,
42+
/// The given amount is invalid.
43+
InvalidAmount,
44+
/// The given invoice is invalid.
45+
InvalidInvoice,
46+
/// The given channel ID is invalid.
47+
InvalidChannelId,
48+
/// The given network is invalid.
49+
InvalidNetwork,
50+
/// Payment of the given invoice has already been intiated.
51+
NonUniquePaymentHash,
52+
/// There are insufficient funds to complete the given operation.
53+
InsufficientFunds,
5454
}
5555

5656
impl fmt::Display for Error {
@@ -62,28 +62,28 @@ impl fmt::Display for Error {
6262
write!(f, "On-chain transaction could not be created.")
6363
}
6464
Self::ConnectionFailed => write!(f, "Network connection closed."),
65-
Self::AddressInvalid => write!(f, "The given address is invalid."),
66-
Self::PublicKeyInvalid => write!(f, "The given public key is invalid."),
67-
Self::PaymentHashInvalid => write!(f, "The given payment hash is invalid."),
68-
Self::PaymentPreimageInvalid => write!(f, "The given payment preimage is invalid."),
69-
Self::PaymentSecretInvalid => write!(f, "The given payment secret is invalid."),
70-
Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."),
71-
Self::InvalidAmount => write!(f, "The given amount is invalid."),
72-
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
7365
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
74-
Self::InsufficientFunds => {
75-
write!(f, "There are insufficient funds to complete the given operation.")
76-
}
7766
Self::PaymentFailed => write!(f, "Failed to send the given payment."),
78-
Self::ChannelIdInvalid => write!(f, "The given channel ID is invalid."),
79-
Self::NetworkInvalid => write!(f, "The given network is invalid."),
8067
Self::PeerInfoParseFailed => write!(f, "Failed to parse the given peer information."),
8168
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
8269
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
8370
Self::PersistenceFailed => write!(f, "Failed to persist data."),
8471
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
8572
Self::WalletSigningFailed => write!(f, "Failed to sign given transaction."),
8673
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
74+
Self::InvalidAddress => write!(f, "The given address is invalid."),
75+
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
76+
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),
77+
Self::InvalidPaymentPreimage => write!(f, "The given payment preimage is invalid."),
78+
Self::InvalidPaymentSecret => write!(f, "The given payment secret is invalid."),
79+
Self::InvalidAmount => write!(f, "The given amount is invalid."),
80+
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
81+
Self::InvalidChannelId => write!(f, "The given channel ID is invalid."),
82+
Self::InvalidNetwork => write!(f, "The given network is invalid."),
83+
Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."),
84+
Self::InsufficientFunds => {
85+
write!(f, "There are insufficient funds to complete the given operation.")
86+
}
8787
}
8888
}
8989
}

src/types.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl UniffiCustomTypeConverter for SocketAddr {
8585
return Ok(addr);
8686
}
8787

88-
Err(Error::PublicKeyInvalid.into())
88+
Err(Error::InvalidPublicKey.into())
8989
}
9090

9191
fn from_custom(obj: Self) -> Self::Builtin {
@@ -101,7 +101,7 @@ impl UniffiCustomTypeConverter for PublicKey {
101101
return Ok(key);
102102
}
103103

104-
Err(Error::PublicKeyInvalid.into())
104+
Err(Error::InvalidPublicKey.into())
105105
}
106106

107107
fn from_custom(obj: Self) -> Self::Builtin {
@@ -117,7 +117,7 @@ impl UniffiCustomTypeConverter for Address {
117117
return Ok(addr);
118118
}
119119

120-
Err(Error::AddressInvalid.into())
120+
Err(Error::InvalidAddress.into())
121121
}
122122

123123
fn from_custom(obj: Self) -> Self::Builtin {
@@ -150,7 +150,7 @@ impl UniffiCustomTypeConverter for PaymentHash {
150150
if let Ok(hash) = Sha256::from_str(&val) {
151151
Ok(PaymentHash(hash.into_inner()))
152152
} else {
153-
Err(Error::PaymentHashInvalid.into())
153+
Err(Error::InvalidPaymentHash.into())
154154
}
155155
}
156156

@@ -169,7 +169,7 @@ impl UniffiCustomTypeConverter for PaymentPreimage {
169169
return Ok(PaymentPreimage(bytes));
170170
}
171171
}
172-
Err(Error::PaymentPreimageInvalid.into())
172+
Err(Error::InvalidPaymentPreimage.into())
173173
}
174174

175175
fn from_custom(obj: Self) -> Self::Builtin {
@@ -187,7 +187,7 @@ impl UniffiCustomTypeConverter for PaymentSecret {
187187
return Ok(PaymentSecret(bytes));
188188
}
189189
}
190-
Err(Error::PaymentSecretInvalid.into())
190+
Err(Error::InvalidPaymentSecret.into())
191191
}
192192

193193
fn from_custom(obj: Self) -> Self::Builtin {
@@ -214,7 +214,7 @@ impl UniffiCustomTypeConverter for ChannelId {
214214
return Ok(Self(channel_id));
215215
}
216216
}
217-
Err(Error::ChannelIdInvalid.into())
217+
Err(Error::InvalidChannelId.into())
218218
}
219219

220220
fn from_custom(obj: Self) -> Self::Builtin {
@@ -246,7 +246,7 @@ impl UniffiCustomTypeConverter for UserChannelId {
246246
type Builtin = String;
247247

248248
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
249-
Ok(UserChannelId(u128::from_str(&val).map_err(|_| Error::ChannelIdInvalid)?))
249+
Ok(UserChannelId(u128::from_str(&val).map_err(|_| Error::InvalidChannelId)?))
250250
}
251251

252252
fn from_custom(obj: Self) -> Self::Builtin {
@@ -272,7 +272,7 @@ impl UniffiCustomTypeConverter for Network {
272272
type Builtin = String;
273273

274274
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
275-
Ok(Network::from_str(&val).map_err(|_| Error::NetworkInvalid)?)
275+
Ok(Network::from_str(&val).map_err(|_| Error::InvalidNetwork)?)
276276
}
277277

278278
fn from_custom(obj: Self) -> Self::Builtin {

0 commit comments

Comments
 (0)