diff --git a/bindings/follow.go b/bindings/follow.go index e676d506002bf53e4b58c5fb1de5fafe409f69bc..482bbd9cd83ab254ee2677a494d8e720df67c88d 100644 --- a/bindings/follow.go +++ b/bindings/follow.go @@ -8,6 +8,7 @@ package bindings import ( + "encoding/json" "fmt" "time" @@ -92,17 +93,32 @@ func (c *Cmix) NetworkFollowerStatus() int { return int(c.api.NetworkFollowerStatus()) } +// NodeRegistrationReport is the report structure which +// Cmix.GetNodeRegistrationStatus returns JSON marshalled. +type NodeRegistrationReport struct { + NumberOfNodesRegistered int + NumberOfNodes int +} + // GetNodeRegistrationStatus returns the current state of node registration. // // Returns: -// - []int - The 0th element represents the number of nodes with which the user is registered. -// The 1st element represents the number of nodes present in the NDF. -// - An error will most likely occur if the network is unhealthy. -func (c *Cmix) GetNodeRegistrationStatus() ([]int, error) { - results := make([]int, 2) - var err error - results[0], results[1], err = c.api.GetNodeRegistrationStatus() - return results, err +// - []bye - A marshalled NodeRegistrationReport containing the number of +// nodes the user is registered with and the number of nodes present in the NDF. +// - An error if it cannot get the node registration status. The most likely cause +// is that the network is unhealthy. +func (c *Cmix) GetNodeRegistrationStatus() ([]byte, error) { + numNodesRegistered, numNodes, err := c.api.GetNodeRegistrationStatus() + if err != nil { + return nil, err + } + + nodeRegReport := NodeRegistrationReport{ + NumberOfNodesRegistered: numNodesRegistered, + NumberOfNodes: numNodes, + } + + return json.Marshal(nodeRegReport) } // HasRunningProcessies checks if any background threads are running and returns diff --git a/bindings/ud.go b/bindings/ud.go index 243d24b55746662f3a69a3d7d7a83588ce7f89ef..c5d8fc2e75019557ef5d2199a044b4a395c9b141 100644 --- a/bindings/ud.go +++ b/bindings/ud.go @@ -144,8 +144,8 @@ func LoadOrNewUserDiscovery(e2eID int, follower UdNetworkStatus, // Parameters: // - e2eID - e2e object ID in the tracker // - follower - network follower func wrapped in UdNetworkStatus -// - emailFactJson - a JSON marshalled email fact.Fact -// - phoneFactJson - a JSON marshalled phone fact.Fact +// - emailFactJson - nullable JSON marshalled email fact.Fact +// - phoneFactJson - nullable JSON marshalled phone fact.Fact func NewUdManagerFromBackup(e2eID int, follower UdNetworkStatus, emailFactJson, phoneFactJson []byte) (*UserDiscovery, error) { @@ -156,14 +156,18 @@ func NewUdManagerFromBackup(e2eID int, follower UdNetworkStatus, emailFactJson, } var email, phone fact.Fact - err = json.Unmarshal(emailFactJson, &email) - if err != nil { - return nil, err + if emailFactJson != nil { + err = json.Unmarshal(emailFactJson, &email) + if err != nil { + return nil, err + } } - err = json.Unmarshal(phoneFactJson, &phone) - if err != nil { - return nil, err + if phoneFactJson != nil { + err = json.Unmarshal(phoneFactJson, &phone) + if err != nil { + return nil, err + } } UdNetworkStatusFn := func() xxdk.Status {