Esempio n. 1
0
        private static void Main(string[] args)
        {
            // If I want a list of up to date onions run it with '--getonions'.
            if (IsGetOnionsMode(args))
            {
                GetOnions();
                return;
            }

            // If I want a list of up to date onions run it with '--getonions'.
            if (IsReduceOnionsMode(args))
            {
                ReduceOnions();
                return;
            }

            // Start with digest creation and return if only digest creation.
            CreateDigests();

            OnlyCreateDigests = IsOnlyCreateDigestsMode(args);
            if (OnlyCreateDigests)
            {
                return;
            }

            // Only binaries mode is for deterministic builds.
            OnlyBinaries = IsOnlyBinariesMode(args);
            ReportStatus();

            if (DoPublish || OnlyBinaries)
            {
                Publish();
                if (OnlyBinaries)
                {
                    IoHelpers.OpenFolderInFileExplorer(BinDistDirectory);
                }
            }

            if (!OnlyBinaries)
            {
                if (DoSign)
                {
                    Sign();
                }

                if (DoRestoreProgramCs)
                {
                    RestoreProgramCs();
                }
            }
        }
Esempio n. 2
0
        public RegTestFixture()
        {
            RuntimeParams.SetDataDir(Path.Combine(Tests.Global.Instance.DataDir, nameof(RegTestFixture)));
            RuntimeParams.LoadAsync().GetAwaiter().GetResult();
            BackendRegTestNode = TestNodeBuilder.CreateAsync(callerMemberName: "RegTests").GetAwaiter().GetResult();

            var testnetBackendDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Tests", "Backend"));

            IoHelpers.DeleteRecursivelyWithMagicDustAsync(testnetBackendDir).GetAwaiter().GetResult();
            Thread.Sleep(100);
            Directory.CreateDirectory(testnetBackendDir);
            Thread.Sleep(100);
            var config = new Config(
                BackendRegTestNode.RpcClient.Network, BackendRegTestNode.RpcClient.CredentialString.ToString(),
                new IPEndPoint(IPAddress.Loopback, Network.Main.DefaultPort),
                new IPEndPoint(IPAddress.Loopback, Network.TestNet.DefaultPort),
                BackendRegTestNode.P2pEndPoint,
                new IPEndPoint(IPAddress.Loopback, Network.Main.RPCPort),
                new IPEndPoint(IPAddress.Loopback, Network.TestNet.RPCPort),
                BackendRegTestNode.RpcEndPoint);
            var configFilePath = Path.Combine(testnetBackendDir, "Config.json");

            config.SetFilePath(configFilePath);
            config.ToFileAsync().GetAwaiter().GetResult();

            var roundConfig         = CreateRoundConfig(Money.Coins(0.1m), Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);
            var roundConfigFilePath = Path.Combine(testnetBackendDir, "CcjRoundConfig.json");

            roundConfig.SetFilePath(roundConfigFilePath);
            roundConfig.ToFileAsync().GetAwaiter().GetResult();

            var conf = new ConfigurationBuilder()
                       .AddInMemoryCollection(new[] { new KeyValuePair <string, string>("datadir", testnetBackendDir) })
                       .Build();

            BackendEndPoint = $"http://localhost:{new Random().Next(37130, 38000)}/";
            BackendHost     = WebHost.CreateDefaultBuilder()
                              .UseStartup <Startup>()
                              .UseConfiguration(conf)
                              .UseWebRoot("../../../../WalletWasabi.Backend/wwwroot")
                              .UseUrls(BackendEndPoint)
                              .Build();
            Global = (Backend.Global)BackendHost.Services.GetService(typeof(Backend.Global));
            var hostInitializationTask = BackendHost.RunWithTasksAsync();

            Logger.LogInfo($"Started Backend webhost: {BackendEndPoint}");

            var delayTask = Task.Delay(3000);

            Task.WaitAny(delayTask, hostInitializationTask);             // Wait for server to initialize (Without this OSX CI will fail)
        }
