lnd
lnd copied to clipboard
cli: add invoice handling route hints
Change Description
This PR adds route hints to the add invoice cli. This change mimics the RPC addinvoice method, which allows for route hints to be added. Several things to note:
- The route hints are a list of json objects encoded as a string
- The route hints are only valid if the
--private
flag is also included
Steps to Test
Simply start up LND with these changes and attempt to add an invoice with the route hints. I've used the following bash script to do this:
function getRouteHint() {
local node_name=$1
# Execute the 'getinfo' command and extract the public key
local pub_key_output=$(run $node_name getinfo)
local pub_key=$(echo "$pub_key_output" | jq -r '.identity_pubkey // empty')
# Execute the 'listchannels' command and extract the channel ID, ensuring it remains as a numerical value
local channel_id_output=$(run $node_name listchannels)
local channel_id=$(echo "$channel_id_output" | jq -r '.channels[0].chan_id // empty')
# Check if either public key or channel ID are empty, indicating a problem
if [ -z "$pub_key" ] || [ -z "$channel_id" ]; then
echo "Error: Public key or channel ID not found for $node_name." >&2
return 1
fi
# Ensure channel_id is numeric (important for Go struct expectation)
local numeric_channel_id=$(echo "$channel_id" | jq -r 'tonumber')
# Construct the JSON structure for the route hint, ensuring types match expected schema
local route_hint_json=$(echo "{\"node_id\":\"$pub_key\",\"chan_id\":$numeric_channel_id,\"fee_base_msat\":1000,\"fee_proportional_millionths\":100,\"cltv_expiry_delta\":40}" | jq -c .)
# Encode the JSON string to Base64
echo "$route_hint_json"
}
Then simply run:
local payment_request1_json=$(run olivia addinvoice --private --route_hints "$(getRouteHint)" --amt=1000000)
You should see the relevant route hints encoded in the payment request data.
Pull Request Checklist
Testing
- [ ] Your PR passes all CI checks.
- [ ] Tests covering the positive and negative (error paths) are included.
- [ ] Bug fixes contain tests triggering the bug to prevent regressions.
Code Style and Documentation
- [ ] The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.
- [ ] Commits follow the Ideal Git Commit Structure.
- [ ] Any new logging statements use an appropriate subsystem and logging level.
- [ ] Any new lncli commands have appropriate tags in the comments for the rpc in the proto file.
- [ ] There is a change description in the release notes, or
[skip ci]
in the commit message for small changes.
📝 Please see our Contribution Guidelines for further guidance.