Skip to content

Commit 478dc2e

Browse files
committed
add a separate battery folder to ldk (xc)framework sources
1 parent 7a5e731 commit 478dc2e

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

bindings/batteries/ChannelManagerConstructor.swift

+23-12
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ enum InvalidSerializedDataError: Error {
1212
}
1313

1414
class ChannelManagerConstructor {
15-
15+
1616
public let channelManager: ChannelManager
1717
/**
1818
* The latest block has the channel manager saw. If this is non-null it is a 32-byte block hash.
1919
* You should sync the blockchain starting with the block that builds on this block.
2020
*/
21-
public let channel_manager_latest_block_hash: [UInt8]
21+
public let channel_manager_latest_block_hash: [UInt8]?
2222
/**
2323
* A list of ChannelMonitors and the last block they each saw. You should sync the blockchain on each individually
2424
* starting with the block that builds on the hash given.
@@ -28,13 +28,12 @@ class ChannelManagerConstructor {
2828
public private(set) var channel_monitors: [(ChannelMonitor, [UInt8])]
2929

3030
private let chain_monitor: ChainMonitor
31-
32-
init(channel_manager_serialized: [UInt8], channel_monitors_serialized: [[UInt8]], keys_interface: KeysInterface, fee_estimator: FeeEstimator, chain_monitor: ChainMonitor, filter: Filter?, tx_broadcaster: BroadcasterInterface, logger: Logger) throws {
33-
31+
32+
public init(channel_manager_serialized: [UInt8], channel_monitors_serialized: [[UInt8]], keys_interface: KeysInterface, fee_estimator: FeeEstimator, chain_monitor: ChainMonitor, filter: Filter?, tx_broadcaster: BroadcasterInterface, logger: Logger) throws {
33+
3434
var monitors: [LDKChannelMonitor] = []
3535
self.channel_monitors = []
36-
for index in 0..<channel_monitors_serialized.count {
37-
let currentSerializedChannelMonitor = channel_monitors_serialized[index]
36+
for currentSerializedChannelMonitor in channel_monitors_serialized {
3837
let res: Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ = UtilMethods.constructor_BlockHashChannelMonitorZ_read(ser: currentSerializedChannelMonitor, arg: keys_interface)
3938
if res.cOpaqueStruct?.result_ok != true {
4039
throw InvalidSerializedDataError.runtimeError
@@ -46,24 +45,36 @@ class ChannelManagerConstructor {
4645
monitors.append(b)
4746
self.channel_monitors.append((currentChannelMonitor, Bindings.LDKThirtyTwoBytes_to_array(nativeType: a)))
4847
}
49-
48+
5049
let res = UtilMethods.constructor_BlockHashChannelManagerZ_read(ser: channel_manager_serialized, arg_keys_manager: keys_interface, arg_fee_estimator: fee_estimator, arg_chain_monitor: chain_monitor.as_Watch(), arg_tx_broadcaster: tx_broadcaster, arg_logger: logger, arg_default_config: UserConfig(), arg_channel_monitors: monitors)
5150
if res.cOpaqueStruct?.result_ok != true {
5251
throw InvalidSerializedDataError.runtimeError
5352
}
5453
let latestBlockHash = Bindings.LDKThirtyTwoBytes_to_array(nativeType: res.cOpaqueStruct!.contents.result.pointee.a)
5554
let channelManager = ChannelManager(pointer: res.cOpaqueStruct!.contents.result.pointee.b)
56-
55+
5756
self.channelManager = channelManager
5857
self.channel_manager_latest_block_hash = latestBlockHash
5958
self.chain_monitor = chain_monitor
60-
59+
6160
if let filter = filter {
6261
for (currentMonitor, _) in self.channel_monitors {
6362
currentMonitor.load_outputs_to_watch(filter: filter)
6463
}
6564
}
66-
65+
6766
}
68-
67+
68+
/*
69+
* Constructs a channel manager from the given interface implementations
70+
*/
71+
public init(network: LDKNetwork, config: UserConfig, current_blockchain_tip_hash: [UInt8], current_blockchain_tip_height: UInt32, keys_interface: KeysInterface, fee_estimator: FeeEstimator, chain_monitor: ChainMonitor, tx_broadcaster: BroadcasterInterface, logger: Logger) {
72+
self.channel_monitors = []
73+
self.channel_manager_latest_block_hash = nil
74+
self.chain_monitor = chain_monitor
75+
let block = BestBlock(block_hash: current_blockchain_tip_hash, height: current_blockchain_tip_height)
76+
let chainParameters = ChainParameters(network_arg: network, best_block_arg: block)
77+
self.channelManager = ChannelManager(fee_est: fee_estimator, chain_monitor: chain_monitor.as_Watch(), tx_broadcaster: tx_broadcaster, logger: logger, keys_manager: keys_interface, config: config, params: chainParameters)
78+
}
79+
6980
}

xcode/LDKFramework/LDKFramework.xcodeproj/project.pbxproj

