Paymetheus.Rpc.SemanticVersion.AssertCompatible C# (CSharp) Method

AssertCompatible() public static method

public static AssertCompatible ( SemanticVersion required, SemanticVersion actual ) : void
required SemanticVersion
actual SemanticVersion
return void
        public static void AssertCompatible(SemanticVersion required, SemanticVersion actual)
        {
            if (required.Major != actual.Major)
                throw IncompatibleVersionException.Major(required, actual);
            if (required.Minor > actual.Minor)
                throw IncompatibleVersionException.Minor(required, actual);
            if (required.Minor == actual.Minor && required.Patch > actual.Patch)
                throw IncompatibleVersionException.Patch(required, actual);
        }
    }

Usage Example

Example #1
0
        public static async Task <WalletClient> ConnectAsync(string networkAddress, string rootCertificate)
        {
            if (networkAddress == null)
            {
                throw new ArgumentNullException(nameof(networkAddress));
            }
            if (rootCertificate == null)
            {
                throw new ArgumentNullException(nameof(rootCertificate));
            }

            var channel  = new Channel(networkAddress, new SslCredentials(rootCertificate));
            var deadline = DateTime.UtcNow.AddSeconds(3);

            try
            {
                await channel.ConnectAsync(deadline);
            }
            catch (TaskCanceledException)
            {
                await channel.ShutdownAsync();

                throw new ConnectTimeoutException();
            }

            // Ensure the server is running a compatible version.
            var versionClient = VersionService.NewClient(channel);
            var response      = await versionClient.VersionAsync(new VersionRequest(), deadline : deadline);

            var serverVersion = new SemanticVersion(response.Major, response.Minor, response.Patch);

            SemanticVersion.AssertCompatible(RequiredRpcServerVersion, serverVersion);

            return(new WalletClient(channel));
        }