|
| 1 | +use ldk_node::bitcoin::Network; |
| 2 | +use ldk_node::{Builder, LogLevel}; |
| 3 | + |
| 4 | +fn main() { |
| 5 | + let mut builder = Builder::new(); |
| 6 | + builder.set_log_level(LogLevel::Gossip); |
| 7 | + builder.set_network(Network::Testnet); |
| 8 | + builder.set_esplora_server("https://blockstream.info/testnet/api".to_string()); |
| 9 | + builder.set_gossip_source_rgs( |
| 10 | + "https://rapidsync.lightningdevkit.org/testnet/snapshot".to_string(), |
| 11 | + ); |
| 12 | + |
| 13 | + // Payjoin directory is needed only if you are setting up Payjoin receiver, |
| 14 | + // not required for Payjoin sender. |
| 15 | + let payjoin_directory = "https://payjo.in".to_string(); |
| 16 | + // Payjoin relay is required for both Payjoin receiver and sender. |
| 17 | + let payjoin_relay = "https://pj.bobspacebkk.com".to_string(); |
| 18 | + |
| 19 | + // Enable sending payjoin transactions |
| 20 | + // builder.set_payjoin_sender_config(payjoin_relay.clone()); |
| 21 | + // ohttp keys refer to the Payjoin directory keys that are needed for the Payjoin receiver |
| 22 | + // enrollement. If those keys are not provided the node will attempt to fetch them for you. |
| 23 | + // let ohttp_keys = None; |
| 24 | + // Enable receiving payjoin transactions |
| 25 | + builder.set_payjoin_config(payjoin_directory, payjoin_relay); |
| 26 | + |
| 27 | + let node = builder.build().unwrap(); |
| 28 | + |
| 29 | + node.start().unwrap(); |
| 30 | + |
| 31 | + // Receiving payjoin transaction |
| 32 | + let payjoin_payment = node.payjoin_payment(); |
| 33 | + let amount_to_receive = bitcoin::Amount::from_sat(1000); |
| 34 | + let payjoin_uri = payjoin_payment.receive(amount_to_receive).unwrap(); |
| 35 | + let payjoin_uri = payjoin_uri.to_string(); |
| 36 | + |
| 37 | + println!("Payjoin URI: {}", payjoin_uri); |
| 38 | + |
| 39 | + //** Open a channel from incoming payjoin transactions ***// |
| 40 | + // let payjoin_payment = node.payjoin_payment(); |
| 41 | + // let channel_amount_sats = bitcoin::Amount::from_sat(10000); |
| 42 | + // use bitcoin::secp256k1::PublicKey; |
| 43 | + // use lightning::ln::msgs::SocketAddress; |
| 44 | + // let counterparty_node_id: PublicKey = unimplemented!(); |
| 45 | + // let counterparty_address: SocketAddress = unimplemented!(); |
| 46 | + // let payjoin_uri = match payjoin_payment.receive_with_channel_opening(channel_amount_sats, None, true, |
| 47 | + // counterparty_node_id, counterparty_address, |
| 48 | + // ).await { |
| 49 | + // Ok(a) => a, |
| 50 | + // Err(e) => { |
| 51 | + // panic!("{}", e); |
| 52 | + // }, |
| 53 | + // }; |
| 54 | + // let payjoin_uri = payjoin_uri.to_string(); |
| 55 | + // println!("Payjoin URI: {}", payjoin_uri); |
| 56 | + |
| 57 | + //** Sending payjoin transaction **// |
| 58 | + // let payjoin_uri = payjoin::Uri::try_from(payjoin_uri).unwrap(); |
| 59 | + // match payjoin_payment.send(payjoin_uri, None, None).await { |
| 60 | + // Ok(Some(txid)) => { |
| 61 | + // dbg!("Sent transaction and got a response. Transaction completed") |
| 62 | + // }, |
| 63 | + // Ok(None) => { |
| 64 | + // dbg!("Sent transaction and got no response. We will keep polling the response for the next 24hours") |
| 65 | + // }, |
| 66 | + // Err(e) => { |
| 67 | + // dbg!(e); |
| 68 | + // } |
| 69 | + // } |
| 70 | + node.stop().unwrap(); |
| 71 | +} |
0 commit comments