Example #1
0
        public static NodeBuilder Create(NodeDownloadData downloadData, Network network = null,
                                         [CallerMemberName] string caller = null)
        {
            network = network ?? Network.RegTest;
            var isFilePath = downloadData.Version.Length >= 2 && downloadData.Version[1] == ':';
            var path       = isFilePath ? downloadData.Version : EnsureDownloaded(downloadData);

            if (!Directory.Exists(caller))
            {
                Directory.CreateDirectory(caller);
            }

            return(new NodeBuilder(caller, path)
            {
                Network = network
            });
        }
Example #2
0
        public static string EnsureDownloaded(NodeDownloadData downloadData)
        {
            if (!Directory.Exists("TestData"))
            {
                Directory.CreateDirectory("TestData");
            }

            var osDownloadData = downloadData.GetCurrentOSDownloadData();
            var bitcoind       = Path.Combine("TestData", string.Format(osDownloadData.Executable, downloadData.Version));
            var zip            = Path.Combine("TestData", string.Format(osDownloadData.Archive, downloadData.Version));

            if (File.Exists(bitcoind))
            {
                return(bitcoind);
            }

            var url    = string.Format(osDownloadData.DownloadLink, downloadData.Version);
            var client = new HttpClient {
                Timeout = TimeSpan.FromMinutes(10.0)
            };
            var data = client.GetByteArrayAsync(url).GetAwaiter().GetResult();

            CheckHash(osDownloadData, data);
            File.WriteAllBytes(zip, data);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                ZipFile.ExtractToDirectory(zip, new FileInfo(zip).Directory.FullName);
            }
            else
            {
                Process.Start("tar", "-zxvf " + zip + " -C TestData").WaitForExit();
            }

            File.Delete(zip);
            return(bitcoind);
        }