Skip to content

Commit 648c16f

Browse files
TheBlueMatt-macbookMatt Corallo
andauthored
Expose marginally more in bindings (#29)
Co-authored-by: Matt Corallo <git+macbook@bluematt.me>
1 parent 9ce95de commit 648c16f

3 files changed

Lines changed: 23 additions & 10 deletions

File tree

orange-sdk/src/ffi/orange/error.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum InitFailure {
3636
/// Failure to start the LDK node.
3737
LdkNodeStartFailure(String),
3838
/// Failure in the trusted wallet implementation.
39-
TrustedFailure,
39+
TrustedFailure(String),
4040
}
4141

4242
impl Display for InitFailure {
@@ -46,7 +46,7 @@ impl Display for InitFailure {
4646
InitFailure::ConfigError(e) => write!(f, "Config error: {e}"),
4747
InitFailure::LdkNodeBuildFailure(e) => write!(f, "Failed to build the LDK node: {e}"),
4848
InitFailure::LdkNodeStartFailure(e) => write!(f, "Failed to start the LDK node: {e}"),
49-
InitFailure::TrustedFailure => write!(f, "Failed to create the trusted wallet"),
49+
InitFailure::TrustedFailure(e) => write!(f, "Failed to create the trusted wallet: {e}"),
5050
}
5151
}
5252
}
@@ -67,7 +67,7 @@ impl From<OrangeInitFailure> for InitFailure {
6767
OrangeInitFailure::LdkNodeStartFailure(e) => {
6868
InitFailure::LdkNodeStartFailure(e.to_string())
6969
},
70-
OrangeInitFailure::TrustedFailure(_e) => InitFailure::TrustedFailure,
70+
OrangeInitFailure::TrustedFailure(e) => InitFailure::TrustedFailure(e.to_string()),
7171
}
7272
}
7373
}
@@ -84,7 +84,7 @@ pub enum WalletError {
8484
/// Failure in the LDK node.
8585
LdkNodeFailure(String),
8686
/// Failure in the trusted wallet implementation.
87-
TrustedFailure,
87+
TrustedFailure(String),
8888
/// Failure to parse payment instructions.
8989
PaymentInstructionsParseError,
9090
/// Failure to build payment info.
@@ -95,7 +95,7 @@ impl Display for WalletError {
9595
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
9696
match self {
9797
WalletError::LdkNodeFailure(e) => write!(f, "Failure from LDK node: {e}"),
98-
WalletError::TrustedFailure => write!(f, "Failure from trusted wallet"),
98+
WalletError::TrustedFailure(e) => write!(f, "Failure from trusted wallet: {e}"),
9999
WalletError::PaymentInstructionsParseError => {
100100
write!(f, "Failure to parse payment instructions")
101101
},
@@ -108,7 +108,7 @@ impl From<OrangeWalletError> for WalletError {
108108
fn from(e: OrangeWalletError) -> Self {
109109
match e {
110110
OrangeWalletError::LdkNodeFailure(e) => WalletError::LdkNodeFailure(e.to_string()),
111-
OrangeWalletError::TrustedFailure(_e) => WalletError::TrustedFailure,
111+
OrangeWalletError::TrustedFailure(e) => WalletError::TrustedFailure(e.to_string()),
112112
}
113113
}
114114
}

orange-sdk/src/ffi/orange/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::{
55
};
66
use crate::{impl_from_core_type, impl_into_core_type};
77
use std::sync::Arc;
8+
use ldk_node::bitcoin::hex::DisplayHex;
89

910
pub mod config;
1011
pub mod error;
@@ -63,19 +64,27 @@ impl Transaction {
6364
/// the payment to the user.
6465
#[derive(Debug, Clone, Hash, PartialEq, Eq, uniffi::Object)]
6566
pub enum PaymentId {
66-
Lightning(Vec<u8>),
67-
Trusted(Vec<u8>),
67+
Lightning(String),
68+
Trusted(String),
6869
}
6970

7071
impl From<OrangePaymentId> for PaymentId {
7172
fn from(id: OrangePaymentId) -> Self {
7273
match id {
73-
OrangePaymentId::SelfCustodial(hash) => Self::Lightning(hash.to_vec()),
74-
OrangePaymentId::Trusted(hash) => Self::Trusted(hash.to_vec()),
74+
OrangePaymentId::SelfCustodial(hash) => Self::Lightning(hash.to_lower_hex_string()),
75+
OrangePaymentId::Trusted(hash) => Self::Trusted(hash.to_lower_hex_string()),
7576
}
7677
}
7778
}
7879

80+
#[uniffi::export]
81+
impl PaymentId {
82+
/// Gets a string representation of this PaymentId
83+
pub fn to_string(&self) -> String {
84+
format!("{self:?}")
85+
}
86+
}
87+
7988
/// The status of a transaction. This is used to track the state of a transaction
8089
#[derive(Debug, Clone, Copy, PartialEq, Eq, uniffi::Enum)]
8190
pub enum TxStatus {

orange-sdk/src/trusted_wallet/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ pub enum TrustedError {
173173
Other(String),
174174
}
175175

176+
impl core::fmt::Display for TrustedError {
177+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { write!(f, "{self:?}") }
178+
}
179+
176180
impl From<ldk_node::lightning::io::Error> for TrustedError {
177181
fn from(e: ldk_node::lightning::io::Error) -> Self {
178182
TrustedError::IOError(e)

0 commit comments

Comments
 (0)