+21
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@
495495
0734506026445915001CD90E /* lightning.h in Headers */ = {isa = PBXBuildFile; fileRef = 0734505D26445915001CD90E /* lightning.h */; settings = {ATTRIBUTES = (Public, ); }; };
496496
0734506126445915001CD90E /* ldk_ver.h in Headers */ = {isa = PBXBuildFile; fileRef = 0734505E26445915001CD90E /* ldk_ver.h */; settings = {ATTRIBUTES = (Public, ); }; };
497497
0734506226445915001CD90E /* ldk_rust_types.h in Headers */ = {isa = PBXBuildFile; fileRef = 0734505F26445915001CD90E /* ldk_rust_types.h */; settings = {ATTRIBUTES = (Public, ); }; };
498+
0749F9C6265615CC00876C52 /* ChannelManagerConstructor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0749F9C4265615CB00876C52 /* ChannelManagerConstructor.swift */; };
499+
0749F9C7265615CC00876C52 /* ChannelManagerConstructor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0749F9C4265615CB00876C52 /* ChannelManagerConstructor.swift */; };
500+
0749F9C8265615CC00876C52 /* UtilMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0749F9C5265615CB00876C52 /* UtilMethods.swift */; };
501+
0749F9C9265615CC00876C52 /* UtilMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0749F9C5265615CB00876C52 /* UtilMethods.swift */; };
498502
/* End PBXBuildFile section */
499503

500504
/* Begin PBXContainerItemProxy section */
@@ -759,6 +763,8 @@
759763
0734505D26445915001CD90E /* lightning.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lightning.h; sourceTree = SOURCE_ROOT; };
760764
0734505E26445915001CD90E /* ldk_ver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ldk_ver.h; sourceTree = SOURCE_ROOT; };
761765
0734505F26445915001CD90E /* ldk_rust_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ldk_rust_types.h; sourceTree = SOURCE_ROOT; };
766+
0749F9C4265615CB00876C52 /* ChannelManagerConstructor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChannelManagerConstructor.swift; sourceTree = "<group>"; };
767+
0749F9C5265615CB00876C52 /* UtilMethods.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UtilMethods.swift; sourceTree = "<group>"; };
762768
/* End PBXFileReference section */
763769

764770
/* Begin PBXFrameworksBuildPhase section */
@@ -806,6 +812,7 @@
806812
isa = PBXGroup;
807813
children = (
808814
07344FAC26428B09001CD90E /* headers */,
815+
0749F9C3265615CB00876C52 /* batteries */,
809816
07344CD02642882A001CD90E /* LDK */,
810817
07344C57264277ED001CD90E /* LDKFramework.h */,
811818
07344C58264277ED001CD90E /* Info.plist */,
@@ -1129,6 +1136,16 @@
11291136
path = ../../../bindings/headers;
11301137
sourceTree = "<group>";
11311138
};
1139+
0749F9C3265615CB00876C52 /* batteries */ = {
1140+
isa = PBXGroup;
1141+
children = (
1142+
0749F9C4265615CB00876C52 /* ChannelManagerConstructor.swift */,
1143+
0749F9C5265615CB00876C52 /* UtilMethods.swift */,
1144+
);
1145+
name = batteries;
1146+
path = ../../../bindings/batteries;
1147+
sourceTree = "<group>";
1148+
};
11321149
/* End PBXGroup section */
11331150

11341151
/* Begin PBXHeadersBuildPhase section */
@@ -1268,6 +1285,7 @@
12681285
07344E092642882B001CD90E /* C2Tuple_BlockHashChannelManagerZ.swift in Sources */,
12691286
07344E0F2642882B001CD90E /* C2Tuple_PaymentHashPaymentSecretZ.swift in Sources */,
12701287
07344F612642882C001CD90E /* AnnouncementSignatures.swift in Sources */,
1288+
0749F9C6265615CC00876C52 /* ChannelManagerConstructor.swift in Sources */,
12711289
07344DE72642882B001CD90E /* Logger.swift in Sources */,
12721290
07344F8F2642882C001CD90E /* SignedRawInvoice.swift in Sources */,
12731291
07344ED52642882B001CD90E /* Result_NoneChannelMonitorUpdateErrZ.swift in Sources */,
@@ -1460,6 +1478,7 @@
14601478
07344E7B2642882B001CD90E /* Result_NetworkGraphDecodeErrorZ.swift in Sources */,
14611479
07344F712642882C001CD90E /* MinFinalCltvExpiry.swift in Sources */,
14621480
07344E4B2642882B001CD90E /* Result_UnsignedNodeAnnouncementDecodeErrorZ.swift in Sources */,
1481+
0749F9C8265615CC00876C52 /* UtilMethods.swift in Sources */,
14631482
07344F372642882C001CD90E /* PeerHandleError.swift in Sources */,
14641483
07344DF72642882B001CD90E /* ChannelMessageHandler.swift in Sources */,
14651484
07344F772642882C001CD90E /* RouteHop.swift in Sources */,
@@ -1630,7 +1649,9 @@
16301649
07344F342642882C001CD90E /* InMemorySigner.swift in Sources */,
16311650
07344F802642882C001CD90E /* InitFeatures.swift in Sources */,
16321651
07344EB62642882B001CD90E /* Result_ReplyChannelRangeDecodeErrorZ.swift in Sources */,
1652+
0749F9C7265615CC00876C52 /* ChannelManagerConstructor.swift in Sources */,
16331653
07344F082642882C001CD90E /* NetGraphMsgHandler.swift in Sources */,
1654+
0749F9C9265615CC00876C52 /* UtilMethods.swift in Sources */,
16341655
07344EC42642882B001CD90E /* Result_PayeePubKeyErrorZ.swift in Sources */,
16351656
07344F322642882C001CD90E /* HTLCUpdate.swift in Sources */,
16361657
07344F3C2642882C001CD90E /* CommitmentSigned.swift in Sources */,

0 commit comments

Comments
 (0)