diff --git a/bindings/follow.go b/bindings/follow.go index 5d324f2e8d0336dc58b27290ad518d484e0193d0..08a9d0bffe2ed250c076b918c76926b0e2544cfa 100644 --- a/bindings/follow.go +++ b/bindings/follow.go @@ -115,33 +115,6 @@ type IsReadyInfo struct { HowClose float64 } -// IsReady returns true if at least percentReady of node registrations has -// completed. If not all have completed, then it returns false and howClose will -// be a percent (0-1) of node registrations completed. -// -// Parameters: -// - percentReady - The percentage of nodes required to be registered with to -// be ready. This is a number between 0 and 1. -// -// Returns: -// - JSON of [IsReadyInfo]. -func (c *Cmix) IsReady(percentReady float64) ([]byte, error) { - // Check if the network is currently healthy - if !c.api.GetCmix().IsHealthy() { - return json.Marshal(&IsReadyInfo{false, 0}) - } - - numReg, numNodes, err := c.api.GetNodeRegistrationStatus() - if err != nil { - jww.FATAL.Panicf("Failed to get node registration status: %+v", err) - } - - isReady := (float64(numReg) / float64(numNodes)) >= percentReady - howClose := float64(numReg) / (float64(numNodes) * percentReady) - - return json.Marshal(&IsReadyInfo{isReady, howClose}) -} - // NetworkFollowerStatus gets the state of the network follower. It returns a // status with the following values: // Stopped - 0 @@ -180,6 +153,21 @@ func (c *Cmix) GetNodeRegistrationStatus() ([]byte, error) { return json.Marshal(nodeRegReport) } +// IsReady returns true if at least percentReady of node registrations has +// completed. If not all have completed, then it returns false and howClose will +// be a percent (0-1) of node registrations completed. +// +// Parameters: +// - percentReady - The percentage of nodes required to be registered with to +// be ready. This is a number between 0 and 1. +// +// Returns: +// - JSON of [IsReadyInfo]. +func (c *Cmix) IsReady(percentReady float64) ([]byte, error) { + isReady, howClose := c.api.IsReady(percentReady) + return json.Marshal(&IsReadyInfo{isReady, howClose}) +} + // PauseNodeRegistrations stops all node registrations and returns a function to // resume them. // diff --git a/xxdk/cmix.go b/xxdk/cmix.go index 5189735c613fa7977af3ffad7c1b55d7750b64ef..8d4e8e4d90efb74c838fd790a4474695e97cbd8c 100644 --- a/xxdk/cmix.go +++ b/xxdk/cmix.go @@ -484,6 +484,28 @@ func (c *Cmix) GetNodeRegistrationStatus() (int, int, error) { return numRegistered, len(nodes) - numStale, nil } + + +// IsReady returns true if at least percentReady of node registrations has +// completed. If not all have completed, then it returns false and howClose will +// be a percent (0-1) of node registrations completed. +func (c *Cmix) IsReady(percentReady float64) (isReady bool, howClose float64) { + // Check if the network is currently healthy + if !c.network.IsHealthy() { + return false, 0 + } + + numReg, numNodes, err := c.GetNodeRegistrationStatus() + if err != nil { + jww.FATAL.Panicf("Failed to get node registration status: %+v", err) + } + + isReady = (float64(numReg) / float64(numNodes)) >= percentReady + howClose = float64(numReg) / (float64(numNodes) * percentReady) + + return isReady, howClose +} + // PauseNodeRegistrations stops all node registrations and returns a function to // resume them. func (c *Cmix) PauseNodeRegistrations(timeout time.Duration) error {