Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into bolt11-data
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Mar 5, 2024
2 parents a4672f6 + b18652c commit cf26193
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 239 deletions.
56 changes: 0 additions & 56 deletions .github/workflows/kotlin.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/publish-android.yml

This file was deleted.

86 changes: 0 additions & 86 deletions .github/workflows/publish-jvm.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/python.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
]
toolchain: [
stable,
beta,
1.63.0, # Our MSRV
]
include:
- toolchain: stable
Expand All @@ -29,8 +27,6 @@ jobs:
platform: macos-latest
- toolchain: stable
platform: windows-latest
- toolchain: 1.63.0
msrv: true
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout source code
Expand Down Expand Up @@ -65,10 +61,6 @@ jobs:
- name: Build with UniFFI support on Rust ${{ matrix.toolchain }}
if: matrix.build-uniffi
run: cargo build --features uniffi --verbose --color always
- name: Build documentation on Rust ${{ matrix.toolchain }}
run: |
cargo doc --release --verbose --color always
cargo doc --document-private-items --verbose --color always
- name: Check release build on Rust ${{ matrix.toolchain }}
run: cargo check --release --verbose --color always
- name: Check release build with UniFFI support on Rust ${{ matrix.toolchain }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ swift.swiftdoc
/bindings/swift/LDKNodeFFI.xcframework
/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs
/bindings/kotlin/ldk-node-android/lib/src/main/kotlin/org/lightningdevkit/ldknode/ldk_node.kt

/ffi/
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ uniffi = { version = "0.25.3", features = ["build"], optional = true }

[profile.release]
panic = "abort"
lto = true
rpath = true

[profile.dev]
panic = "abort"
8 changes: 7 additions & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ interface LDKNode {
[Throws=NodeError]
PaymentHash send_payment_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat);
[Throws=NodeError]
PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id);
PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id, sequence<TlvEntry> custom_tlvs);
[Throws=NodeError]
void send_payment_probes([ByRef]Bolt11Invoice invoice);
[Throws=NodeError]
Expand Down Expand Up @@ -131,6 +131,7 @@ enum NodeError {
"InvalidInvoice",
"InvalidChannelId",
"InvalidNetwork",
"InvalidCustomTlv",
"DuplicatePayment",
"InsufficientFunds",
"LiquiditySourceUnavailable",
Expand Down Expand Up @@ -316,6 +317,11 @@ enum LogLevel {
"Error",
};

dictionary TlvEntry {
u64 type;
sequence<u8> value;
};

[Custom]
typedef string Txid;

Expand Down
35 changes: 35 additions & 0 deletions scripts/uniffi_bindgen_generate_go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

if ! command -v cross &> /dev/null; then
echo "cross-rs is required to build bindings. Install it by running:"
echo " cargo install cross --git https://github.com/cross-rs/cross"
exit 1
fi

uniffi-bindgen-go bindings/ldk_node.udl -o ffi/golang -c ./uniffi.toml

build_lib() {
local TOOL=$1
local TARGET=$2
local OUTPUT_FILE=$3

$TOOL build --release --target $TARGET --features uniffi || exit 1
mkdir -p "ffi/golang/ldk_node/$TARGET" || exit 1
cp "target/$TARGET/release/$OUTPUT_FILE" "ffi/golang/ldk_node/$TARGET/" || exit 1
}

is_target_installed() {
local TARGET=$1
rustup target list --installed | grep -q $TARGET
}

# If we're running on macOS, build the macOS library using the host compiler.
# Cross compilation is not supported (needs more complex setup).
if [[ "$OSTYPE" == "darwin"* ]]; then
build_lib "cargo" "aarch64-apple-darwin" "libldk_node.dylib"
fi

build_lib "cross" "x86_64-unknown-linux-gnu" "libldk_node.so"
build_lib "cross" "x86_64-pc-windows-gnu" "ldk_node.dll"
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub enum Error {
InvalidChannelId,
/// The given network is invalid.
InvalidNetwork,
/// The custom TLVs are invalid.
InvalidCustomTlv,
/// A payment with the given hash has already been initiated.
DuplicatePayment,
/// The available funds are insufficient to complete the given operation.
Expand Down Expand Up @@ -107,6 +109,7 @@ impl fmt::Display for Error {
Self::InvalidInvoice => write!(f, "The given invoice is invalid."),
Self::InvalidChannelId => write!(f, "The given channel ID is invalid."),
Self::InvalidNetwork => write!(f, "The given network is invalid."),
Self::InvalidCustomTlv => write!(f, "The given custom TLVs are invalid."),
Self::DuplicatePayment => {
write!(f, "A payment with the given hash has already been initiated.")
},
Expand Down
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ use types::{
Broadcaster, ChainMonitor, ChannelManager, FeeEstimator, KeysManager, NetworkGraph,
PeerManager, Router, Scorer, Sweeper, Wallet,
};
pub use types::{ChannelDetails, PeerDetails, UserChannelId};
pub use types::{ChannelDetails, PeerDetails, TlvEntry, UserChannelId};

use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger};

Expand Down Expand Up @@ -1234,7 +1234,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {

/// Send a spontaneous, aka. "keysend", payment
pub fn send_spontaneous_payment(
&self, amount_msat: u64, node_id: PublicKey,
&self, amount_msat: u64, node_id: PublicKey, custom_tlvs: Vec<TlvEntry>,
) -> Result<PaymentHash, Error> {
let rt_lock = self.runtime.read().unwrap();
if rt_lock.is_none() {
Expand All @@ -1257,7 +1257,12 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
PaymentParameters::from_node_id(node_id, self.config.default_cltv_expiry_delta),
amount_msat,
);
let recipient_fields = RecipientOnionFields::spontaneous_empty();
let recipient_fields = RecipientOnionFields::spontaneous_empty()
.with_custom_tlvs(custom_tlvs.into_iter().map(|tlv| (tlv.r#type, tlv.value)).collect())
.map_err(|_| {
log_error!(self.logger, "Payment error: invalid custom TLVs.");
Error::InvalidCustomTlv
})?;

match self.channel_manager.send_spontaneous_payment_with_retry(
Some(payment_preimage),
Expand Down
9 changes: 9 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,12 @@ impl Default for ChannelConfig {
LdkChannelConfig::default().into()
}
}

/// Custom TLV entry.
pub struct TlvEntry {
/// Type number.
pub r#type: u64,

/// Serialized value.
pub value: Vec<u8>,
}
Loading

0 comments on commit cf26193

Please sign in to comment.