Skip to content

Commit

Permalink
Merge pull request #50 from TheBlueMatt/main
Browse files Browse the repository at this point in the history
v0.0.102.0
  • Loading branch information
TheBlueMatt authored Oct 19, 2021
2 parents e6173a7 + 2a3bb81 commit db55d4e
Show file tree
Hide file tree
Showing 59 changed files with 12,405 additions and 6,558 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.101
git checkout 0.0.102
- name: Rebuild C bindings without STD for WASM
run: |
cd ldk-c-bindings
Expand Down Expand Up @@ -153,7 +153,7 @@ jobs:
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.101
git checkout 0.0.102
- name: Checkout Android AAR binaries and artifacts
run: git clone --depth 1 https://git.bitcoin.ninja/ldk-java-bins
- name: Build Android aar
Expand Down Expand Up @@ -193,14 +193,14 @@ jobs:
run: rustup target install aarch64-apple-darwin
- name: Fetch upstream LLVM/clang snapshot
run: |
wget -O clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
if [ "$(shasum -a 256 clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "7bc2259bf75c003f644882460fc8e844ddb23b27236fe43a2787870a4cd8ab50" ]; then
wget -O clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz
if [ "$(shasum -a 256 clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "d051234eca1db1f5e4bc08c64937c879c7098900f7a0370f3ceb7544816a8b09" ]; then
echo "Bad hash"
exit 1
fi
- name: Unpack upstream LLVM+clang and use it by default
run: |
tar xvvf clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
tar xvvf clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz
- name: Checkout source code
uses: actions/checkout@v2
with:
Expand All @@ -218,11 +218,11 @@ jobs:
cd ..
git clone https://github.com/lightningdevkit/ldk-c-bindings
cd ldk-c-bindings
git checkout 0.0.101
git checkout 0.0.102
- name: Rebuild C bindings with upstream clang, and check the sample app builds + links
run: |
cd ldk-c-bindings
export PATH=`pwd`/clang+llvm-12.0.0-x86_64-apple-darwin/bin:$PATH
export PATH=`pwd`/clang+llvm-13.0.0-x86_64-apple-darwin/bin:$PATH
CC=clang ./genbindings.sh ../rust-lightning true
cd ..
- name: Fetch OpenJDK 16
Expand All @@ -247,7 +247,7 @@ jobs:
# genbindings.sh always fails as there is no wasm32-wasi library
# available, so instead we check that the expected JNI library
# is created.
export PATH=`pwd`/clang+llvm-12.0.0-x86_64-apple-darwin/bin:$PATH
export PATH=`pwd`/clang+llvm-13.0.0-x86_64-apple-darwin/bin:$PATH
./genbindings.sh ./ldk-c-bindings/ "-I$JAVA_HOME/include/ -I$JAVA_HOME/include/darwin -isysroot$(xcrun --show-sdk-path)" false false || echo
cat src/main/resources/liblightningjni_MacOSX-x86_64.nativelib > /dev/null
if [ "${{ matrix.platform }}" = "macos-11" ]; then
Expand Down
4 changes: 4 additions & 0 deletions genbindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.clas

IS_MAC=false
[ "$($CC --version | grep apple-darwin)" != "" ] && IS_MAC=true
IS_APPLE_CLANG=false
[ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true

echo "Building Java bindings..."
COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -ldl -shared -fPIC"
[ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--no-undefined"
[ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9"
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && COMPILE="$COMPILE -fuse-ld=lld"
[ "$IS_MAC" = "true" -a "$IS_APPLE_CLANG" = "false" ] && echo "WARNING: Need at least upstream clang 13!"
[ "$IS_MAC" = "false" -a "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,malloc -Wl,-wrap,free"
if [ "$3" = "true" ]; then
$COMPILE -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
Expand Down
462 changes: 304 additions & 158 deletions src/main/java/org/ldk/impl/bindings.java

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/main/java/org/ldk/structs/ChainMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ public Balance[] get_claimable_balances(ChannelDetails[] ignored_channels) {
return ret_conv_9_arr;
}

/**
* Gets the [`LockedChannelMonitor`] for a given funding outpoint, returning an `Err` if no
* such [`ChannelMonitor`] is currently being monitored for.
*
* Note that the result holds a mutex over our monitor set, and should not be held
* indefinitely.
*/
public Result_LockedChannelMonitorNoneZ get_monitor(OutPoint funding_txo) {
long ret = bindings.ChainMonitor_get_monitor(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1);
if (ret >= 0 && ret < 1024) { return null; }
Result_LockedChannelMonitorNoneZ ret_hu_conv = Result_LockedChannelMonitorNoneZ.constr_from_ptr(ret);
return ret_hu_conv;
}

/**
* Lists the funding outpoint of each [`ChannelMonitor`] being monitored.
*
* Note that [`ChannelMonitor`]s are not removed when a channel is closed as they are always
* monitoring for on-chain state resolutions.
*/
public OutPoint[] list_monitors() {
long[] ret = bindings.ChainMonitor_list_monitors(this.ptr);
OutPoint[] ret_conv_10_arr = new OutPoint[ret.length];
for (int k = 0; k < ret.length; k++) {
long ret_conv_10 = ret[k];
OutPoint ret_conv_10_hu_conv = new OutPoint(null, ret_conv_10);
ret_conv_10_hu_conv.ptrs_to.add(this);
ret_conv_10_arr[k] = ret_conv_10_hu_conv;
}
return ret_conv_10_arr;
}

/**
* Constructs a new Listen which calls the relevant methods on this_arg.
* This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/ldk/structs/ChannelDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,18 @@ public void set_unspendable_punishment_reserve(Option_u64Z val) {
}

/**
* The user_id passed in to create_channel, or 0 if the channel was inbound.
* The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
*/
public long get_user_id() {
long ret = bindings.ChannelDetails_get_user_id(this.ptr);
public long get_user_channel_id() {
long ret = bindings.ChannelDetails_get_user_channel_id(this.ptr);
return ret;
}

/**
* The user_id passed in to create_channel, or 0 if the channel was inbound.
* The `user_channel_id` passed in to create_channel, or 0 if the channel was inbound.
*/
public void set_user_id(long val) {
bindings.ChannelDetails_set_user_id(this.ptr, val);
public void set_user_channel_id(long val) {
bindings.ChannelDetails_set_user_channel_id(this.ptr, val);
}

/**
Expand Down Expand Up @@ -382,8 +382,8 @@ public void set_is_public(boolean val) {
/**
* Constructs a new ChannelDetails given each field
*/
public static ChannelDetails of(byte[] channel_id_arg, ChannelCounterparty counterparty_arg, OutPoint funding_txo_arg, Option_u64Z short_channel_id_arg, long channel_value_satoshis_arg, Option_u64Z unspendable_punishment_reserve_arg, long user_id_arg, long outbound_capacity_msat_arg, long inbound_capacity_msat_arg, Option_u32Z confirmations_required_arg, Option_u16Z force_close_spend_delay_arg, boolean is_outbound_arg, boolean is_funding_locked_arg, boolean is_usable_arg, boolean is_public_arg) {
long ret = bindings.ChannelDetails_new(channel_id_arg, counterparty_arg == null ? 0 : counterparty_arg.ptr & ~1, funding_txo_arg == null ? 0 : funding_txo_arg.ptr & ~1, short_channel_id_arg.ptr, channel_value_satoshis_arg, unspendable_punishment_reserve_arg.ptr, user_id_arg, outbound_capacity_msat_arg, inbound_capacity_msat_arg, confirmations_required_arg.ptr, force_close_spend_delay_arg.ptr, is_outbound_arg, is_funding_locked_arg, is_usable_arg, is_public_arg);
public static ChannelDetails of(byte[] channel_id_arg, ChannelCounterparty counterparty_arg, OutPoint funding_txo_arg, Option_u64Z short_channel_id_arg, long channel_value_satoshis_arg, Option_u64Z unspendable_punishment_reserve_arg, long user_channel_id_arg, long outbound_capacity_msat_arg, long inbound_capacity_msat_arg, Option_u32Z confirmations_required_arg, Option_u16Z force_close_spend_delay_arg, boolean is_outbound_arg, boolean is_funding_locked_arg, boolean is_usable_arg, boolean is_public_arg) {
long ret = bindings.ChannelDetails_new(channel_id_arg, counterparty_arg == null ? 0 : counterparty_arg.ptr & ~1, funding_txo_arg == null ? 0 : funding_txo_arg.ptr & ~1, short_channel_id_arg.ptr, channel_value_satoshis_arg, unspendable_punishment_reserve_arg.ptr, user_channel_id_arg, outbound_capacity_msat_arg, inbound_capacity_msat_arg, confirmations_required_arg.ptr, force_close_spend_delay_arg.ptr, is_outbound_arg, is_funding_locked_arg, is_usable_arg, is_public_arg);
if (ret >= 0 && ret < 1024) { return null; }
ChannelDetails ret_hu_conv = new ChannelDetails(null, ret);
ret_hu_conv.ptrs_to.add(ret_hu_conv);
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/org/ldk/structs/ChannelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ public void set_features(ChannelFeatures val) {
/**
* Source node of the first direction of a channel
*/
public byte[] get_node_one() {
byte[] ret = bindings.ChannelInfo_get_node_one(this.ptr);
return ret;
public NodeId get_node_one() {
long ret = bindings.ChannelInfo_get_node_one(this.ptr);
if (ret >= 0 && ret < 1024) { return null; }
NodeId ret_hu_conv = new NodeId(null, ret);
ret_hu_conv.ptrs_to.add(this);
return ret_hu_conv;
}

/**
* Source node of the first direction of a channel
*/
public void set_node_one(byte[] val) {
bindings.ChannelInfo_set_node_one(this.ptr, val);
public void set_node_one(NodeId val) {
bindings.ChannelInfo_set_node_one(this.ptr, val == null ? 0 : val.ptr & ~1);
}

/**
Expand Down Expand Up @@ -79,16 +82,19 @@ public void set_one_to_two(@Nullable DirectionalChannelInfo val) {
/**
* Source node of the second direction of a channel
*/
public byte[] get_node_two() {
byte[] ret = bindings.ChannelInfo_get_node_two(this.ptr);
return ret;
public NodeId get_node_two() {
long ret = bindings.ChannelInfo_get_node_two(this.ptr);
if (ret >= 0 && ret < 1024) { return null; }
NodeId ret_hu_conv = new NodeId(null, ret);
ret_hu_conv.ptrs_to.add(this);
return ret_hu_conv;
}

/**
* Source node of the second direction of a channel
*/
public void set_node_two(byte[] val) {
bindings.ChannelInfo_set_node_two(this.ptr, val);
public void set_node_two(NodeId val) {
bindings.ChannelInfo_set_node_two(this.ptr, val == null ? 0 : val.ptr & ~1);
}

/**
Expand Down Expand Up @@ -164,8 +170,8 @@ public void set_announcement_message(@Nullable ChannelAnnouncement val) {
/**
* Constructs a new ChannelInfo given each field
*/
public static ChannelInfo of(ChannelFeatures features_arg, byte[] node_one_arg, DirectionalChannelInfo one_to_two_arg, byte[] node_two_arg, DirectionalChannelInfo two_to_one_arg, Option_u64Z capacity_sats_arg, ChannelAnnouncement announcement_message_arg) {
long ret = bindings.ChannelInfo_new(features_arg == null ? 0 : features_arg.ptr & ~1, node_one_arg, one_to_two_arg == null ? 0 : one_to_two_arg.ptr & ~1, node_two_arg, two_to_one_arg == null ? 0 : two_to_one_arg.ptr & ~1, capacity_sats_arg.ptr, announcement_message_arg == null ? 0 : announcement_message_arg.ptr & ~1);
public static ChannelInfo of(ChannelFeatures features_arg, NodeId node_one_arg, DirectionalChannelInfo one_to_two_arg, NodeId node_two_arg, DirectionalChannelInfo two_to_one_arg, Option_u64Z capacity_sats_arg, ChannelAnnouncement announcement_message_arg) {
long ret = bindings.ChannelInfo_new(features_arg == null ? 0 : features_arg.ptr & ~1, node_one_arg == null ? 0 : node_one_arg.ptr & ~1, one_to_two_arg == null ? 0 : one_to_two_arg.ptr & ~1, node_two_arg == null ? 0 : node_two_arg.ptr & ~1, two_to_one_arg == null ? 0 : two_to_one_arg.ptr & ~1, capacity_sats_arg.ptr, announcement_message_arg == null ? 0 : announcement_message_arg.ptr & ~1);
if (ret >= 0 && ret < 1024) { return null; }
ChannelInfo ret_hu_conv = new ChannelInfo(null, ret);
ret_hu_conv.ptrs_to.add(ret_hu_conv);
Expand Down
61 changes: 44 additions & 17 deletions src/main/java/org/ldk/structs/ChannelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,37 @@ public UserConfig get_current_default_configuration() {
/**
* Creates a new outbound channel to the given remote node and with the given value.
*
* user_id will be provided back as user_channel_id in FundingGenerationReady events to allow
* tracking of which events correspond with which create_channel call. Note that the
* user_channel_id defaults to 0 for inbound channels, so you may wish to avoid using 0 for
* user_id here. user_id has no meaning inside of LDK, it is simply copied to events and
* otherwise ignored.
* `user_channel_id` will be provided back as in
* [`Event::FundingGenerationReady::user_channel_id`] to allow tracking of which events
* correspond with which `create_channel` call. Note that the `user_channel_id` defaults to 0
* for inbound channels, so you may wish to avoid using 0 for `user_channel_id` here.
* `user_channel_id` has no meaning inside of LDK, it is simply copied to events and otherwise
* ignored.
*
* If successful, will generate a SendOpenChannel message event, so you should probably poll
* PeerManager::process_events afterwards.
*
* Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat is
* greater than channel_value_satoshis * 1k or channel_value_satoshis is < 1000.
* Raises [`APIError::APIMisuseError`] when `channel_value_satoshis` > 2**24 or `push_msat` is
* greater than `channel_value_satoshis * 1k` or `channel_value_satoshis < 1000`.
*
* Note that we do not check if you are currently connected to the given peer. If no
* connection is available, the outbound `open_channel` message may fail to send, resulting in
* the channel eventually being silently forgotten.
* the channel eventually being silently forgotten (dropped on reload).
*
* Returns the new Channel's temporary `channel_id`. This ID will appear as
* [`Event::FundingGenerationReady::temporary_channel_id`] and in
* [`ChannelDetails::channel_id`] until after
* [`ChannelManager::funding_transaction_generated`] is called, swapping the Channel's ID for
* one derived from the funding transaction's TXID. If the counterparty rejects the channel
* immediately, this temporary ID will appear in [`Event::ChannelClosed::channel_id`].
*
* [`Event::FundingGenerationReady::user_channel_id`]: events::Event::FundingGenerationReady::user_channel_id
* [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
* [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
*
* Note that override_config (or a relevant inner pointer) may be NULL or all-0s to represent None
*/
public Result_NoneAPIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_id, @Nullable UserConfig override_config) {
long ret = bindings.ChannelManager_create_channel(this.ptr, their_network_key, channel_value_satoshis, push_msat, user_id, override_config == null ? 0 : override_config.ptr & ~1);
public Result__u832APIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_channel_id, @Nullable UserConfig override_config) {
long ret = bindings.ChannelManager_create_channel(this.ptr, their_network_key, channel_value_satoshis, push_msat, user_channel_id, override_config == null ? 0 : override_config.ptr & ~1);
if (ret >= 0 && ret < 1024) { return null; }
Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret);
Result__u832APIErrorZ ret_hu_conv = Result__u832APIErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}

Expand Down Expand Up @@ -272,9 +281,27 @@ public void force_close_all_channels() {
*
* Note that payment_secret (or a relevant inner pointer) may be NULL or all-0s to represent None
*/
public Result_NonePaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
public Result_PaymentIdPaymentSendFailureZ send_payment(Route route, byte[] payment_hash, @Nullable byte[] payment_secret) {
long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_hash, payment_secret);
if (ret >= 0 && ret < 1024) { return null; }
Result_PaymentIdPaymentSendFailureZ ret_hu_conv = Result_PaymentIdPaymentSendFailureZ.constr_from_ptr(ret);
this.ptrs_to.add(route);
return ret_hu_conv;
}

/**
* Retries a payment along the given [`Route`].
*
* Errors returned are a superset of those returned from [`send_payment`], so see
* [`send_payment`] documentation for more details on errors. This method will also error if the
* retry amount puts the payment more than 10% over the payment's total amount, or if the payment
* for the given `payment_id` cannot be found (likely due to timeout or success).
*
* [`send_payment`]: [`ChannelManager::send_payment`]
*/
public Result_NonePaymentSendFailureZ retry_payment(Route route, PaymentId payment_id) {
long ret = bindings.ChannelManager_retry_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_id == null ? 0 : payment_id.ptr & ~1);
if (ret >= 0 && ret < 1024) { return null; }
Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret);
this.ptrs_to.add(route);
return ret_hu_conv;
Expand All @@ -298,10 +325,10 @@ public Result_NonePaymentSendFailureZ send_payment(Route route, byte[] payment_h
*
* Note that payment_preimage (or a relevant inner pointer) may be NULL or all-0s to represent None
*/
public Result_PaymentHashPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
public Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ send_spontaneous_payment(Route route, @Nullable byte[] payment_preimage) {
long ret = bindings.ChannelManager_send_spontaneous_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_preimage);
if (ret >= 0 && ret < 1024) { return null; }
Result_PaymentHashPaymentSendFailureZ ret_hu_conv = Result_PaymentHashPaymentSendFailureZ.constr_from_ptr(ret);
Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ ret_hu_conv = Result_C2Tuple_PaymentHashPaymentIdZPaymentSendFailureZ.constr_from_ptr(ret);
this.ptrs_to.add(route);
return ret_hu_conv;
}
Expand Down
Loading

0 comments on commit db55d4e

Please sign in to comment.