Esempio n. 3
0
        public static async Task DisposeAsync()
        {
            try
            {
                await DisposeInWalletDependentServicesAsync();

                if (UpdateChecker != null)
                {
                    UpdateChecker?.Dispose();
                    Logger.LogInfo($"{nameof(UpdateChecker)} is stopped.", nameof(Global));
                }

                if (Synchronizer != null)
                {
                    Synchronizer?.Dispose();
                    Logger.LogInfo($"{nameof(Synchronizer)} is stopped.", nameof(Global));
                }

                if (AddressManagerFilePath != null)
                {
                    IoHelpers.EnsureContainingDirectoryExists(AddressManagerFilePath);
                    if (AddressManager != null)
                    {
                        AddressManager?.SavePeerFile(AddressManagerFilePath, Config.Network);
                        Logger.LogInfo($"{nameof(AddressManager)} is saved to `{AddressManagerFilePath}`.", nameof(Global));
                    }
                }

                if (Nodes != null)
                {
                    Nodes?.Dispose();
                    Logger.LogInfo($"{nameof(Nodes)} are disposed.", nameof(Global));
                }

                if (RegTestMemPoolServingNode != null)
                {
                    RegTestMemPoolServingNode.Disconnect();
                    Logger.LogInfo($"{nameof(RegTestMemPoolServingNode)} is disposed.", nameof(Global));
                }

                if (TorManager != null)
                {
                    TorManager?.Dispose();
                    Logger.LogInfo($"{nameof(TorManager)} is stopped.", nameof(Global));
                }
            }
            catch (Exception ex)
            {
                Logger.LogWarning(ex, nameof(Global));
            }
        }
    public LinkViewModel()
    {
        OpenBrowserCommand = ReactiveCommand.CreateFromTask <string>(
            async(link) =>
            await IoHelpers.OpenBrowserAsync(link));

        CopyLinkCommand = ReactiveCommand.CreateFromTask <string>(
            async(link) =>
        {
            if (Application.Current is { Clipboard: { } clipboard })
            {
                await clipboard.SetTextAsync(link);
            }
        });
        private async Task WriteOutHashAsync(byte[] hash)
        {
            try
            {
                IoHelpers.EnsureContainingDirectoryExists(DigestFilePath);

                await File.WriteAllBytesAsync(DigestFilePath, hash);
            }
            catch (Exception ex)
            {
                Logger.LogWarning <DigestableSafeMutexIoManager>("Failed to create digest.");
                Logger.LogInfo <DigestableSafeMutexIoManager>(ex);
            }
        }
Esempio n. 6
0
        private async Task InitializeTransactionsNoLockAsync(CancellationToken cancel)
        {
            try
            {
                IoHelpers.EnsureFileExists(TransactionsFileManager.FilePath);
                cancel.ThrowIfCancellationRequested();

                var allLines = await TransactionsFileManager.ReadAllLinesAsync(cancel).ConfigureAwait(false);

                var allTransactions = allLines
                                      .Select(x => SmartTransaction.FromLine(x, Network))
                                      .OrderByBlockchain();

                var added   = false;
                var updated = false;
                lock (TransactionsLock)
                {
                    foreach (var tx in allTransactions)
                    {
                        var(isAdded, isUpdated) = TryAddOrUpdateNoLockNoSerialization(tx);
                        if (isAdded)
                        {
                            added = true;
                        }
                        if (isUpdated)
                        {
                            updated = true;
                        }
                    }
                }

                if (added || updated)
                {
                    cancel.ThrowIfCancellationRequested();

                    // Another process worked into the file and appended the same transaction into it.
                    // In this case we correct the file by serializing the unique set.
                    await SerializeAllTransactionsNoLockAsync().ConfigureAwait(false);
                }
            }
            catch (Exception ex) when(ex is not OperationCanceledException)
            {
                // We found a corrupted entry. Stop here.
                // Delete the currupted file.
                // Do not try to autocorrect, because the internal data structures are throwing events that may confuse the consumers of those events.
                Logger.LogError($"{TransactionsFileManager.FileNameWithoutExtension} file got corrupted. Deleting it...");
                TransactionsFileManager.DeleteMe();
                throw;
            }
        }
Esempio n. 7
0
        public static async Task InitializeAsync(string dataDir, Network network, bool logFound = true)
        {
            Network = network;

            var fullBaseDirectory = Path.GetFullPath(AppContext.BaseDirectory);

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (!fullBaseDirectory.StartsWith('/'))
                {
                    fullBaseDirectory.Insert(0, "/");
                }
            }
            else
            {
                HwiPath = Path.Combine(fullBaseDirectory, "Hwi", "Software", "hwi-win64", "hwi.exe");
                return;
            }

            var    hwiDir  = Path.Combine(dataDir, "hwi");
            string hwiPath = $@"{hwiDir}/hwi";

            if (!File.Exists(hwiPath))
            {
                Logger.LogInfo($"HWI instance NOT found at `{hwiPath}`. Attempting to acquire it...", nameof(HwiProcessManager));
                await InstallHwiAsync(fullBaseDirectory, hwiDir);
            }
            else if (!IoHelpers.CheckExpectedHash(hwiPath, Path.Combine(fullBaseDirectory, "Hwi", "Software")))
            {
                Logger.LogInfo($"Updating HWI...", nameof(HwiProcessManager));

                string backupHwiDir = $"{hwiDir}_backup";
                if (Directory.Exists(backupHwiDir))
                {
                    Directory.Delete(backupHwiDir, true);
                }
                Directory.Move(hwiDir, backupHwiDir);

                await InstallHwiAsync(fullBaseDirectory, hwiDir);
            }
            else
            {
                if (logFound)
                {
                    Logger.LogInfo($"HWI instance found at `{hwiPath}`.", nameof(HwiProcessManager));
                }
            }

            HwiPath = hwiPath;
        }
