X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FUtilMethods.java;h=7c53034ab6b3f49978075c0c580af1c7be17b7cf;hp=ef8ba8012d2bfceabdfc97011a5b6fa6278e4300;hb=ff3dacec3be60f870d81f6df11bd9fff92aa6047;hpb=1ef2dc8b8a3e0e244ad82ac08e286df489eca4b7 diff --git a/src/main/java/org/ldk/structs/UtilMethods.java b/src/main/java/org/ldk/structs/UtilMethods.java index ef8ba801..7c53034a 100644 --- a/src/main/java/org/ldk/structs/UtilMethods.java +++ b/src/main/java/org/ldk/structs/UtilMethods.java @@ -388,14 +388,15 @@ public class UtilMethods { * * Note that first_hops (or a relevant inner pointer) may be NULL or all-0s to represent None */ - public static Result_RouteLightningErrorZ find_route(byte[] our_node_pubkey, RouteParameters route_params, NetworkGraph network, @Nullable ChannelDetails[] first_hops, Logger logger, Score scorer) { - long ret = bindings.find_route(InternalUtils.check_arr_len(our_node_pubkey, 33), route_params == null ? 0 : route_params.ptr & ~1, network == null ? 0 : network.ptr & ~1, first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr & ~1).toArray() : null, logger == null ? 0 : logger.ptr, scorer == null ? 0 : scorer.ptr); + public static Result_RouteLightningErrorZ find_route(byte[] our_node_pubkey, RouteParameters route_params, NetworkGraph network, @Nullable ChannelDetails[] first_hops, Logger logger, Score scorer, byte[] random_seed_bytes) { + long ret = bindings.find_route(InternalUtils.check_arr_len(our_node_pubkey, 33), route_params == null ? 0 : route_params.ptr & ~1, network == null ? 0 : network.ptr & ~1, first_hops != null ? Arrays.stream(first_hops).mapToLong(first_hops_conv_16 -> first_hops_conv_16 == null ? 0 : first_hops_conv_16.ptr & ~1).toArray() : null, logger == null ? 0 : logger.ptr, scorer == null ? 0 : scorer.ptr, InternalUtils.check_arr_len(random_seed_bytes, 32)); Reference.reachabilityFence(our_node_pubkey); Reference.reachabilityFence(route_params); Reference.reachabilityFence(network); Reference.reachabilityFence(first_hops); Reference.reachabilityFence(logger); Reference.reachabilityFence(scorer); + Reference.reachabilityFence(random_seed_bytes); if (ret >= 0 && ret <= 4096) { return null; } Result_RouteLightningErrorZ ret_hu_conv = Result_RouteLightningErrorZ.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(route_params); @@ -420,6 +421,20 @@ public class UtilMethods { return ret_hu_conv; } + /** + * Write the provided `NetworkGraph` to the path provided at `FilesystemPersister` + * initialization, within a file called \"network_graph\" + */ + public static Result_NoneErrorZ FilesystemPersister_persist_network_graph(java.lang.String data_dir, NetworkGraph network_graph) { + long ret = bindings.FilesystemPersister_persist_network_graph(data_dir, network_graph == null ? 0 : network_graph.ptr & ~1); + Reference.reachabilityFence(data_dir); + Reference.reachabilityFence(network_graph); + if (ret >= 0 && ret <= 4096) { return null; } + Result_NoneErrorZ ret_hu_conv = Result_NoneErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(network_graph); + return ret_hu_conv; + } + /** * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\" * See [`PhantomKeysManager`] for more information on phantom node payments. @@ -461,6 +476,49 @@ public class UtilMethods { return ret_hu_conv; } + /** + * Utility to create an invoice that can be paid to one of multiple nodes, or a \"phantom invoice.\" + * See [`PhantomKeysManager`] for more information on phantom node payments. + * + * `phantom_route_hints` parameter: + * Contains channel info for all nodes participating in the phantom invoice + * Entries are retrieved from a call to [`ChannelManager::get_phantom_route_hints`] on each + * participating node + * It is fine to cache `phantom_route_hints` and reuse it across invoices, as long as the data is + * updated when a channel becomes disabled or closes + * Note that if too many channels are included in [`PhantomRouteHints::channels`], the invoice + * may be too long for QR code scanning. To fix this, `PhantomRouteHints::channels` may be pared + * down + * + * `description_hash` is a SHA-256 hash of the description text + * + * `payment_hash` and `payment_secret` come from [`ChannelManager::create_inbound_payment`] or + * [`ChannelManager::create_inbound_payment_for_hash`]. These values can be retrieved from any + * participating node. + * + * Note that the provided `keys_manager`'s `KeysInterface` implementation must support phantom + * invoices in its `sign_invoice` implementation ([`PhantomKeysManager`] satisfies this + * requirement). + * + * [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager + * [`ChannelManager::get_phantom_route_hints`]: lightning::ln::channelmanager::ChannelManager::get_phantom_route_hints + * [`PhantomRouteHints::channels`]: lightning::ln::channelmanager::PhantomRouteHints::channels + */ + public static Result_InvoiceSignOrCreationErrorZ create_phantom_invoice_with_description_hash(Option_u64Z amt_msat, Sha256 description_hash, byte[] payment_hash, byte[] payment_secret, PhantomRouteHints[] phantom_route_hints, KeysInterface keys_manager, org.ldk.enums.Currency network) { + long ret = bindings.create_phantom_invoice_with_description_hash(amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr & ~1, InternalUtils.check_arr_len(payment_hash, 32), InternalUtils.check_arr_len(payment_secret, 32), phantom_route_hints != null ? Arrays.stream(phantom_route_hints).mapToLong(phantom_route_hints_conv_19 -> phantom_route_hints_conv_19 == null ? 0 : phantom_route_hints_conv_19.ptr & ~1).toArray() : null, keys_manager == null ? 0 : keys_manager.ptr, network); + Reference.reachabilityFence(amt_msat); + Reference.reachabilityFence(description_hash); + Reference.reachabilityFence(payment_hash); + Reference.reachabilityFence(payment_secret); + Reference.reachabilityFence(phantom_route_hints); + Reference.reachabilityFence(keys_manager); + Reference.reachabilityFence(network); + if (ret >= 0 && ret <= 4096) { return null; } + Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(keys_manager); + return ret_hu_conv; + } + /** * Utility to construct an invoice. Generally, unless you want to do something like a custom * cltv_expiry, this is what you should be using to create an invoice. The reason being, this @@ -482,6 +540,48 @@ public class UtilMethods { return ret_hu_conv; } + /** + * Utility to construct an invoice. Generally, unless you want to do something like a custom + * cltv_expiry, this is what you should be using to create an invoice. The reason being, this + * method stores the invoice's payment secret and preimage in `ChannelManager`, so (a) the user + * doesn't have to store preimage/payment secret information and (b) `ChannelManager` can verify + * that the payment secret is valid when the invoice is paid. + * Use this variant if you want to pass the `description_hash` to the invoice. + */ + public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash(ChannelManager channelmanager, KeysInterface keys_manager, org.ldk.enums.Currency network, Option_u64Z amt_msat, Sha256 description_hash) { + long ret = bindings.create_invoice_from_channelmanager_with_description_hash(channelmanager == null ? 0 : channelmanager.ptr & ~1, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr & ~1); + Reference.reachabilityFence(channelmanager); + Reference.reachabilityFence(keys_manager); + Reference.reachabilityFence(network); + Reference.reachabilityFence(amt_msat); + Reference.reachabilityFence(description_hash); + if (ret >= 0 && ret <= 4096) { return null; } + Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(channelmanager); + ret_hu_conv.ptrs_to.add(keys_manager); + return ret_hu_conv; + } + + /** + * See [`create_invoice_from_channelmanager_with_description_hash`] + * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not + * available and the current time is supplied by the caller. + */ + public static Result_InvoiceSignOrCreationErrorZ create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(ChannelManager channelmanager, KeysInterface keys_manager, org.ldk.enums.Currency network, Option_u64Z amt_msat, Sha256 description_hash, long duration_since_epoch) { + long ret = bindings.create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(channelmanager == null ? 0 : channelmanager.ptr & ~1, keys_manager == null ? 0 : keys_manager.ptr, network, amt_msat.ptr, description_hash == null ? 0 : description_hash.ptr & ~1, duration_since_epoch); + Reference.reachabilityFence(channelmanager); + Reference.reachabilityFence(keys_manager); + Reference.reachabilityFence(network); + Reference.reachabilityFence(amt_msat); + Reference.reachabilityFence(description_hash); + Reference.reachabilityFence(duration_since_epoch); + if (ret >= 0 && ret <= 4096) { return null; } + Result_InvoiceSignOrCreationErrorZ ret_hu_conv = Result_InvoiceSignOrCreationErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(channelmanager); + ret_hu_conv.ptrs_to.add(keys_manager); + return ret_hu_conv; + } + /** * See [`create_invoice_from_channelmanager`] * This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not