-hard_tabs = true # use tab characters for indentation, spaces for alignment
+use_small_heuristics = "Max"
+fn_params_layout = "Compressed"
+hard_tabs = true
use_field_init_shorthand = true
max_width = 100
-use_small_heuristics = "Max"
-fn_args_layout = "Compressed"
+match_block_trailing_comma = true
+# UNSTABLE: format_code_in_doc_comments = true
+# UNSTABLE: overflow_delimited_expr = true
+# UNSTABLE: comment_width = 100
+# UNSTABLE: format_macro_matchers = true
+# UNSTABLE: format_strings = true
+# UNSTABLE: group_imports = "StdExternalCrate"
Some(Err(_)) => {
ldk_peer_port_set = false;
9735
- }
+ },
None => {
ldk_peer_port_set = false;
9735
- }
+ },
};
let mut arg_idx = match ldk_peer_port_set {
Some("signet") => Network::Signet,
Some(net) => {
panic!("Unsupported network provided. Options are: `regtest`, `testnet`, and `signet`. Got {}", net);
- }
+ },
None => Network::Testnet,
};
let mut bytes = [0; 32];
bytes[..s.len()].copy_from_slice(s.as_bytes());
bytes
- }
+ },
None => [0; 32],
};
Ok(sa) => {
ldk_announced_listen_addr.push(sa);
arg_idx += 1;
- }
+ },
Err(_) => panic!("Failed to parse announced-listen-addr into a socket address"),
},
None => break,
Err(e) => {
println!("{:?}", e.into_inner().unwrap());
continue;
- }
+ },
};
let chan_amt_sat: Result<u64, _> = channel_value_sat.unwrap().parse();
_ => {
println!("ERROR: invalid boolean flag format. Valid formats: `--option`, `--option=true` `--option=false`");
continue;
- }
+ },
}
}
peer_pubkey_and_ip_addr,
);
}
- }
+ },
"sendpayment" => {
let invoice_str = words.next();
if invoice_str.is_none() {
Err(e) => {
println!("ERROR: couldn't parse amount_msat: {}", e);
continue;
- }
+ },
};
}
(amt, _) => {
println!("ERROR: Cannot process non-Bitcoin-denominated offer value {:?}", amt);
continue;
- }
+ },
};
if user_provided_amt.is_some() && user_provided_amt != Some(amt_msat) {
println!("Amount didn't match offer of {}msat", amt_msat);
),
Err(e) => {
println!("ERROR: invalid invoice: {:?}", e);
- }
+ },
}
}
- }
+ },
"keysend" => {
let dest_pubkey = match words.next() {
Some(dest) => match hex_utils::to_compressed_pubkey(dest) {
None => {
println!("ERROR: couldn't parse destination pubkey");
continue;
- }
+ },
},
None => {
println!("ERROR: keysend requires a destination pubkey: `keysend <dest_pubkey> <amt_msat>`");
continue;
- }
+ },
};
let amt_msat_str = match words.next() {
Some(amt) => amt,
None => {
println!("ERROR: keysend requires an amount in millisatoshis: `keysend <dest_pubkey> <amt_msat>`");
continue;
- }
+ },
};
let amt_msat: u64 = match amt_msat_str.parse() {
Ok(amt) => amt,
Err(e) => {
println!("ERROR: couldn't parse amount_msat: {}", e);
continue;
- }
+ },
};
keysend(
&channel_manager,
&mut outbound_payments.lock().unwrap(),
Arc::clone(&fs_store),
);
- }
+ },
"getoffer" => {
let offer_builder = channel_manager.create_offer_builder(String::new());
if let Err(e) = offer_builder {
// correspond with individual payments.
println!("{}", offer.unwrap());
}
- }
+ },
"getinvoice" => {
let amt_str = words.next();
if amt_str.is_none() {
fs_store
.write("", "", INBOUND_PAYMENTS_FNAME, &inbound_payments.encode())
.unwrap();
- }
+ },
"connectpeer" => {
let peer_pubkey_and_ip_addr = words.next();
if peer_pubkey_and_ip_addr.is_none() {
Err(e) => {
println!("{:?}", e.into_inner().unwrap());
continue;
- }
+ },
};
if tokio::runtime::Handle::current()
.block_on(connect_peer_if_necessary(
{
println!("SUCCESS: connected to peer {}", pubkey);
}
- }
+ },
"disconnectpeer" => {
let peer_pubkey = words.next();
if peer_pubkey.is_none() {
Err(e) => {
println!("ERROR: {}", e.to_string());
continue;
- }
+ },
};
if do_disconnect_peer(
{
println!("SUCCESS: disconnected from peer {}", peer_pubkey);
}
- }
+ },
"listchannels" => list_channels(&channel_manager, &network_graph),
"listpayments" => list_payments(
&inbound_payments.lock().unwrap(),
None => {
println!("ERROR: couldn't parse peer_pubkey");
continue;
- }
+ },
};
let peer_pubkey = match PublicKey::from_slice(&peer_pubkey_vec) {
Ok(peer_pubkey) => peer_pubkey,
Err(_) => {
println!("ERROR: couldn't parse peer_pubkey");
continue;
- }
+ },
};
close_channel(channel_id, peer_pubkey, channel_manager.clone());
- }
+ },
"forceclosechannel" => {
let channel_id_str = words.next();
if channel_id_str.is_none() {
None => {
println!("ERROR: couldn't parse peer_pubkey");
continue;
- }
+ },
};
let peer_pubkey = match PublicKey::from_slice(&peer_pubkey_vec) {
Ok(peer_pubkey) => peer_pubkey,
Err(_) => {
println!("ERROR: couldn't parse peer_pubkey");
continue;
- }
+ },
};
force_close_channel(channel_id, peer_pubkey, channel_manager.clone());
- }
+ },
"nodeinfo" => node_info(&channel_manager, &peer_manager),
"listpeers" => list_peers(peer_manager.clone()),
"signmessage" => {
&keys_manager.get_node_secret_key()
)
);
- }
+ },
"sendonionmessage" => {
let path_pks_str = words.next();
if path_pks_str.is_none() {
println!("ERROR: couldn't parse peer_pubkey");
errored = true;
break;
- }
+ },
};
let node_pubkey = match PublicKey::from_slice(&node_pubkey_vec) {
Ok(peer_pubkey) => peer_pubkey,
println!("ERROR: couldn't parse peer_pubkey");
errored = true;
break;
- }
+ },
};
intermediate_nodes.push(node_pubkey);
}
_ => {
println!("Need an integral message type above 64");
continue;
- }
+ },
};
let data = match words.next().map(|s| hex_utils::to_vec(s)) {
Some(Some(data)) => data,
_ => {
println!("Need a hex data string");
continue;
- }
+ },
};
let destination = Destination::Node(intermediate_nodes.pop().unwrap());
match onion_messenger.send_onion_message(
) {
Ok(success) => {
println!("SUCCESS: forwarded onion message to first hop {:?}", success)
- }
+ },
Err(e) => println!("ERROR: failed to send onion message: {:?}", e),
}
- }
+ },
"quit" | "exit" => break,
_ => println!("Unknown command. See `\"help\" for available commands."),
}
return Ok(());
}
}
- }
+ },
None => Err(()),
}
}
Ok(_) => {
println!("EVENT: initiated channel with peer {}. ", peer_pubkey);
return Ok(());
- }
+ },
Err(e) => {
println!("ERROR: failed to open channel: {:?}", e);
return Err(());
- }
+ },
}
}
println!("Failed to parse invoice");
print!("> ");
return;
- }
+ },
};
outbound_payments.payments.insert(
payment_id,
let amt_msat = invoice.amount_milli_satoshis().unwrap();
println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
print!("> ");
- }
+ },
Err(e) => {
println!("ERROR: failed to send payment: {:?}", e);
print!("> ");
outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
- }
+ },
};
}
Ok(_payment_hash) => {
println!("EVENT: initiated sending {} msats to {}", amt_msat, payee_pubkey);
print!("> ");
- }
+ },
Err(e) => {
println!("ERROR: failed to send payment: {:?}", e);
print!("> ");
outbound_payments.payments.get_mut(&payment_id).unwrap().status = HTLCStatus::Failed;
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.encode()).unwrap();
- }
+ },
};
}
Ok(inv) => {
println!("SUCCESS: generated invoice: {}", inv);
inv
- }
+ },
Err(e) => {
println!("ERROR: failed to create invoice: {:?}", e);
return;
- }
+ },
};
let payment_hash = PaymentHash(invoice.payment_hash().to_byte_array());
// to convert virtual-bytes into weight units.
Some(feerate_btc_per_kvbyte) => {
Some((feerate_btc_per_kvbyte * 100_000_000.0 / 4.0).round() as u32)
- }
+ },
None => None,
},
})
// to convert virtual-bytes into weight units.
Some(feerate_btc_per_kvbyte) => {
Some((feerate_btc_per_kvbyte * 100_000_000.0 / 4.0).round() as u32)
- }
+ },
None => None,
},
})
match cli::parse_peer_info(line.unwrap()) {
Ok((pubkey, socket_addr)) => {
peer_data.insert(pubkey, socket_addr);
- }
+ },
Err(e) => return Err(e),
}
}
print!("> ");
io::stdout().flush().unwrap();
}
- }
+ },
Event::PaymentClaimable {
payment_hash,
purpose,
PaymentPurpose::SpontaneousPayment(preimage) => Some(preimage),
};
channel_manager.claim_funds(payment_preimage.unwrap());
- }
+ },
Event::PaymentClaimed {
payment_hash,
purpose,
let (payment_preimage, payment_secret) = match purpose {
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
(payment_preimage, Some(payment_secret))
- }
+ },
PaymentPurpose::SpontaneousPayment(preimage) => (Some(preimage), None),
};
let mut inbound = inbound_payments.lock().unwrap();
payment.status = HTLCStatus::Succeeded;
payment.preimage = payment_preimage;
payment.secret = payment_secret;
- }
+ },
Entry::Vacant(e) => {
e.insert(PaymentInfo {
preimage: payment_preimage,
status: HTLCStatus::Succeeded,
amt_msat: MillisatAmount(Some(amount_msat)),
});
- }
+ },
}
fs_store.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap();
- }
+ },
Event::PaymentSent {
payment_preimage, payment_hash, fee_paid_msat, payment_id, ..
} => {
}
}
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
- }
+ },
Event::OpenChannelRequest {
ref temporary_channel_id, ref counterparty_node_id, ..
} => {
}
print!("> ");
io::stdout().flush().unwrap();
- }
- Event::PaymentPathSuccessful { .. } => {}
- Event::PaymentPathFailed { .. } => {}
- Event::ProbeSuccessful { .. } => {}
- Event::ProbeFailed { .. } => {}
+ },
+ Event::PaymentPathSuccessful { .. } => {},
+ Event::PaymentPathFailed { .. } => {},
+ Event::ProbeSuccessful { .. } => {},
+ Event::ProbeFailed { .. } => {},
Event::PaymentFailed { payment_hash, reason, payment_id, .. } => {
print!(
"\nEVENT: Failed to send payment to payment hash {}: {:?}",
payment.status = HTLCStatus::Failed;
}
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
- }
+ },
Event::InvoiceRequestFailed { payment_id } => {
print!("\nEVENT: Failed to request invoice to send payment with id {}", payment_id);
print!("> ");
payment.status = HTLCStatus::Failed;
}
fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
- }
+ },
Event::PaymentForwarded {
prev_channel_id,
next_channel_id,
None => "unnamed node".to_string(),
Some(announcement) => {
format!("node {}", announcement.alias)
- }
+ },
},
}
- }
+ },
},
};
let channel_str = |channel_id: &Option<ChannelId>| {
}
print!("> ");
io::stdout().flush().unwrap();
- }
- Event::HTLCHandlingFailed { .. } => {}
+ },
+ Event::HTLCHandlingFailed { .. } => {},
Event::PendingHTLCsForwardable { time_forwardable } => {
let forwarding_channel_manager = channel_manager.clone();
let min = time_forwardable.as_millis() as u64;
tokio::time::sleep(Duration::from_millis(millis_to_sleep)).await;
forwarding_channel_manager.process_pending_htlc_forwards();
});
- }
+ },
Event::SpendableOutputs { outputs, channel_id: _ } => {
// SpendableOutputDescriptors, of which outputs is a vec of, are critical to keep track
// of! While a `StaticOutput` descriptor is just an output to a static, well-known key,
let output: SpendableOutputDescriptor = output;
fs_store.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap();
}
- }
+ },
Event::ChannelPending { channel_id, counterparty_node_id, .. } => {
println!(
"\nEVENT: Channel {} with peer {} is pending awaiting funding lock-in!",
);
print!("> ");
io::stdout().flush().unwrap();
- }
+ },
Event::ChannelReady {
ref channel_id,
user_channel_id: _,
);
print!("> ");
io::stdout().flush().unwrap();
- }
+ },
Event::ChannelClosed {
channel_id,
reason,
);
print!("> ");
io::stdout().flush().unwrap();
- }
+ },
Event::DiscardFunding { .. } => {
// A "real" node should probably "lock" the UTXOs spent in funding transactions until
// the funding transaction either confirms, or this event is generated.
- }
- Event::HTLCIntercepted { .. } => {}
+ },
+ Event::HTLCIntercepted { .. } => {},
Event::BumpTransaction(event) => bump_tx_event_handler.handle_event(&event),
Event::ConnectionNeeded { node_id, addresses } => {
tokio::spawn(async move {
}
}
});
- }
+ },
}
}
Err(e) => {
println!("Failed to connect to bitcoind client: {}", e);
return;
- }
+ },
};
// Check that the bitcoind we've connected to is running the network we expect
Ok(mut f) => {
Write::write_all(&mut f, &key).expect("Failed to write node keys seed to disk");
f.sync_all().expect("Failed to sync node keys seed to disk");
- }
+ },
Err(e) => {
println!("ERROR: Unable to create keys seed file {}: {}", keys_seed_path, e);
return;
- }
+ },
}
key
};
}
}
}
- }
+ },
Err(e) => println!("ERROR: errored reading channel peer info from disk: {:?}", e),
}
}
match file.read_exact(&mut [0; 1]) {
Ok(_) => {
file.seek(SeekFrom::Current(-1)).unwrap();
- }
+ },
Err(e) if e.kind() == io::ErrorKind::UnexpectedEof => break,
Err(e) => Err(e).unwrap(),
}