[#270] netmap: Export NodeState type

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-20 10:34:27 +03:00 committed by fyrchik
parent 70ae2c94e1
commit 2d0101033b

View file

@ -20,10 +20,11 @@ type (
netmapNode struct { netmapNode struct {
node storageNode node storageNode
state nodeState state NodeState
} }
nodeState int // NodeState is an enumeration for node states.
NodeState int
record struct { record struct {
key []byte key []byte
@ -52,7 +53,7 @@ const (
const ( const (
// V2 format // V2 format
_ nodeState = iota _ NodeState = iota
OnlineState OnlineState
OfflineState OfflineState
) )
@ -312,7 +313,7 @@ func UpdateState(state int, publicKey interop.PublicKey) {
common.CheckAlphabetWitness(common.AlphabetAddress()) common.CheckAlphabetWitness(common.AlphabetAddress())
} }
switch nodeState(state) { switch NodeState(state) {
case OfflineState: case OfflineState:
removeFromNetmap(ctx, publicKey) removeFromNetmap(ctx, publicKey)
runtime.Log("remove storage node from the network map") runtime.Log("remove storage node from the network map")
@ -325,7 +326,7 @@ func UpdateState(state int, publicKey interop.PublicKey) {
// UpdateStateIR method tries to change the node state in the network map. // UpdateStateIR method tries to change the node state in the network map.
// Should only be invoked in notary-enabled environment by alphabet. // Should only be invoked in notary-enabled environment by alphabet.
func UpdateStateIR(state nodeState, publicKey interop.PublicKey) { func UpdateStateIR(state NodeState, publicKey interop.PublicKey) {
ctx := storage.GetContext() ctx := storage.GetContext()
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool) notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
if notaryDisabled { if notaryDisabled {
@ -648,7 +649,7 @@ func removeFromNetmap(ctx storage.Context, key interop.PublicKey) {
storage.Delete(ctx, storageKey) storage.Delete(ctx, storageKey)
} }
func filterNetmap(ctx storage.Context, st nodeState) []storageNode { func filterNetmap(ctx storage.Context, st NodeState) []storageNode {
var ( var (
netmap = getNetmapNodes(ctx) netmap = getNetmapNodes(ctx)
result = []storageNode{} result = []storageNode{}