use lightning::ln::channelmanager::{PaymentId, RecipientOnionFields, Retry};
use lightning::ln::msgs::SocketAddress;
use lightning::ln::{ChannelId, PaymentHash, PaymentPreimage};
-use lightning::onion_message::OnionMessagePath;
-use lightning::onion_message::{Destination, OnionMessageContents};
+use lightning::onion_message::messenger::Destination;
+use lightning::onion_message::packet::OnionMessageContents;
use lightning::routing::gossip::NodeId;
use lightning::routing::router::{PaymentParameters, RouteParameters};
use lightning::sign::{EntropySource, KeysManager};
use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
use lightning::util::persist::KVStore;
use lightning::util::ser::{Writeable, Writer};
-use lightning_invoice::payment::pay_invoice;
+use lightning_invoice::payment::payment_parameters_from_invoice;
use lightning_invoice::{utils, Bolt11Invoice, Currency};
use lightning_persister::fs_store::FilesystemStore;
use std::env;
pub(crate) network: Network,
}
+#[derive(Debug)]
struct UserOnionMessageContents {
tlv_type: u64,
data: Vec<u8>,
}
};
let destination = Destination::Node(intermediate_nodes.pop().unwrap());
- let message_path = OnionMessagePath { intermediate_nodes, destination };
match onion_messenger.send_onion_message(
- message_path,
UserOnionMessageContents { tlv_type, data },
+ destination,
None,
) {
- Ok(()) => println!("SUCCESS: forwarded onion message to first hop"),
+ Ok(success) => {
+ println!("SUCCESS: forwarded onion message to first hop {:?}", success)
+ }
Err(e) => println!("ERROR: failed to send onion message: {:?}", e),
}
}
..Default::default()
};
- match channel_manager.create_channel(peer_pubkey, channel_amt_sat, 0, 0, Some(config)) {
+ match channel_manager.create_channel(peer_pubkey, channel_amt_sat, 0, 0, None, Some(config)) {
Ok(_) => {
println!("EVENT: initiated channel with peer {}. ", peer_pubkey);
return Ok(());
channel_manager: &ChannelManager, invoice: &Bolt11Invoice,
outbound_payments: &mut OutboundPaymentInfoStorage, fs_store: Arc<FilesystemStore>,
) {
- let payment_id = PaymentId((*invoice.payment_hash()).into_inner());
+ let payment_id = PaymentId((*invoice.payment_hash()).to_byte_array());
let payment_secret = Some(*invoice.payment_secret());
+ let (payment_hash, recipient_onion, route_params) =
+ match payment_parameters_from_invoice(invoice) {
+ Ok(res) => res,
+ Err(e) => {
+ println!("Failed to parse invoice");
+ print!("> ");
+ return;
+ }
+ };
outbound_payments.payments.insert(
payment_id,
PaymentInfo {
},
);
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
- match pay_invoice(invoice, Retry::Timeout(Duration::from_secs(10)), channel_manager) {
- Ok(_payment_id) => {
+
+ match channel_manager.send_payment(
+ payment_hash,
+ recipient_onion,
+ payment_id,
+ route_params,
+ Retry::Timeout(Duration::from_secs(10)),
+ ) {
+ Ok(_) => {
let payee_pubkey = invoice.recover_payee_pub_key();
let amt_msat = invoice.amount_milli_satoshis().unwrap();
println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
outbound_payments: &mut OutboundPaymentInfoStorage, fs_store: Arc<FilesystemStore>,
) {
let payment_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes());
- let payment_id = PaymentId(Sha256::hash(&payment_preimage.0[..]).into_inner());
+ let payment_id = PaymentId(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::for_keysend(payee_pubkey, 40, false),
) {
let currency = match network {
Network::Bitcoin => Currency::Bitcoin,
- Network::Testnet => Currency::BitcoinTestnet,
Network::Regtest => Currency::Regtest,
Network::Signet => Currency::Signet,
+ Network::Testnet | _ => Currency::BitcoinTestnet,
};
let invoice = match utils::create_invoice_from_channelmanager(
channel_manager,
}
};
- let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
+ let payment_hash = PaymentHash(invoice.payment_hash().to_byte_array());
inbound_payments.payments.insert(
payment_hash,
PaymentInfo {