Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniFFI bindings #25

Merged
merged 10 commits into from
May 9, 2023
Prev Previous commit
Next Next commit
Harmonize and reorder error variants
tnull committed May 8, 2023
commit f9c8894dd2081ec2e5a8636ed1601d014c52a8f9
22 changes: 11 additions & 11 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
@@ -66,26 +66,26 @@ enum NodeError {
"NotRunning",
"OnchainTxCreationFailed",
"ConnectionFailed",
"AddressInvalid",
"PublicKeyInvalid",
"PaymentHashInvalid",
"PaymentPreimageInvalid",
"PaymentSecretInvalid",
"NonUniquePaymentHash",
"InvalidAmount",
"InvalidInvoice",
"InvoiceCreationFailed",
"InsufficientFunds",
"PaymentFailed",
"ChannelIdInvalid",
"NetworkInvalid",
"PeerInfoParseFailed",
"ChannelCreationFailed",
"ChannelClosingFailed",
"PersistenceFailed",
"WalletOperationFailed",
"WalletSigningFailed",
"TxSyncFailed",
"InvalidAddress",
"InvalidPublicKey",
"InvalidPaymentHash",
"InvalidPaymentPreimage",
"InvalidPaymentSecret",
"InvalidAmount",
"InvalidInvoice",
"InvalidChannelId",
"InvalidNetwork",
"NonUniquePaymentHash",
"InsufficientFunds",
};

[Enum]
70 changes: 35 additions & 35 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -11,32 +11,10 @@ pub enum Error {
OnchainTxCreationFailed,
/// A network connection has been closed.
ConnectionFailed,
/// The given address is invalid.
AddressInvalid,
/// The given public key is invalid.
PublicKeyInvalid,
/// The given payment hash is invalid.
PaymentHashInvalid,
/// The given payment preimage is invalid.
PaymentPreimageInvalid,
/// The given payment secret is invalid.
PaymentSecretInvalid,
/// Payment of the given invoice has already been intiated.
NonUniquePaymentHash,
/// The given amount is invalid.
InvalidAmount,
/// The given invoice is invalid.
InvalidInvoice,
/// Invoice creation failed.
InvoiceCreationFailed,
/// There are insufficient funds to complete the given operation.
InsufficientFunds,
/// An attempted payment has failed.
PaymentFailed,
/// The given channel ID is invalid.
ChannelIdInvalid,
/// The given network is invalid.
NetworkInvalid,
/// A given peer info could not be parsed.
PeerInfoParseFailed,
/// A channel could not be opened.
@@ -51,6 +29,28 @@ pub enum Error {
WalletSigningFailed,
/// A transaction sync operation failed.
TxSyncFailed,
/// The given address is invalid.
InvalidAddress,
/// The given public key is invalid.
InvalidPublicKey,
/// The given payment hash is invalid.
InvalidPaymentHash,
/// The given payment preimage is invalid.
InvalidPaymentPreimage,
/// The given payment secret is invalid.
InvalidPaymentSecret,
/// The given amount is invalid.
InvalidAmount,
/// The given invoice is invalid.
InvalidInvoice,
/// The given channel ID is invalid.
InvalidChannelId,
/// The given network is invalid.
InvalidNetwork,
/// Payment of the given invoice has already been intiated.
NonUniquePaymentHash,
/// There are insufficient funds to complete the given operation.
InsufficientFunds,
}

impl fmt::Display for Error {
@@ -62,28 +62,28 @@ impl fmt::Display for Error {
write!(f, "On-chain transaction could not be created.")
}
Self::ConnectionFailed => write!(f, "Network connection closed."),
Self::AddressInvalid => write!(f, "The given address is invalid."),
Self::PublicKeyInvalid => write!(f, "The given public key is invalid."),
Self::PaymentHashInvalid => write!(f, "The given payment hash is invalid."),
Self::PaymentPreimageInvalid => write!(f, "The given payment preimage is invalid."),
Self::PaymentSecretInvalid => write!(f, "The given payment secret is invalid."),
Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."),
Self::InvalidAmount => write!(f, "The given amount is invalid."),
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
Self::InvoiceCreationFailed => write!(f, "Failed to create invoice."),
Self::InsufficientFunds => {
write!(f, "There are insufficient funds to complete the given operation.")
}
Self::PaymentFailed => write!(f, "Failed to send the given payment."),
Self::ChannelIdInvalid => write!(f, "The given channel ID is invalid."),
Self::NetworkInvalid => write!(f, "The given network is invalid."),
Self::PeerInfoParseFailed => write!(f, "Failed to parse the given peer information."),
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
Self::PersistenceFailed => write!(f, "Failed to persist data."),
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
Self::WalletSigningFailed => write!(f, "Failed to sign given transaction."),
Self::TxSyncFailed => write!(f, "Failed to sync transactions."),
Self::InvalidAddress => write!(f, "The given address is invalid."),
Self::InvalidPublicKey => write!(f, "The given public key is invalid."),
Self::InvalidPaymentHash => write!(f, "The given payment hash is invalid."),
Self::InvalidPaymentPreimage => write!(f, "The given payment preimage is invalid."),
Self::InvalidPaymentSecret => write!(f, "The given payment secret is invalid."),
Self::InvalidAmount => write!(f, "The given amount is invalid."),
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
Self::InvalidChannelId => write!(f, "The given channel ID is invalid."),
Self::InvalidNetwork => write!(f, "The given network is invalid."),
Self::NonUniquePaymentHash => write!(f, "An invoice must not get payed twice."),
Self::InsufficientFunds => {
write!(f, "There are insufficient funds to complete the given operation.")
}
}
}
}
18 changes: 9 additions & 9 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ impl UniffiCustomTypeConverter for SocketAddr {
return Ok(addr);
}

Err(Error::PublicKeyInvalid.into())
Err(Error::InvalidPublicKey.into())
}

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

Err(Error::PublicKeyInvalid.into())
Err(Error::InvalidPublicKey.into())
}

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

Err(Error::AddressInvalid.into())
Err(Error::InvalidAddress.into())
}

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

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

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

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

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

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

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

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

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