github.com/ledgerwatch/erigon-lib@v1.0.0/gointerfaces/version.go (about)

     1  /*
     2     Copyright 2021 Erigon contributors
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package gointerfaces
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/ledgerwatch/erigon-lib/gointerfaces/types"
    23  )
    24  
    25  type Version struct {
    26  	Major, Minor, Patch uint32 // interface Version of the client - to perform compatibility check when opening
    27  }
    28  
    29  func VersionFromProto(r *types.VersionReply) Version {
    30  	return Version{Major: r.Major, Minor: r.Minor, Patch: r.Patch}
    31  }
    32  
    33  // EnsureVersion - Default policy: allow only patch difference
    34  func EnsureVersion(local Version, remote *types.VersionReply) bool {
    35  	if remote.Major != local.Major {
    36  		return false
    37  	}
    38  	if remote.Minor != local.Minor {
    39  		return false
    40  	}
    41  	return true
    42  }
    43  
    44  func (v Version) String() string {
    45  	return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
    46  }