File tree Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 11package commands
22
33import (
4- "bytes"
54 "context"
65 "encoding/json"
76 "fmt"
@@ -12,6 +11,7 @@ import (
1211 lfn "github.com/lightningnetwork/lnd/fn/v2"
1312 "github.com/lightningnetwork/lnd/signal"
1413 "github.com/urfave/cli"
14+ "google.golang.org/protobuf/encoding/protojson"
1515 "google.golang.org/protobuf/proto"
1616)
1717
@@ -193,16 +193,36 @@ func getContext() context.Context {
193193 return ctxc
194194}
195195
196+ // printJSON prints any JSON serializable object to stdout in a pretty format.
196197func printJSON (resp interface {}) {
197- b , err := json .Marshal (resp )
198+ var (
199+ b []byte
200+ err error
201+ )
202+
203+ switch m := resp .(type ) {
204+ case proto.Message :
205+ mo := protojson.MarshalOptions {
206+ Multiline : true ,
207+ Indent : "\t " ,
208+ EmitUnpopulated : true ,
209+ UseProtoNames : true ,
210+ }
211+ b , err = mo .Marshal (m )
212+
213+ default :
214+ // This does not emit unpopulated fields.
215+ b , err = json .MarshalIndent (resp , "" , "\t " )
216+ }
217+
198218 if err != nil {
199219 Fatal (err )
200220 }
201221
202- var out bytes. Buffer
203- _ = json . Indent ( & out , b , "" , " \t " )
204- out . WriteString ( " \n " )
205- _ , _ = out . WriteTo ( os . Stdout )
222+ _ , err = os . Stdout . Write ( append ( b , '\n' ))
223+ if err != nil {
224+ Fatal ( err )
225+ }
206226}
207227
208228func printRespJSON (resp proto.Message ) {
Original file line number Diff line number Diff line change 182182 allows users to specify the amount to send to a V2 address that allows custom
183183 amounts (which is the case when a V2 address is created with an amount of 0).
184184
185+ - CLI JSON output [ now] ( https://github.com/lightninglabs/taproot-assets/pull/1821 )
186+ includes unset and zero-valued proto fields (e.g. transaction output indexes).
187+ This ensures consistent output shape across all proto messages.
188+
185189# Improvements
186190
187191## Functional Updates
You can’t perform that action at this time.
0 commit comments