github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/identity/registry/status.go (about)

     1  /*
     2   * Copyright (C) 2019 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package registry
    19  
    20  import (
    21  	"time"
    22  
    23  	"github.com/mysteriumnetwork/node/identity"
    24  )
    25  
    26  // RegistrationStatus represents all the possible registration statuses
    27  type RegistrationStatus int
    28  
    29  const (
    30  	// Registered represents a registration
    31  	Registered RegistrationStatus = iota
    32  	// Unregistered represents an unregistered identity
    33  	Unregistered
    34  	// InProgress shows that registration is still in progress
    35  	InProgress
    36  	// RegistrationError shows that an error occurred during registration
    37  	RegistrationError
    38  	// Unknown is returned when there was an error fetching registration status and it is now
    39  	// impossible to determine. A request should be retried to get the status again.
    40  	Unknown
    41  )
    42  
    43  // String converts registration to human readable notation
    44  func (rs RegistrationStatus) String() string {
    45  	return [...]string{
    46  		"Registered",
    47  		"Unregistered",
    48  		"InProgress",
    49  		"RegistrationError",
    50  		"Unknown",
    51  	}[rs]
    52  }
    53  
    54  // Registered returns flag if registration is in successful status
    55  func (rs RegistrationStatus) Registered() bool {
    56  	switch rs {
    57  	case Registered:
    58  		return true
    59  	default:
    60  		return false
    61  	}
    62  }
    63  
    64  // StoredRegistrationStatus represents a registration status that is being stored in our local DB
    65  type StoredRegistrationStatus struct {
    66  	RegistrationStatus  RegistrationStatus
    67  	Identity            identity.Identity
    68  	ChainID             int64
    69  	RegistrationRequest IdentityRegistrationRequest
    70  	UpdatedAt           time.Time
    71  }
    72  
    73  // FromEvent constructs a stored registration status from transactor.IdentityRegistrationRequest
    74  func (srs StoredRegistrationStatus) FromEvent(status RegistrationStatus, ev IdentityRegistrationRequest) StoredRegistrationStatus {
    75  	return StoredRegistrationStatus{
    76  		RegistrationStatus:  status,
    77  		RegistrationRequest: ev,
    78  		Identity:            identity.FromAddress(ev.Identity),
    79  		ChainID:             ev.ChainID,
    80  	}
    81  }
    82  
    83  // AppTopicIdentityRegistration represents the registration event topic.
    84  const AppTopicIdentityRegistration = "registration_event_topic"
    85  
    86  // AppEventIdentityRegistration represents the registration event payload.
    87  type AppEventIdentityRegistration struct {
    88  	ID      identity.Identity
    89  	Status  RegistrationStatus
    90  	ChainID int64
    91  }