@@ -2,6 +2,7 @@ package name
22
33import (
44 "bytes"
5+ "encoding/json"
56 "fmt"
67 "io"
78 "strings"
@@ -15,6 +16,7 @@ import (
1516 cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"
1617 "github.com/ipld/go-ipld-prime"
1718 "github.com/ipld/go-ipld-prime/codec/dagcbor"
19+ "github.com/ipld/go-ipld-prime/codec/dagjson"
1820 ic "github.com/libp2p/go-libp2p/core/crypto"
1921 "github.com/libp2p/go-libp2p/core/peer"
2022 mbase "github.com/multiformats/go-multibase"
@@ -156,11 +158,26 @@ var IpnsInspectCmd = &cmds.Command{
156158 }
157159
158160 if len (entry .Data ) != 0 {
161+ // This is hacky. The variable node (datamodel.Node) doesn't directly marshal
162+ // to JSON. Therefore, we need to first decode from DAG-CBOR, then encode in
163+ // DAG-JSON and finally unmarshal it from JSON. Since DAG-JSON is a subset
164+ // of JSON, that should work. Then, we can store the final value in the
165+ // result.Entry.Data for further inspection.
159166 node , err := ipld .Decode (entry .Data , dagcbor .Decode )
160167 if err != nil {
161168 return err
162169 }
163- result .Entry .Data = node
170+
171+ var buf bytes.Buffer
172+ err = dagjson .Encode (node , & buf )
173+ if err != nil {
174+ return err
175+ }
176+
177+ err = json .Unmarshal (buf .Bytes (), & result .Entry .Data )
178+ if err != nil {
179+ return err
180+ }
164181 }
165182
166183 validity , err := ipns .GetEOL (& entry )
@@ -200,9 +217,9 @@ var IpnsInspectCmd = &cmds.Command{
200217 }
201218 }
202219
203- return cmds .EmitOnce (res , & result )
220+ return cmds .EmitOnce (res , result )
204221 },
205- Type : & IpnsInspectResult {},
222+ Type : IpnsInspectResult {},
206223 Encoders : cmds.EncoderMap {
207224 cmds .Text : cmds .MakeTypedEncoder (func (req * cmds.Request , w io.Writer , out * IpnsInspectResult ) error {
208225 tw := tabwriter .NewWriter (w , 0 , 0 , 1 , ' ' , 0 )
@@ -220,7 +237,12 @@ var IpnsInspectCmd = &cmds.Command{
220237 fmt .Fprintf (tw , "PublicKey:\t %q\n " , out .Entry .PublicKey )
221238 fmt .Fprintf (tw , "Signature V1:\t %q\n " , out .Entry .SignatureV1 )
222239 fmt .Fprintf (tw , "Signature V2:\t %q\n " , out .Entry .SignatureV2 )
223- fmt .Fprintf (tw , "Data:\t %q\n " , out .Entry .Data )
240+
241+ data , err := json .Marshal (out .Entry .Data )
242+ if err != nil {
243+ return err
244+ }
245+ fmt .Fprintf (tw , "Data:\t %s\n " , string (data ))
224246
225247 if out .Validation == nil {
226248 tw .Flush ()
0 commit comments