out_java_trait.write("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); } super.finalize();\n")
out_java_trait.write("\t}\n\n")
- java_trait_constr = "\tpublic " + struct_name.replace("LDK", "") + "(" + struct_name.replace("LDK", "") + "Interface arg"
+ java_trait_constr = "\tprivate static class " + struct_name + "Holder { " + struct_name.replace("LDK", "") + " held; }\n"
+ java_trait_constr = java_trait_constr + "\tpublic static " + struct_name.replace("LDK", "") + " new_impl(" + struct_name.replace("LDK", "") + "Interface arg"
for idx, var_line in enumerate(field_var_lines):
if var_line.group(1) in trait_structs:
# Ideally we'd be able to take any instance of the interface, but our C code can only represent
# Java-implemented version, so we require users pass a Java implementation here :/
- java_trait_constr = java_trait_constr + ", " + var_line.group(1).replace("LDK", "") + "." + var_line.group(1).replace("LDK", "") + "Interface " + var_line.group(2)
+ java_trait_constr = java_trait_constr + ", " + var_line.group(1).replace("LDK", "") + "." + var_line.group(1).replace("LDK", "") + "Interface " + var_line.group(2) + "_impl"
else:
java_trait_constr = java_trait_constr + ", " + field_var_convs[idx].java_hu_ty + " " + var_line.group(2)
- java_trait_constr = java_trait_constr + ") {\n\t\tthis(new bindings." + struct_name + "() {\n"
+ java_trait_constr = java_trait_constr + ") {\n\t\tfinal " + struct_name + "Holder impl_holder = new " + struct_name + "Holder();\n"
+ java_trait_constr = java_trait_constr + "\t\timpl_holder.held = new " + struct_name.replace("LDK", "") + "(new bindings." + struct_name + "() {\n"
out_java_trait.write("\tpublic static interface " + struct_name.replace("LDK", "") + "Interface {\n")
out_java.write("\tpublic interface " + struct_name + " {\n")
java_meths = []
if ret_ty_info.from_hu_conv is not None:
java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.java_ty + " result = " + ret_ty_info.from_hu_conv[0] + ";\n"
if ret_ty_info.from_hu_conv[1] != "":
- java_trait_constr = java_trait_constr + "\t\t\t\t//TODO: May need to call: " + ret_ty_info.from_hu_conv[1] + ";\n"
+ java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.from_hu_conv[1].replace("this", "impl_holder.held") + ";\n"
if is_common_base_ext(ret_ty_info.rust_obj):
java_trait_constr = java_trait_constr + "\t\t\t\tret.ptr = 0;\n"
java_trait_constr = java_trait_constr + "\t\t\t\treturn result;\n"
java_trait_constr = java_trait_constr + "\t\t}"
for var_line in field_var_lines:
if var_line.group(1) in trait_structs:
- java_trait_constr = java_trait_constr + ", new " + var_line.group(2) + "(" + var_line.group(2) + ").bindings_instance"
+ java_trait_constr = java_trait_constr + ", " + var_line.group(2) + ".new_impl(" + var_line.group(2) + "_impl).bindings_instance"
else:
java_trait_constr = java_trait_constr + ", " + var_line.group(2)
out_java_trait.write("\t}\n")
- out_java_trait.write(java_trait_constr + ");\n\t}\n")
+ out_java_trait.write(java_trait_constr + ");\n\t\treturn impl_holder.held;\n\t}\n")
# Write out a clone function whether we need one or not, as we use them in moving to rust
write_c("static void* " + struct_name + "_JCalls_clone(const void* this_arg) {\n")
public static interface AccessInterface {
Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id);
}
- public Access(AccessInterface arg) {
- this(new bindings.LDKAccess() {
+ private static class LDKAccessHolder { Access held; }
+ public static Access new_impl(AccessInterface arg) {
+ final LDKAccessHolder impl_holder = new LDKAccessHolder();
+ impl_holder.held = new Access(new bindings.LDKAccess() {
@Override public long get_utxo(byte[] genesis_hash, long short_channel_id) {
Result_TxOutAccessErrorZ ret = arg.get_utxo(genesis_hash, short_channel_id);
long result = ret != null ? ret.ptr : 0;
return result;
}
});
+ return impl_holder.held;
}
public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) {
long ret = bindings.Access_get_utxo(this.ptr, genesis_hash, short_channel_id);
public static interface BroadcasterInterfaceInterface {
void broadcast_transaction(Transaction tx);
}
- public BroadcasterInterface(BroadcasterInterfaceInterface arg) {
- this(new bindings.LDKBroadcasterInterface() {
+ private static class LDKBroadcasterInterfaceHolder { BroadcasterInterface held; }
+ public static BroadcasterInterface new_impl(BroadcasterInterfaceInterface arg) {
+ final LDKBroadcasterInterfaceHolder impl_holder = new LDKBroadcasterInterfaceHolder();
+ impl_holder.held = new BroadcasterInterface(new bindings.LDKBroadcasterInterface() {
@Override public void broadcast_transaction(long tx) {
Transaction tx_conv = new Transaction(null, tx);
arg.broadcast_transaction(tx_conv);
}
});
+ return impl_holder.held;
}
public void broadcast_transaction(Transaction tx) {
bindings.BroadcasterInterface_broadcast_transaction(this.ptr, tx.ptr);
Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg);
void on_accept(ChannelPublicKeys channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay);
}
- public ChannelKeys(ChannelKeysInterface arg, ChannelPublicKeys pubkeys) {
- this(new bindings.LDKChannelKeys() {
+ private static class LDKChannelKeysHolder { ChannelKeys held; }
+ public static ChannelKeys new_impl(ChannelKeysInterface arg, ChannelPublicKeys pubkeys) {
+ final LDKChannelKeysHolder impl_holder = new LDKChannelKeysHolder();
+ impl_holder.held = new ChannelKeys(new bindings.LDKChannelKeys() {
@Override public byte[] get_per_commitment_point(long idx) {
byte[] ret = arg.get_per_commitment_point(idx);
return ret;
arg.on_accept(channel_points_hu_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
}
}, pubkeys);
+ return impl_holder.held;
}
public byte[] get_per_commitment_point(long idx) {
byte[] ret = bindings.ChannelKeys_get_per_commitment_point(this.ptr, idx);
void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg);
void handle_error(byte[] their_node_id, ErrorMessage msg);
}
- public ChannelMessageHandler(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider) {
- this(new bindings.LDKChannelMessageHandler() {
+ private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; }
+ public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) {
+ final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder();
+ impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() {
@Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) {
InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
OpenChannel msg_hu_conv = new OpenChannel(null, msg);
ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
arg.handle_error(their_node_id, msg_hu_conv);
}
- }, new MessageSendEventsProvider(MessageSendEventsProvider).bindings_instance);
+ }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
+ return impl_holder.held;
}
// Skipped ChannelMessageHandler_handle_open_channel
// Skipped ChannelMessageHandler_handle_accept_channel
public static interface EventsProviderInterface {
Event[] get_and_clear_pending_events();
}
- public EventsProvider(EventsProviderInterface arg) {
- this(new bindings.LDKEventsProvider() {
+ private static class LDKEventsProviderHolder { EventsProvider held; }
+ public static EventsProvider new_impl(EventsProviderInterface arg) {
+ final LDKEventsProviderHolder impl_holder = new LDKEventsProviderHolder();
+ impl_holder.held = new EventsProvider(new bindings.LDKEventsProvider() {
@Override public long[] get_and_clear_pending_events() {
Event[] ret = arg.get_and_clear_pending_events();
long[] result = Arrays.stream(ret).mapToLong(arr_conv_7 -> arr_conv_7.ptr).toArray();
- //TODO: May need to call: /* TODO 2 Event */;
+ /* TODO 2 Event */;
return result;
}
});
+ return impl_holder.held;
}
public Event[] get_and_clear_pending_events() {
long[] ret = bindings.EventsProvider_get_and_clear_pending_events(this.ptr);
public static interface FeeEstimatorInterface {
int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target);
}
- public FeeEstimator(FeeEstimatorInterface arg) {
- this(new bindings.LDKFeeEstimator() {
+ private static class LDKFeeEstimatorHolder { FeeEstimator held; }
+ public static FeeEstimator new_impl(FeeEstimatorInterface arg) {
+ final LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder();
+ impl_holder.held = new FeeEstimator(new bindings.LDKFeeEstimator() {
@Override public int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target) {
int ret = arg.get_est_sat_per_1000_weight(confirmation_target);
return ret;
}
});
+ return impl_holder.held;
}
public int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target) {
int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target);
void register_tx(byte[] txid, byte[] script_pubkey);
void register_output(OutPoint outpoint, byte[] script_pubkey);
}
- public Filter(FilterInterface arg) {
- this(new bindings.LDKFilter() {
+ private static class LDKFilterHolder { Filter held; }
+ public static Filter new_impl(FilterInterface arg) {
+ final LDKFilterHolder impl_holder = new LDKFilterHolder();
+ impl_holder.held = new Filter(new bindings.LDKFilter() {
@Override public void register_tx(byte[] txid, byte[] script_pubkey) {
arg.register_tx(txid, script_pubkey);
}
arg.register_output(outpoint_hu_conv, script_pubkey);
}
});
+ return impl_holder.held;
}
public void register_tx(byte[] txid, byte[] script_pubkey) {
bindings.Filter_register_tx(this.ptr, txid, script_pubkey);
ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis);
byte[] get_secure_random_bytes();
}
- public KeysInterface(KeysInterfaceInterface arg) {
- this(new bindings.LDKKeysInterface() {
+ private static class LDKKeysInterfaceHolder { KeysInterface held; }
+ public static KeysInterface new_impl(KeysInterfaceInterface arg) {
+ final LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
+ impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() {
@Override public byte[] get_node_secret() {
byte[] ret = arg.get_node_secret();
return ret;
@Override public long get_channel_keys(boolean inbound, long channel_value_satoshis) {
ChannelKeys ret = arg.get_channel_keys(inbound, channel_value_satoshis);
long result = ret == null ? 0 : ret.ptr;
- //TODO: May need to call: this.ptrs_to.add(ret);
+ impl_holder.held.ptrs_to.add(ret);
ret.ptr = 0;
return result;
}
return ret;
}
});
+ return impl_holder.held;
}
public byte[] get_node_secret() {
byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr);
public static interface LoggerInterface {
void log(String record);
}
- public Logger(LoggerInterface arg) {
- this(new bindings.LDKLogger() {
+ private static class LDKLoggerHolder { Logger held; }
+ public static Logger new_impl(LoggerInterface arg) {
+ final LDKLoggerHolder impl_holder = new LDKLoggerHolder();
+ impl_holder.held = new Logger(new bindings.LDKLogger() {
@Override public void log(String record) {
arg.log(record);
}
});
+ return impl_holder.held;
}
}
public static interface MessageSendEventsProviderInterface {
MessageSendEvent[] get_and_clear_pending_msg_events();
}
- public MessageSendEventsProvider(MessageSendEventsProviderInterface arg) {
- this(new bindings.LDKMessageSendEventsProvider() {
+ private static class LDKMessageSendEventsProviderHolder { MessageSendEventsProvider held; }
+ public static MessageSendEventsProvider new_impl(MessageSendEventsProviderInterface arg) {
+ final LDKMessageSendEventsProviderHolder impl_holder = new LDKMessageSendEventsProviderHolder();
+ impl_holder.held = new MessageSendEventsProvider(new bindings.LDKMessageSendEventsProvider() {
@Override public long[] get_and_clear_pending_msg_events() {
MessageSendEvent[] ret = arg.get_and_clear_pending_msg_events();
long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18.ptr).toArray();
- //TODO: May need to call: /* TODO 2 MessageSendEvent */;
+ /* TODO 2 MessageSendEvent */;
return result;
}
});
+ return impl_holder.held;
}
public MessageSendEvent[] get_and_clear_pending_msg_events() {
long[] ret = bindings.MessageSendEventsProvider_get_and_clear_pending_msg_events(this.ptr);
if (ptr != 0) { bindings.PreCalculatedTxCreationKeys_free(ptr); }
}
+ public static PreCalculatedTxCreationKeys constructor_clone(PreCalculatedTxCreationKeys orig) {
+ long ret = bindings.PreCalculatedTxCreationKeys_clone(orig == null ? 0 : orig.ptr & ~1);
+ PreCalculatedTxCreationKeys ret_hu_conv = new PreCalculatedTxCreationKeys(null, ret);
+ ret_hu_conv.ptrs_to.add(orig);
+ return ret_hu_conv;
+ }
+
public static PreCalculatedTxCreationKeys constructor_new(TxCreationKeys keys) {
long ret = bindings.PreCalculatedTxCreationKeys_new(keys == null ? 0 : keys.ptr & ~1);
PreCalculatedTxCreationKeys ret_hu_conv = new PreCalculatedTxCreationKeys(null, ret);
NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount);
boolean should_request_full_sync(byte[] node_id);
}
- public RoutingMessageHandler(RoutingMessageHandlerInterface arg) {
- this(new bindings.LDKRoutingMessageHandler() {
+ private static class LDKRoutingMessageHandlerHolder { RoutingMessageHandler held; }
+ public static RoutingMessageHandler new_impl(RoutingMessageHandlerInterface arg) {
+ final LDKRoutingMessageHandlerHolder impl_holder = new LDKRoutingMessageHandlerHolder();
+ impl_holder.held = new RoutingMessageHandler(new bindings.LDKRoutingMessageHandler() {
@Override public long handle_node_announcement(long msg) {
NodeAnnouncement msg_hu_conv = new NodeAnnouncement(null, msg);
Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv);
@Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) {
ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] ret = arg.get_next_channel_announcements(starting_point, batch_amount);
long[] result = Arrays.stream(ret).mapToLong(arr_conv_63 -> bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(arr_conv_63.a == null ? 0 : arr_conv_63.a.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_a)*/, arr_conv_63.b == null ? 0 : arr_conv_63.b.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_b)*/, arr_conv_63.c == null ? 0 : arr_conv_63.c.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_c)*/)).toArray();
- //TODO: May need to call: /* TODO 2 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> */;
+ /* TODO 2 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> */;
return result;
}
@Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) {
NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount);
long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18 == null ? 0 : arr_conv_18.ptr & ~1).toArray();
- //TODO: May need to call: /* TODO 2 NodeAnnouncement */;
+ /* TODO 2 NodeAnnouncement */;
return result;
}
@Override public boolean should_request_full_sync(byte[] node_id) {
return ret;
}
});
+ return impl_holder.held;
}
public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) {
long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
boolean eq(long other_arg);
long hash();
}
- public SocketDescriptor(SocketDescriptorInterface arg) {
- this(new bindings.LDKSocketDescriptor() {
+ private static class LDKSocketDescriptorHolder { SocketDescriptor held; }
+ public static SocketDescriptor new_impl(SocketDescriptorInterface arg) {
+ final LDKSocketDescriptorHolder impl_holder = new LDKSocketDescriptorHolder();
+ impl_holder.held = new SocketDescriptor(new bindings.LDKSocketDescriptor() {
@Override public long send_data(byte[] data, boolean resume_read) {
long ret = arg.send_data(data, resume_read);
return ret;
return ret;
}
});
+ return impl_holder.held;
}
public long send_data(byte[] data, boolean resume_read) {
long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read);
Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update);
MonitorEvent[] release_pending_monitor_events();
}
- public Watch(WatchInterface arg) {
- this(new bindings.LDKWatch() {
+ private static class LDKWatchHolder { Watch held; }
+ public static Watch new_impl(WatchInterface arg) {
+ final LDKWatchHolder impl_holder = new LDKWatchHolder();
+ impl_holder.held = new Watch(new bindings.LDKWatch() {
@Override public long watch_channel(long funding_txo, long monitor) {
OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo);
ChannelMonitor monitor_hu_conv = new ChannelMonitor(null, monitor);
@Override public long[] release_pending_monitor_events() {
MonitorEvent[] ret = arg.release_pending_monitor_events();
long[] result = Arrays.stream(ret).mapToLong(arr_conv_14 -> arr_conv_14 == null ? 0 : arr_conv_14.ptr & ~1).toArray();
- //TODO: May need to call: /* TODO 2 MonitorEvent */;
+ /* TODO 2 MonitorEvent */;
return result;
}
});
+ return impl_holder.held;
}
// Skipped Watch_watch_channel
public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) {