Esempio n. 8
0
 private static async Task TryRemoveWorkingDirectoryAsync()
 {
     try
     {
         await IoHelpers.DeleteRecursivelyWithMagicDustAsync(WorkingDirectory);
     }
     catch (DirectoryNotFoundException)
     {
     }
     catch (Exception ex)
     {
         Logger.LogError <NodeBuilder>(ex);
     }
 }
Esempio n. 9
0
 public AboutViewModel(Global global) : base(global, "About")
 {
     OpenBrowserCommand = ReactiveCommand.Create <string>(x =>
     {
         try
         {
             IoHelpers.OpenBrowser(x);
         }
         catch (Exception ex)
         {
             Logger.LogError(ex);
         }
     });
 }
Esempio n. 10
0
        private async Task WriteOutHashAsync(byte[] hash)
        {
            try
            {
                IoHelpers.EnsureContainingDirectoryExists(DigestFilePath);

                await File.WriteAllBytesAsync(DigestFilePath, hash).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.LogWarning("Failed to create digest.");
                Logger.LogInfo(ex);
            }
        }
Esempio n. 11
0
    public async Task CreatesConfigAsync()
    {
        var workDir = Common.GetWorkDir();
        await IoHelpers.TryDeleteDirectoryAsync(workDir);

        CoordinatorParameters coordinatorParameters = new(workDir);

        using WabiSabiCoordinator coordinator = new(coordinatorParameters, NewMockRpcClient(), new CoinJoinIdStore());
        await coordinator.StartAsync(CancellationToken.None);

        Assert.True(File.Exists(Path.Combine(workDir, "WabiSabiConfig.json")));

        await coordinator.StopAsync(CancellationToken.None);
    }
Esempio n. 12
0
    public IndexStore(string workFolderPath, Network network, SmartHeaderChain smartHeaderChain)
    {
        WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
        IoHelpers.EnsureDirectoryExists(WorkFolderPath);
        var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");

        MatureIndexFileManager = new DigestableSafeIoManager(indexFilePath, useLastCharacterDigest: true);
        var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");

        ImmatureIndexFileManager = new DigestableSafeIoManager(immatureIndexFilePath, useLastCharacterDigest: true);

        Network          = network;
        StartingFilter   = StartingFilters.GetStartingFilter(Network);
        SmartHeaderChain = smartHeaderChain;
    }
