public async Task LoadOrCreateDefaultFileAsync(string path, CancellationToken cancel) { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException(nameof(path)); } Network = Network.Main; BitcoinRpcUser = "******"; BitcoinRpcPassword = "******"; DenominationAlgorithm = Configuration.DenominationAlgorithm.FixedUSD; DenominationUSD = 10000; DenominationBTC = new Money(1m, MoneyUnit.BTC); MinimumAnonymitySet = 3; MaximumAnonymitySet = 100; // for now, in theory 300-400 should be fine, too StartingAnonymitySet = 7; AverageTimeToSpendInInputRegistrationInSeconds = 180; // 3min InputRegistrationPhaseTimeoutInSeconds = 86400; // one day ConnectionConfirmationPhaseTimeoutInSeconds = 60; OutputRegistrationPhaseTimeoutInSeconds = 60; SigningPhaseTimeoutInSeconds = 60; MaximumInputsPerAlices = 7; FallBackSatoshiFeePerBytes = 300; FeeConfirmationTarget = 144; FeeEstimationMode = EstimateSmartFeeMode.Conservative; if (!File.Exists(path)) { Console.WriteLine($"Config file did not exist. Created at path: {path}"); } else { string jsonString = await File.ReadAllTextAsync(path, Encoding.UTF8, cancel); var config = JsonConvert.DeserializeObject <Config>(jsonString); Network = config.Network ?? Network; BitcoinRpcUser = config.BitcoinRpcUser ?? BitcoinRpcUser; BitcoinRpcPassword = config.BitcoinRpcPassword ?? BitcoinRpcPassword; DenominationAlgorithm = config.DenominationAlgorithm ?? DenominationAlgorithm; DenominationUSD = config.DenominationUSD ?? DenominationUSD; DenominationBTC = config.DenominationBTC ?? DenominationBTC; MinimumAnonymitySet = config.MinimumAnonymitySet ?? MinimumAnonymitySet; MaximumAnonymitySet = config.MaximumAnonymitySet ?? MaximumAnonymitySet; StartingAnonymitySet = config.StartingAnonymitySet ?? StartingAnonymitySet; AverageTimeToSpendInInputRegistrationInSeconds = config.AverageTimeToSpendInInputRegistrationInSeconds ?? AverageTimeToSpendInInputRegistrationInSeconds; InputRegistrationPhaseTimeoutInSeconds = config.InputRegistrationPhaseTimeoutInSeconds ?? InputRegistrationPhaseTimeoutInSeconds; ConnectionConfirmationPhaseTimeoutInSeconds = config.ConnectionConfirmationPhaseTimeoutInSeconds ?? ConnectionConfirmationPhaseTimeoutInSeconds; OutputRegistrationPhaseTimeoutInSeconds = config.OutputRegistrationPhaseTimeoutInSeconds ?? OutputRegistrationPhaseTimeoutInSeconds; SigningPhaseTimeoutInSeconds = config.SigningPhaseTimeoutInSeconds ?? SigningPhaseTimeoutInSeconds; MaximumInputsPerAlices = config.MaximumInputsPerAlices ?? MaximumInputsPerAlices; FallBackSatoshiFeePerBytes = config.FallBackSatoshiFeePerBytes ?? FallBackSatoshiFeePerBytes; FeeConfirmationTarget = config.FeeConfirmationTarget ?? FeeConfirmationTarget; FeeEstimationMode = config.FeeEstimationMode ?? FeeEstimationMode; } await ToFileAsync(path, cancel); }
/// <remarks> /// Throws OperationCancelledException if <paramref name="cancel"/> is set. /// </remarks> public async Task <SynchronizeResponse> GetSynchronizeAsync(uint256 bestKnownBlockHash, int count, EstimateSmartFeeMode?estimateMode = null, CancellationToken cancel = default) { string relativeUri = $"/api/v{ApiVersion}/btc/batch/synchronize?bestKnownBlockHash={bestKnownBlockHash}&maxNumberOfFilters={count}"; if (estimateMode is { })
/// <remarks> /// Throws OperationCancelledException if <paramref name="cancel"/> is set. /// </remarks> public async Task <SynchronizeResponse> GetSynchronizeAsync(uint256 bestKnownBlockHash, int count, EstimateSmartFeeMode?estimateMode = null, CancellationToken cancel = default) { string relativeUri = $"/api/v{Constants.BackendMajorVersion}/btc/batch/synchronize?bestKnownBlockHash={bestKnownBlockHash}&maxNumberOfFilters={count}"; if (estimateMode != null) { relativeUri = $"{relativeUri}&estimateSmartFeeMode={estimateMode}"; } using var response = await TorClient.SendAndRetryAsync(HttpMethod.Get, HttpStatusCode.OK, relativeUri, cancel : cancel); if (response.StatusCode != HttpStatusCode.OK) { await response.ThrowRequestExceptionFromContentAsync(); } using HttpContent content = response.Content; var ret = await content.ReadAsJsonAsync <SynchronizeResponse>(); return(ret); }