mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-04 18:01:57 +01:00
build+lncli: default to hex encoding for byte slices
This commit swaps out golang/protobuf/jsonpb for a custom variant that by default prints byte slices as hex, which is more useful for our setting. Some existing wrapper structs are removed as they can now be printed directly with the new jsonpb. !!! NOTE !!! This commit introduces a breaking change to lncli listinvoices since payment hashes and preimages will now be printed in hex instead of base64.
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -20,8 +19,9 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/lightninglabs/protobuf-hex-display/json"
|
||||
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
|
||||
"github.com/lightninglabs/protobuf-hex-display/proto"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@@ -2427,15 +2427,7 @@ func sendPaymentRequest(ctx *cli.Context, req *lnrpc.SendRequest) error {
|
||||
|
||||
paymentStream.CloseSend()
|
||||
|
||||
printJSON(struct {
|
||||
E string `json:"payment_error"`
|
||||
P string `json:"payment_preimage"`
|
||||
R *lnrpc.Route `json:"payment_route"`
|
||||
}{
|
||||
E: resp.PaymentError,
|
||||
P: hex.EncodeToString(resp.PaymentPreimage),
|
||||
R: resp.PaymentRoute,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
|
||||
// If we get a payment error back, we pass an error
|
||||
// up to main which eventually calls fatal() and returns
|
||||
@@ -2637,15 +2629,7 @@ func sendToRouteRequest(ctx *cli.Context, req *lnrpc.SendToRouteRequest) error {
|
||||
return err
|
||||
}
|
||||
|
||||
printJSON(struct {
|
||||
E string `json:"payment_error"`
|
||||
P string `json:"payment_preimage"`
|
||||
R *lnrpc.Route `json:"payment_route"`
|
||||
}{
|
||||
E: resp.PaymentError,
|
||||
P: hex.EncodeToString(resp.PaymentPreimage),
|
||||
R: resp.PaymentRoute,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -2762,15 +2746,7 @@ func addInvoice(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
printJSON(struct {
|
||||
RHash string `json:"r_hash"`
|
||||
PayReq string `json:"pay_req"`
|
||||
AddIndex uint64 `json:"add_index"`
|
||||
}{
|
||||
RHash: hex.EncodeToString(resp.RHash),
|
||||
PayReq: resp.PaymentRequest,
|
||||
AddIndex: resp.AddIndex,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -3856,14 +3832,11 @@ func exportChanBackup(ctx *cli.Context) error {
|
||||
|
||||
printJSON(struct {
|
||||
ChanPoint string `json:"chan_point"`
|
||||
ChanBackup string `json:"chan_backup"`
|
||||
ChanBackup []byte `json:"chan_backup"`
|
||||
}{
|
||||
ChanPoint: chanPoint.String(),
|
||||
ChanBackup: hex.EncodeToString(
|
||||
chanBackup.ChanBackup,
|
||||
),
|
||||
},
|
||||
)
|
||||
ChanPoint: chanPoint.String(),
|
||||
ChanBackup: chanBackup.ChanBackup,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3901,16 +3874,8 @@ func exportChanBackup(ctx *cli.Context) error {
|
||||
}.String())
|
||||
}
|
||||
|
||||
printJSON(struct {
|
||||
ChanPoints []string `json:"chan_points"`
|
||||
MultiChanBackup string `json:"multi_chan_backup"`
|
||||
}{
|
||||
ChanPoints: chanPoints,
|
||||
MultiChanBackup: hex.EncodeToString(
|
||||
chanBackup.MultiChanBackup.MultiChanBackup,
|
||||
),
|
||||
},
|
||||
)
|
||||
printRespJSON(chanBackup)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user