Skip to content

Commit 3b7cb61

Browse files
committed
Update HumanObjectPeerTest to use new constructor
1 parent 51b9993 commit 3b7cb61

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

src/test/java/org/ldk/HumanObjectPeerTest.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bitcoinj.core.Transaction;
55
import org.bitcoinj.script.Script;
66
import org.junit.jupiter.api.Test;
7+
import org.ldk.batteries.ChannelManagerConstructor;
78
import org.ldk.batteries.NioPeerHandler;
89
import org.ldk.enums.LDKNetwork;
910
import org.ldk.impl.bindings;
@@ -13,6 +14,7 @@
1314
import java.io.IOException;
1415
import java.lang.ref.WeakReference;
1516
import java.net.InetSocketAddress;
17+
import java.util.ArrayList;
1618
import java.util.Arrays;
1719
import java.util.HashMap;
1820
import java.util.LinkedList;
@@ -264,28 +266,39 @@ private void bind_nio() {
264266
Object ptr_to;
265267
Peer(Peer orig) {
266268
this(null, orig.seed);
267-
ChannelMonitor[] monitors = new ChannelMonitor[1];
268-
synchronized (monitors) {
269-
assert orig.monitors.size() == 1;
270-
monitors[0] = orig.monitors.values().stream().iterator().next();
271-
if (break_cross_peer_refs) {
272-
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = UtilMethods.constructor_BlockHashChannelMonitorZ_read(monitors[0].write(), keys_interface);
273-
assert res instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK;
274-
monitors[0] = ((Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK) res).res.b;
269+
if (!break_cross_peer_refs) {
270+
ChannelMonitor[] monitors = new ChannelMonitor[1];
271+
synchronized (monitors) {
272+
assert orig.monitors.size() == 1;
273+
monitors[0] = orig.monitors.values().stream().iterator().next();
274+
}
275+
byte[] serialized = orig.chan_manager.write();
276+
Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res =
277+
UtilMethods.constructor_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.constructor_default(), monitors);
278+
assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK;
279+
this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b;
280+
this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]);
281+
} else {
282+
final ArrayList<byte[]> channel_monitors = new ArrayList();
283+
synchronized (monitors) {
284+
assert orig.monitors.size() == 1;
285+
channel_monitors.add(orig.monitors.values().stream().iterator().next().write());
286+
}
287+
byte[] serialized = orig.chan_manager.write();
288+
try {
289+
ChannelManagerConstructor constructed = new ChannelManagerConstructor(serialized, channel_monitors.toArray(new byte[1][]), this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger);
290+
this.chan_manager = constructed.channel_manager;
291+
constructed.chain_sync_completed();
292+
} catch (ChannelManagerConstructor.InvalidSerializedDataException e) {
293+
assert false;
275294
}
276295
}
277-
byte[] serialized = orig.chan_manager.write();
278-
Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ read_res =
279-
UtilMethods.constructor_BlockHashChannelManagerZ_read(serialized, this.keys_interface, this.fee_estimator, this.chain_watch, this.tx_broadcaster, this.logger, UserConfig.constructor_default(), monitors);
280296
if (!break_cross_peer_refs && (use_manual_watch || use_km_wrapper)) {
281297
// When we pass monitors[0] into chain_watch.watch_channel we create a reference from the new Peer to a
282298
// field in the old peer, preventing freeing of the original Peer until the new Peer is freed. Thus, we
283299
// shouldn't bother waiting for the original to be freed later on.
284300
cross_reload_ref_pollution = true;
285301
}
286-
this.chain_watch.watch_channel(monitors[0].get_funding_txo().a, monitors[0]);
287-
assert read_res instanceof Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK;
288-
this.chan_manager = ((Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK) read_res).res.b;
289302
this.node_id = chan_manager.get_our_node_id();
290303
this.chan_manager_events = chan_manager.as_EventsProvider();
291304

0 commit comments

Comments
 (0)