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); }
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); }
public static IncompatibleVersionException Patch(SemanticVersion required, SemanticVersion actual) => new IncompatibleVersionException("patch", required, actual);
public static IncompatibleVersionException Minor(SemanticVersion required, SemanticVersion actual) => new IncompatibleVersionException("minor", required, actual);
private IncompatibleVersionException(string whatVersion, SemanticVersion required, SemanticVersion actual) : base($"Incompatible {whatVersion} versions: required={required} actual={actual}") { }