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 = new VersionService.VersionServiceClient(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);
        }
Example #2
0
 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);
 }
Example #3
0
 public static IncompatibleVersionException Patch(SemanticVersion required, SemanticVersion actual) =>
     new IncompatibleVersionException("patch", required, actual);
Example #4
0
 public static IncompatibleVersionException Minor(SemanticVersion required, SemanticVersion actual) =>
     new IncompatibleVersionException("minor", required, actual);
Example #5
0
 private IncompatibleVersionException(string whatVersion, SemanticVersion required, SemanticVersion actual)
     : base($"Incompatible {whatVersion} versions: required={required} actual={actual}")
 { }