Skip to content

Commit d6c4b40

Browse files
committed
Upgrade uniffi dependency to v0.29.5
We here upgrade to `uniffi` v0.29.5. This upgrade requires a few changes and workarounds, in particular `UniffiCustomTypeConverter` are gone and replaced with corresponding macros. We also had to find workarounds for remote enum interface definitions, and discovered that `uniffi` lost the ability to use remote trait interfaces. The latter therefore requires us to add some duplicative code as we added a local copy of `VssHeaderProvider`/`VssHeaderProviderError` and used an adaptor to make it work for the bindings side of the builder.
1 parent 7ad0d63 commit d6c4b40

6 files changed

Lines changed: 296 additions & 218 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ tokio = { version = "1.37", default-features = false, features = [ "rt-multi-thr
7070
esplora-client = { version = "0.12", default-features = false, features = ["tokio", "async-https-rustls"] }
7171
electrum-client = { version = "0.24.0", default-features = false, features = ["proxy", "use-rustls-ring"] }
7272
libc = "0.2"
73-
uniffi = { version = "0.28.3", features = ["build"], optional = true }
73+
uniffi = { version = "0.29.5", features = ["build"], optional = true }
7474
serde = { version = "1.0.210", default-features = false, features = ["std", "derive"] }
7575
serde_json = { version = "1.0.128", default-features = false, features = ["std"] }
7676
log = { version = "0.4.22", default-features = false, features = ["std"]}
7777

78+
async-trait = { version = "0.1", default-features = false }
7879
vss-client = { package = "vss-client-ng", version = "0.5" }
7980
prost = { version = "0.11.6", default-features = false}
8081
#bitcoin-payment-instructions = { version = "0.6" }
@@ -106,7 +107,7 @@ lnd_grpc_rust = { version = "2.10.0", default-features = false }
106107
tokio = { version = "1.37", features = ["fs"] }
107108

108109
[build-dependencies]
109-
uniffi = { version = "0.28.3", features = ["build"], optional = true }
110+
uniffi = { version = "0.29.5", features = ["build"], optional = true }
110111

111112
[profile.release]
112113
panic = "abort"

bindings/ldk_node.udl

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ enum WordCount {
7979
"Words24",
8080
};
8181

82+
[Remote]
8283
enum LogLevel {
8384
"Gossip",
8485
"Trace",
@@ -281,6 +282,7 @@ interface OnchainPayment {
281282
Txid bump_fee_rbf(PaymentId payment_id, FeeRate? fee_rate);
282283
};
283284

285+
[Remote]
284286
interface FeeRate {
285287
[Name=from_sat_per_kwu]
286288
constructor(u64 sat_kwu);
@@ -377,6 +379,7 @@ dictionary NodeStatus {
377379
u64? latest_node_announcement_broadcast_timestamp;
378380
};
379381

382+
[Remote]
380383
dictionary BestBlock {
381384
BlockHash block_hash;
382385
u32 height;
@@ -400,35 +403,21 @@ enum BuildError {
400403
"AsyncPaymentsConfigMismatch",
401404
};
402405

403-
[Trait]
406+
[Trait, WithForeign]
404407
interface VssHeaderProvider {
405408
[Async, Throws=VssHeaderProviderError]
406-
record<string, string> get_headers([ByRef]sequence<u8> request);
409+
record<string, string> get_headers(sequence<u8> request);
407410
};
408411

409412
[Error]
410-
enum VssHeaderProviderError {
411-
"InvalidData",
412-
"RequestError",
413-
"AuthorizationError",
414-
"InternalError",
415-
};
416-
417-
[Enum]
418-
interface Event {
419-
PaymentSuccessful(PaymentId? payment_id, PaymentHash payment_hash, PaymentPreimage? payment_preimage, u64? fee_paid_msat);
420-
PaymentFailed(PaymentId? payment_id, PaymentHash? payment_hash, PaymentFailureReason? reason);
421-
PaymentReceived(PaymentId? payment_id, PaymentHash payment_hash, u64 amount_msat, sequence<CustomTlvRecord> custom_records);
422-
PaymentClaimable(PaymentId payment_id, PaymentHash payment_hash, u64 claimable_amount_msat, u32? claim_deadline, sequence<CustomTlvRecord> custom_records);
423-
PaymentForwarded(ChannelId prev_channel_id, ChannelId next_channel_id, UserChannelId?
424-
prev_user_channel_id, UserChannelId? next_user_channel_id, PublicKey? prev_node_id, PublicKey? next_node_id, u64? total_fee_earned_msat, u64? skimmed_fee_msat, boolean claim_from_onchain_tx, u64? outbound_amount_forwarded_msat);
425-
ChannelPending(ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo);
426-
ChannelReady(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id, OutPoint? funding_txo);
427-
ChannelClosed(ChannelId channel_id, UserChannelId user_channel_id, PublicKey? counterparty_node_id, ClosureReason? reason);
428-
SplicePending(ChannelId channel_id, UserChannelId user_channel_id, PublicKey counterparty_node_id, OutPoint new_funding_txo);
429-
SpliceFailed(ChannelId channel_id, UserChannelId user_channel_id, PublicKey counterparty_node_id, OutPoint? abandoned_funding_txo);
413+
interface VssHeaderProviderError {
414+
InvalidData(string error);
415+
RequestError(string error);
416+
AuthorizationError(string error);
417+
InternalError(string error);
430418
};
431419

420+
[Remote]
432421
enum PaymentFailureReason {
433422
"RecipientRejected",
434423
"UserAbandoned",
@@ -442,25 +431,6 @@ enum PaymentFailureReason {
442431
"BlindedPathCreationFailed",
443432
};
444433

445-
[Enum]
446-
interface ClosureReason {
447-
CounterpartyForceClosed(UntrustedString peer_msg);
448-
HolderForceClosed(boolean? broadcasted_latest_txn, string message);
449-
LegacyCooperativeClosure();
450-
CounterpartyInitiatedCooperativeClosure();
451-
LocallyInitiatedCooperativeClosure();
452-
CommitmentTxConfirmed();
453-
FundingTimedOut();
454-
ProcessingError(string err);
455-
DisconnectedPeer();
456-
OutdatedChannelManager();
457-
CounterpartyCoopClosedUnfundedChannel();
458-
LocallyCoopClosedUnfundedChannel();
459-
FundingBatchClosure();
460-
HTLCsTimedOut( PaymentHash? payment_hash );
461-
PeerFeerateTooLow(u32 peer_feerate_sat_per_kw, u32 required_feerate_sat_per_kw);
462-
};
463-
464434
[Enum]
465435
interface PaymentKind {
466436
Onchain(Txid txid, ConfirmationStatus status);
@@ -510,6 +480,7 @@ dictionary PaymentDetails {
510480
u64 latest_update_timestamp;
511481
};
512482

483+
[Remote]
513484
dictionary RouteParametersConfig {
514485
u64? max_total_routing_fee_msat;
515486
u32 max_total_cltv_expiry_delta;
@@ -522,13 +493,15 @@ dictionary CustomTlvRecord {
522493
sequence<u8> value;
523494
};
524495

496+
[Remote]
525497
dictionary LSPS1OrderStatus {
526498
LSPS1OrderId order_id;
527499
LSPS1OrderParams order_params;
528500
LSPS1PaymentInfo payment_options;
529501
LSPS1ChannelInfo? channel_state;
530502
};
531503

504+
[Remote]
532505
dictionary LSPS1OrderParams {
533506
u64 lsp_balance_sat;
534507
u64 client_balance_sat;
@@ -563,26 +536,29 @@ dictionary LSPS1OnchainPaymentInfo {
563536
Address? refund_onchain_address;
564537
};
565538

539+
[Remote]
566540
dictionary LSPS1ChannelInfo {
567541
LSPSDateTime funded_at;
568542
OutPoint funding_outpoint;
569543
LSPSDateTime expires_at;
570544
};
571545

546+
[Remote]
572547
enum LSPS1PaymentState {
573548
"ExpectPayment",
574549
"Paid",
575550
"Refunded",
576551
};
577552

578-
[NonExhaustive]
553+
[Remote, NonExhaustive]
579554
enum Network {
580555
"Bitcoin",
581556
"Testnet",
582557
"Signet",
583558
"Regtest",
584559
};
585560

561+
[Remote]
586562
dictionary OutPoint {
587563
Txid txid;
588564
u32 vout;
@@ -679,6 +655,7 @@ interface LightningBalance {
679655
);
680656
};
681657

658+
[Remote]
682659
enum BalanceSource {
683660
"HolderForceClosed",
684661
"CounterpartyForceClosed",
@@ -741,6 +718,7 @@ dictionary ChannelUpdateInfo {
741718
RoutingFees fees;
742719
};
743720

721+
[Remote]
744722
dictionary RoutingFees {
745723
u32 base_msat;
746724
u32 proportional_millionths;
@@ -757,6 +735,7 @@ dictionary NodeAnnouncementInfo {
757735
sequence<SocketAddress> addresses;
758736
};
759737

738+
[Remote]
760739
enum Currency {
761740
"Bitcoin",
762741
"BitcoinTestnet",
@@ -929,3 +908,6 @@ typedef string LSPSDateTime;
929908

930909
[Custom]
931910
typedef string ScriptBuf;
911+
912+
typedef interface ClosureReason;
913+
typedef enum Event;

bindings/uniffi-bindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
uniffi = { version = "0.28.3", features = ["cli"] }
9+
uniffi = { version = "0.29.5", features = ["cli"] }

src/builder.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,17 +1026,13 @@ impl ArcedNodeBuilder {
10261026
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
10271027
pub fn build_with_vss_store_and_header_provider(
10281028
&self, node_entropy: Arc<NodeEntropy>, vss_url: String, store_id: String,
1029-
header_provider: Arc<dyn VssHeaderProvider>,
1029+
header_provider: Arc<dyn crate::ffi::VssHeaderProvider>,
10301030
) -> Result<Arc<Node>, BuildError> {
1031+
let adapter = Arc::new(crate::ffi::VssHeaderProviderAdapter::new(header_provider));
10311032
self.inner
10321033
.read()
10331034
.unwrap()
1034-
.build_with_vss_store_and_header_provider(
1035-
*node_entropy,
1036-
vss_url,
1037-
store_id,
1038-
header_provider,
1039-
)
1035+
.build_with_vss_store_and_header_provider(*node_entropy, vss_url, store_id, adapter)
10401036
.map(Arc::new)
10411037
}
10421038

src/event.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use crate::{
6060
///
6161
/// [`Node`]: [`crate::Node`]
6262
#[derive(Debug, Clone, PartialEq, Eq)]
63+
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
6364
pub enum Event {
6465
/// A sent payment was successful.
6566
PaymentSuccessful {

0 commit comments

Comments
 (0)