diff --git a/pkg/netmap/node_info.go b/pkg/netmap/node_info.go index 327e77ab..81f27679 100644 --- a/pkg/netmap/node_info.go +++ b/pkg/netmap/node_info.go @@ -214,6 +214,21 @@ func NewNodeInfoFromV2(i *netmap.NodeInfo) *NodeInfo { return (*NodeInfo)(i) } +// NodeInfoToJSON encodes NodeInfo to JSON format. +func NodeInfoToJSON(i *NodeInfo) ([]byte, error) { + return netmap.NodeInfoToJSON(i.ToV2()) +} + +// NodeInfoFromJSON decodes NodeInfo from JSON-encoded data. +func NodeInfoFromJSON(data []byte) (*NodeInfo, error) { + i, err := netmap.NodeInfoFromJSON(data) + if err != nil { + return nil, err + } + + return NewNodeInfoFromV2(i), nil +} + // ToV2 converts NodeInfo to v2 NodeInfo. func (i *NodeInfo) ToV2() *netmap.NodeInfo { return (*netmap.NodeInfo)(i) diff --git a/pkg/netmap/node_info_test.go b/pkg/netmap/node_info_test.go index 75de15dc..366b9ffa 100644 --- a/pkg/netmap/node_info_test.go +++ b/pkg/netmap/node_info_test.go @@ -140,3 +140,19 @@ func TestNodeInfo_Attributes(t *testing.T) { require.Equal(t, as, i.Attributes()) } + +func TestNodeInfoJSON(t *testing.T) { + i := NewNodeInfo() + i.SetPublicKey([]byte{1, 2, 3}) + i.SetAddress("some node address") + i.SetState(NodeStateOnline) + i.SetAttributes(testNodeAttribute(), testNodeAttribute()) + + j, err := NodeInfoToJSON(i) + require.NoError(t, err) + + i2, err := NodeInfoFromJSON(j) + require.NoError(t, err) + + require.Equal(t, i, i2) +}