Esempio n. 13
0
        public static KeyManager FromFile(string filePath)
        {
            filePath = Guard.NotNullOrEmptyOrWhitespace(nameof(filePath), filePath);

            if (!IoHelpers.TryGetSafestFileVersion(filePath, out var safestFile))
            {
                throw new FileNotFoundException($"Wallet file not found at: `{filePath}`.");
            }

            string jsonString = File.ReadAllText(safestFile, Encoding.UTF8);
            var    km         = JsonConvert.DeserializeObject <KeyManager>(jsonString);

            km.SetFilePath(filePath);
            return(km);
        }
    public CrashReportWindowViewModel(SerializableException serializedException)
    {
        SerializedException = serializedException;
        CancelCommand       = ReactiveCommand.Create(AppLifetimeHelper.Restart);
        NextCommand         = ReactiveCommand.Create(AppLifetimeHelper.Shutdown);

        OpenGitHubRepoCommand = ReactiveCommand.CreateFromTask(async() => await IoHelpers.OpenBrowserAsync(AboutViewModel.UserSupportLink));

        CopyTraceCommand = ReactiveCommand.CreateFromTask(async() =>
        {
            if (Application.Current is { Clipboard: { } clipboard })
            {
                await clipboard.SetTextAsync(Trace);
            }
        });
Esempio n. 15
0
        private static void Prepare()
        {
            Injector = new DependencyInjector(new string[]
            {
                IoHelpers.GetStartupPath(),
                IoHelpers.GetActionPath()
            });

            var templatePath = Path.Combine(IoHelpers.GetStartupPath(), "Templates");

            if (!Directory.Exists(templatePath))
            {
                Directory.CreateDirectory(templatePath);
            }
        }
        public BitcoinStore(
            string workFolderPath,
            Network network,
            IndexStore indexStore,
            AllTransactionStore transactionStore,
            MempoolService mempoolService)
        {
            WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
            IoHelpers.EnsureDirectoryExists(WorkFolderPath);

            Network          = Guard.NotNull(nameof(network), network);
            IndexStore       = indexStore;
            TransactionStore = transactionStore;
            MempoolService   = mempoolService;
        }
Esempio n. 17
0
        /// <param name="dataDir">Application data directory.</param>
        /// <param name="distributionFolderPath">Full path to folder containing Tor installation files.</param>
        public TorSettings(string dataDir, string distributionFolderPath, bool terminateOnExit, int?owningProcessId = null)
        {
            TorBinaryFilePath = GetTorBinaryFilePath();
            TorBinaryDir      = Path.Combine(MicroserviceHelpers.GetBinaryFolder(), "Tor");

            TorDataDir         = Path.Combine(dataDir, "tordata2");
            CookieAuthFilePath = Path.Combine(dataDir, "control_auth_cookie");
            LogFilePath        = Path.Combine(dataDir, "TorLogs.txt");
            IoHelpers.EnsureContainingDirectoryExists(LogFilePath);
            DistributionFolder = distributionFolderPath;
            TerminateOnExit    = terminateOnExit;
            OwningProcessId    = owningProcessId;
            GeoIpPath          = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip");
            GeoIp6Path         = Path.Combine(DistributionFolder, "Tor", "Geoip", "geoip6");
        }
    private void CreateFolders()
    {
        try
        {
            if (Directory.Exists(BlocksFolderPath) && Network == Network.RegTest)
            {
                Directory.Delete(BlocksFolderPath, true);
            }
        }
        catch (Exception ex)
        {
            Logger.LogDebug(ex);
        }

        IoHelpers.EnsureDirectoryExists(BlocksFolderPath);
    }
Esempio n. 19
0
        private void PrepareTestEnv(out string dir, out Network network, out string mempoolFile, out string txFile, out SmartTransaction uTx1, out SmartTransaction uTx2, out SmartTransaction uTx3, out SmartTransaction cTx1, out SmartTransaction cTx2, out SmartTransaction cTx3, [CallerFilePath] string callerFilePath = "", [CallerMemberName] string callerMemberName = "")
        {
            dir         = PrepareWorkDir(EnvironmentHelpers.ExtractFileName(callerFilePath), callerMemberName);
            network     = Network.TestNet;
            mempoolFile = Path.Combine(dir, "Mempool", "Transactions.dat");
            txFile      = Path.Combine(dir, "ConfirmedTransactions", Constants.ConfirmedTransactionsVersion, "Transactions.dat");
            IoHelpers.EnsureContainingDirectoryExists(mempoolFile);
            IoHelpers.EnsureContainingDirectoryExists(txFile);

            uTx1 = SmartTransaction.FromLine("34fc45781f2ac8e541b6045c2858c755dd2ab85e0ea7b5778b4d0cc191468571:01000000000102d5ae6e2612cdf8932d0e4f684d8ad9afdbca0afffba5c3dc0bf85f2b661bfb670000000000ffffffffbfd117908d5ba536624630519aaea7419605efa33bf1cb50c5ff7441f7b27a5b0100000000ffffffff01c6473d0000000000160014f9d25fe27812c3d35ad3819fcab8b95098effe15024730440220165730f8275434a5484b6aba3c71338a109b7cfd7380fdc18c6791a6afba9dee0220633b3b65313e57bdbd491d17232e6702912869d81461b4c939600d1cc99c06ec012102667c9fb272660cd6c06f853314b53c41da851f86024f9475ff15ea0636f564130247304402205e81562139231274cd7f705772c2810e34b7a291bd9882e6c567553babca9c7402206554ebd60d62a605a27bd4bf6482a533dd8dd35b12dc9d6abfa21738fdf7b57a012102b25dec5439a1aad8d901953a90d16252514a55f547fe2b85bc12e3f72cff1c4b00000000:Mempool::0::1570464578:False", network);
            uTx2 = SmartTransaction.FromLine("b5cd5b4431891d913a6fbc0e946798b6f730c8b97f95a5c730c24189bed24ce7:01000000010113145dd6264da43406a0819b6e2d791ec9281322f33944ef034c3307f38c330000000000ffffffff0220a10700000000001600149af662cf9564700b93bd46fac8b51f64f2adad2343a5070000000000160014f1938902267eac1ae527128fe7773657d2b757b900000000:Mempool::0::1555590391:False", network);
            uTx3 = SmartTransaction.FromLine("89e6788e63c5966fae0ccf6e85665ec62754f982b9593d7e3c4b78ac0e93208d:01000000000101f3e7c1bce1e0566800d8e6cae8f0d771a2ace8939cc6be7c8c21b05e590969530000000000ffffffff01cc2b0f0000000000160014e0ff6f42032bbfda63fabe0832b4ccb7be7350ae024730440220791e34413957c0f8348718d5d767f660657faf241801e74b5b81ac69e8912f60022041f3e9aeca137044565e1a81b6bcca74a88166436e5fa5f0e390448ac18fa5900121034dc07f3c26734591eb97f7e112888c3198d62bc3718106cba5a5688c62485b4500000000:Mempool::0::1555590448:False", network);
            cTx1 = SmartTransaction.FromLine("95374c1037eb5268c8ae6681eb26756459d19754d41b660c251e6f62df586d29:0100000001357852bdf4e75a4ee2afe213463ff8afbed977ea5459a310777322504254ffdf0100000000ffffffff0240420f0000000000160014dc992214c430bf306fe446e9bac1dfc4ad4d3ee368cc100300000000160014005340d370675c47f7a04eb186200dd98c3d463c00000000:1580176:0000000034522ee38f074e1f4330b9c2f20c6a2b9a96de6f474a5f5f8fa76e2b:307::1569940579:False", network);
            cTx2 = SmartTransaction.FromLine("af73b4c173da1bd24063e35a755babfa40728a282d6f56eeef4ce5a81ab26ee7:01000000013c81d2dcb25ad36781d1a6f9faa68f4a8b927f40e0b4e4b6184bb4761ebfc0dd0000000000ffffffff016f052e0000000000160014ae6e31ee9dae103f50979f761c2f9b44661da24f00000000:1580176:0000000034522ee38f074e1f4330b9c2f20c6a2b9a96de6f474a5f5f8fa76e2b:346::1569940633:False", network);
            cTx3 = SmartTransaction.FromLine("ebcef423f6b03ef89dce076b53e624c966381f76e5d8b2b5034d3615ae950b2f:01000000000101296d58df626f1e250c661bd45497d159647526eb8166aec86852eb37104c37950100000000ffffffff01facb100300000000160014d5461e0e7077d62c4cf9c18a4e9ba10efd4930340247304402206d2c5b2b182474531ed07587e44ea22b136a37d5ddbd35aa2d984da7be5f7e5202202abd8435d9856e3d0892dbd54e9c05f2a20d9d5f333247314b925947a480a2eb01210321dd0574c773a35d4a7ebf17bf8f974b5665c0183598f1db53153e74c876768500000000:1580673:0000000017b09a77b815f3df513ff698d1f3b0e8c5e16ac0d6558e2d831f3bf9:130::1570462988:False", network);
        }
        public async Task WriteAllLinesAsync(IEnumerable <string> lines, CancellationToken cancellationToken = default, bool dismissNullOrEmptyContent = true)
        {
            if (dismissNullOrEmptyContent)
            {
                if (lines is null || !lines.Any())
                {
                    return;
                }
            }

            IoHelpers.EnsureContainingDirectoryExists(NewFilePath);

            await File.WriteAllLinesAsync(NewFilePath, lines, cancellationToken);

            SafeMoveNewToOriginal();
        }
        public AboutViewModel(Global global) : base(global, "About")
        {
            Version = WalletWasabi.Helpers.Constants.ClientVersion;

            OpenBrowserCommand = ReactiveCommand.Create <string>(x =>
            {
                try
                {
                    IoHelpers.OpenBrowser(x);
                }
                catch (Exception ex)
                {
                    Logging.Logger.LogError <AboutViewModel>(ex);
                }
            });
        }
        public IFileSystemNode GetChild(string path)
        {
            var parts = IoHelpers.SplitPath(path);

            if (children != null && children.TryGetValue(parts[0], out var child))
            {
                if (parts.Length == 1)
                {
                    return(child);
                }

                return(child.GetChild(parts[1]));
            }

            return(null);
        }
Esempio n. 23
0
 public void Kill(bool cleanFolder = true)
 {
     lock (_l)
     {
         if (_process != null && !_process.HasExited)
         {
             _process.Kill();
             _process.WaitForExit();
         }
         State = CoreNodeState.Killed;
         if (cleanFolder)
         {
             IoHelpers.DeleteRecursivelyWithMagicDustAsync(Folder).GetAwaiter().GetResult();
         }
     }
 }
Esempio n. 24
0
        private static void CreateDigests()
        {
            var tempDir = "DigestTempDir";

            IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter().GetResult();
            Directory.CreateDirectory(tempDir);

            var    torDaemonsDir = Path.Combine(LibraryProjectDirectory, "TorDaemons");
            string torWinZip     = Path.Combine(torDaemonsDir, "tor-win32.zip");

            IoHelpers.BetterExtractZipToDirectoryAsync(torWinZip, tempDir).GetAwaiter().GetResult();
            File.Move(Path.Combine(tempDir, "Tor", "tor.exe"), Path.Combine(tempDir, "TorWin"));

            string torLinuxZip = Path.Combine(torDaemonsDir, "tor-linux64.zip");

            IoHelpers.BetterExtractZipToDirectoryAsync(torLinuxZip, tempDir).GetAwaiter().GetResult();
            File.Move(Path.Combine(tempDir, "Tor", "tor"), Path.Combine(tempDir, "TorLin"));

            string torOsxZip = Path.Combine(torDaemonsDir, "tor-osx64.zip");

            IoHelpers.BetterExtractZipToDirectoryAsync(torOsxZip, tempDir).GetAwaiter().GetResult();
            File.Move(Path.Combine(tempDir, "Tor", "tor"), Path.Combine(tempDir, "TorOsx"));

            string hwiSoftwareDir = Path.Combine(LibraryProjectDirectory, "Hwi", "Software");
            string hwiLinuxZip    = Path.Combine(hwiSoftwareDir, "hwi-linux64.zip");

            IoHelpers.BetterExtractZipToDirectoryAsync(hwiLinuxZip, tempDir).GetAwaiter().GetResult();
            File.Move(Path.Combine(tempDir, "hwi"), Path.Combine(tempDir, "HwiLin"));

            string hwiOsxZip = Path.Combine(hwiSoftwareDir, "hwi-osx64.zip");

            IoHelpers.BetterExtractZipToDirectoryAsync(hwiOsxZip, tempDir).GetAwaiter().GetResult();
            File.Move(Path.Combine(tempDir, "hwi"), Path.Combine(tempDir, "HwiOsx"));

            var tempDirInfo = new DirectoryInfo(tempDir);
            var binaries    = tempDirInfo.GetFiles();

            Console.WriteLine("Digests:");
            foreach (var file in binaries)
            {
                var filePath = file.FullName;
                var hash     = ByteHelpers.ToHex(IoHelpers.GetHashFile(filePath)).ToLowerInvariant();
                Console.WriteLine($"{file.Name} : {hash}");
            }

            IoHelpers.DeleteRecursivelyWithMagicDustAsync(tempDir).GetAwaiter().GetResult();
        }
Esempio n. 25
0
    public IndexStore(string workFolderPath, Network network, SmartHeaderChain hashChain)
    {
        WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
        IoHelpers.EnsureDirectoryExists(WorkFolderPath);
        var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");

        MatureIndexFileManager = new DigestableSafeIoManager(indexFilePath, digestRandomIndex: -1);
        var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");

        ImmatureIndexFileManager = new DigestableSafeIoManager(immatureIndexFilePath, digestRandomIndex: -1);

        Network = Guard.NotNull(nameof(network), network);

        StartingFilter = StartingFilters.GetStartingFilter(Network);

        SmartHeaderChain = Guard.NotNull(nameof(hashChain), hashChain);
    }
Esempio n. 26
0
        private void ToFileNoLock(string filePath)
        {
            IoHelpers.EnsureContainingDirectoryExists(filePath);
            // Remove the last 100 blocks to ensure verification on the next run. This is needed of reorg.
            int    maturity     = 101;
            Height prevHeight   = BlockchainState.Height;
            int    matureHeight = Math.Max(0, prevHeight.Value - maturity);

            BlockchainState.Height = new Height(matureHeight);

            string jsonString = JsonConvert.SerializeObject(this, Formatting.Indented);

            File.WriteAllText(filePath, jsonString, Encoding.UTF8);

            // Re-add removed items for further operations.
            BlockchainState.Height = prevHeight;
        }
        private async Task <TransactionProcessor> CreateTransactionProcessorAsync([CallerMemberName] string callerName = "")
        {
            var keyManager = KeyManager.CreateNew(out _, "password");

            keyManager.AssertCleanKeysIndexed();

            var txStore = new AllTransactionStore();
            var dir     = Path.Combine(Global.Instance.DataDir, callerName, "TransactionStore");
            await IoHelpers.DeleteRecursivelyWithMagicDustAsync(dir);

            await txStore.InitializeAsync(dir, Network.RegTest);

            return(new TransactionProcessor(
                       txStore,
                       keyManager,
                       Money.Coins(0.0001m)));
        }
Esempio n. 28
0
        public async Task InitializeAsync(string workFolderPath, Network network)
        {
            using (BenchmarkLogger.Measure())
            {
                WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
                IoHelpers.EnsureDirectoryExists(WorkFolderPath);

                Network = Guard.NotNull(nameof(network), network);

                IndexStore = new IndexStore();
                var indexStoreFolderPath = Path.Combine(WorkFolderPath, Network.ToString(), "IndexStore");
                HashChain      = new HashChain();
                MempoolService = new MempoolService();

                await IndexStore.InitializeAsync(indexStoreFolderPath, Network, HashChain).ConfigureAwait(false);
            }
        }
Esempio n. 29
0
        public static async Task <NodeBuilder> CreateAsync([CallerMemberName] string caller = null, string version = "0.16.0")
        {
            var directory = Path.Combine(SharedFixture.DataDir, caller);

            version = version ?? "0.16.0";
            var path = await EnsureDownloadedAsync(version);

            try
            {
                await IoHelpers.DeleteRecursivelyWithMagicDustAsync(directory);
            }
            catch (DirectoryNotFoundException)
            {
            }
            Directory.CreateDirectory(directory);
            return(new NodeBuilder(directory, path));
        }
Esempio n. 30
0
        public AboutViewModel()
        {
            OpenBrowserCommand = ReactiveCommand.CreateFromTask <string>(IoHelpers.OpenBrowserAsync);

            AboutAdvancedInfoDialogCommand = ReactiveCommand.CreateFromTask(
                execute: async() => await NavigateDialog(new AboutAdvancedInfoViewModel(), NavigationTarget.CompactDialogScreen));

            OpenBrowserCommand = ReactiveCommand.CreateFromTask <string>(
                async(link) =>
                await IoHelpers.OpenBrowserAsync(link));

            CopyLinkCommand = ReactiveCommand.CreateFromTask <string>(
                async(link) =>
                await Application.Current.Clipboard.SetTextAsync(link));

            NextCommand = CancelCommand;
        }