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 1
1
package commands
2
2
3
3
import (
4
- "bytes"
5
4
"context"
6
5
"encoding/json"
7
6
"fmt"
@@ -12,6 +11,7 @@ import (
12
11
lfn "github.com/lightningnetwork/lnd/fn/v2"
13
12
"github.com/lightningnetwork/lnd/signal"
14
13
"github.com/urfave/cli"
14
+ "google.golang.org/protobuf/encoding/protojson"
15
15
"google.golang.org/protobuf/proto"
16
16
)
17
17
@@ -193,16 +193,36 @@ func getContext() context.Context {
193
193
return ctxc
194
194
}
195
195
196
+ // printJSON prints any JSON serializable object to stdout in a pretty format.
196
197
func 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
+
198
218
if err != nil {
199
219
Fatal (err )
200
220
}
201
221
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
+ }
206
226
}
207
227
208
228
func printRespJSON (resp proto.Message ) {
Original file line number Diff line number Diff line change 182
182
allows users to specify the amount to send to a V2 address that allows custom
183
183
amounts (which is the case when a V2 address is created with an amount of 0).
184
184
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
+
185
189
# Improvements
186
190
187
191
## Functional Updates
You can’t perform that action at this time.
0 commit comments