lncli: send key
Extend lncli with a flag that indicates the intention to send a spontaneous payment. lncli will generate a preimage/hash combination and send the preimage as a custom record to the recipient.
This commit is contained in:
parent
c08865f4ae
commit
b1206f67c2
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -24,6 +25,8 @@ import (
|
|||||||
"github.com/lightninglabs/protobuf-hex-display/proto"
|
"github.com/lightninglabs/protobuf-hex-display/proto"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
|
"github.com/lightningnetwork/lnd/record"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/walletunlocker"
|
"github.com/lightningnetwork/lnd/walletunlocker"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@ -2164,6 +2167,10 @@ var sendPaymentCommand = cli.Command{
|
|||||||
Name: "final_cltv_delta",
|
Name: "final_cltv_delta",
|
||||||
Usage: "the number of blocks the last hop has to reveal the preimage",
|
Usage: "the number of blocks the last hop has to reveal the preimage",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "key_send",
|
||||||
|
Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]",
|
||||||
|
},
|
||||||
),
|
),
|
||||||
Action: sendPayment,
|
Action: sendPayment,
|
||||||
}
|
}
|
||||||
@ -2268,6 +2275,23 @@ func sendPayment(ctx *cli.Context) error {
|
|||||||
|
|
||||||
var rHash []byte
|
var rHash []byte
|
||||||
|
|
||||||
|
if ctx.Bool("key_send") {
|
||||||
|
if ctx.IsSet("payment_hash") {
|
||||||
|
return errors.New("cannot set payment hash when using " +
|
||||||
|
"key send")
|
||||||
|
}
|
||||||
|
var preimage lntypes.Preimage
|
||||||
|
if _, err := rand.Read(preimage[:]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.DestCustomRecords = map[uint64][]byte{
|
||||||
|
record.KeySendType: preimage[:],
|
||||||
|
}
|
||||||
|
|
||||||
|
hash := preimage.Hash()
|
||||||
|
rHash = hash[:]
|
||||||
|
} else {
|
||||||
switch {
|
switch {
|
||||||
case ctx.IsSet("payment_hash"):
|
case ctx.IsSet("payment_hash"):
|
||||||
rHash, err = hex.DecodeString(ctx.String("payment_hash"))
|
rHash, err = hex.DecodeString(ctx.String("payment_hash"))
|
||||||
@ -2277,6 +2301,7 @@ func sendPayment(ctx *cli.Context) error {
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("payment hash argument missing")
|
return fmt.Errorf("payment hash argument missing")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user