lncli: add custom data payment flag
This commit is contained in:
parent
daa08be62a
commit
d978b55701
@ -2091,6 +2091,14 @@ var (
|
||||
Usage: "pubkey of the last hop (penultimate node in the path) " +
|
||||
"to route through for this payment",
|
||||
}
|
||||
|
||||
dataFlag = cli.StringFlag{
|
||||
Name: "data",
|
||||
Usage: "attach custom data to the payment. The required " +
|
||||
"format is: <record_id>=<hex_value>,<record_id>=" +
|
||||
"<hex_value>,.. For example: --data 3438382=0a21ff. " +
|
||||
"Custom record ids start from 65536.",
|
||||
}
|
||||
)
|
||||
|
||||
// paymentFlags returns common flags for sendpayment and payinvoice.
|
||||
@ -2127,6 +2135,7 @@ func paymentFlags() []cli.Flag {
|
||||
Name: "allow_self_payment",
|
||||
Usage: "allow sending a circular payment to self",
|
||||
},
|
||||
dataFlag,
|
||||
}
|
||||
}
|
||||
|
||||
@ -2270,8 +2279,9 @@ func sendPayment(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
req := &lnrpc.SendRequest{
|
||||
Dest: destNode,
|
||||
Amt: amount,
|
||||
Dest: destNode,
|
||||
Amt: amount,
|
||||
DestCustomRecords: make(map[uint64][]byte),
|
||||
}
|
||||
|
||||
var rHash []byte
|
||||
@ -2286,9 +2296,10 @@ func sendPayment(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
req.DestCustomRecords = map[uint64][]byte{
|
||||
record.KeySendType: preimage[:],
|
||||
}
|
||||
// Set the preimage. If the user supplied a preimage with the
|
||||
// data flag, the preimage that is set here will be overwritten
|
||||
// later.
|
||||
req.DestCustomRecords[record.KeySendType] = preimage[:]
|
||||
|
||||
hash := preimage.Hash()
|
||||
rHash = hash[:]
|
||||
@ -2355,6 +2366,33 @@ func sendPaymentRequest(ctx *cli.Context, req *lnrpc.SendRequest) error {
|
||||
|
||||
req.AllowSelfPayment = ctx.Bool("allow_self_payment")
|
||||
|
||||
// Parse custom data records.
|
||||
data := ctx.String(dataFlag.Name)
|
||||
if data != "" {
|
||||
records := strings.Split(data, ",")
|
||||
for _, r := range records {
|
||||
kv := strings.Split(r, "=")
|
||||
if len(kv) != 2 {
|
||||
return errors.New("invalid data format: " +
|
||||
"multiple equal signs in record")
|
||||
}
|
||||
|
||||
recordID, err := strconv.ParseUint(kv[0], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid data format: %v",
|
||||
err)
|
||||
}
|
||||
|
||||
hexValue, err := hex.DecodeString(kv[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid data format: %v",
|
||||
err)
|
||||
}
|
||||
|
||||
req.DestCustomRecords[recordID] = hexValue
|
||||
}
|
||||
}
|
||||
|
||||
amt := req.Amt
|
||||
|
||||
if req.PaymentRequest != "" {
|
||||
@ -2434,8 +2472,9 @@ func payInvoice(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
req := &lnrpc.SendRequest{
|
||||
PaymentRequest: payReq,
|
||||
Amt: ctx.Int64("amt"),
|
||||
PaymentRequest: payReq,
|
||||
Amt: ctx.Int64("amt"),
|
||||
DestCustomRecords: make(map[uint64][]byte),
|
||||
}
|
||||
|
||||
return sendPaymentRequest(ctx, req)
|
||||
|
Loading…
Reference in New Issue
Block a user