Esempio n. 1
0
        public MainWindowViewModel(BlockchainDaemon blockchainDaemon)
        {
            this.blockchainDaemon = blockchainDaemon;

            var winningBlockLocal      = this.blockchainDaemon.WinningBlock;
            var currentBlockchainLocal = this.blockchainDaemon.CurrentBlockchain;

            this.viewBlockchain = currentBlockchainLocal;

            this.WinningBlockchainHeight = winningBlockLocal.Height;
            this.CurrentBlockchainHeight = currentBlockchainLocal.Height;
            this.DownloadedBlockCount    = this.blockchainDaemon.CacheContext.BlockCache.Count;

            this.blockchainDaemon.CacheContext.BlockCache.OnAddition +=
                blockHash =>
                DownloadedBlockCount = this.blockchainDaemon.CacheContext.BlockCache.Count;

            this.blockchainDaemon.OnWinningBlockChanged +=
                (sender, block) =>
                WinningBlockchainHeight = block.Height;

            this.blockchainDaemon.OnCurrentBlockchainChanged +=
                (sender, blockchain) =>
                CurrentBlockchainHeight = blockchain.Height;
        }
Esempio n. 2
0
        public MainWindow()
        {
            try
            {
                //TODO
                //MainnetRules.BypassValidation = true;
                //MainnetRules.BypassExecuteScript = true;
                ScriptEngine.BypassVerifySignature = true;

#if SQLITE
                var storageContext      = new SQLiteStorageContext();
                var knownAddressStorage = new BitSharp.Storage.SQLite.KnownAddressStorage(storageContext);
                this.storageContext = storageContext;
#elif FIREBIRD
                var storageContext      = new FirebirdStorageContext();
                var knownAddressStorage = new BitSharp.Storage.Firebird.KnownAddressStorage(storageContext);
                this.storageContext = storageContext;
#elif SQL_SERVER
                var storageContext      = new SqlServerStorageContext();
                var knownAddressStorage = new BitSharp.Storage.SqlServer.KnownAddressStorage(storageContext);
                this.storageContext = storageContext;
#endif

                this.cacheContext     = new CacheContext(this.storageContext);
                this.rules            = new MainnetRules(this.cacheContext);
                this.blockchainDaemon = new BlockchainDaemon(this.rules, this.cacheContext);
                this.localClient      = new LocalClient(LocalClientType.MainNet, this.blockchainDaemon, knownAddressStorage);

                // setup view model
                this.viewModel = new MainWindowViewModel(this.blockchainDaemon);

                InitializeComponent();

                // start the blockchain daemon
                this.blockchainDaemon.Start();

                this.viewModel.ViewBlockchainLast();

                // start p2p client
                this.localClient.Start();

                this.DataContext = this.viewModel;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            //TODO
            //MainnetRules.BypassValidation = true;
            //MainnetRules.BypassExecuteScript = true;
            ScriptEngine.BypassVerifySignature = true;

            using (var storageContext = new MemoryStorageContext())
                using (var cacheContext = new CacheContext(storageContext))
                {
                    var rules = new Testnet2Rules(cacheContext);

                    using (var blockchainDaemon = new BlockchainDaemon(rules, cacheContext))
                        using (var knownAddressStorage = new MemoryStorage <NetworkAddressKey, NetworkAddressWithTime>(storageContext))
                            using (var localClient = new LocalClient(LocalClientType.ComparisonToolTestNet, blockchainDaemon, knownAddressStorage))
                            {
                                // start the blockchain daemon
                                blockchainDaemon.Start();

                                // start p2p client
                                localClient.Start();

                                var projectFolder = Environment.CurrentDirectory;
                                while (projectFolder.Contains(@"\bin"))
                                {
                                    projectFolder = Path.GetDirectoryName(projectFolder);
                                }

                                File.Delete(Path.Combine(projectFolder, "Bitcoinj-comparison.log"));

                                var javaProcessStartInfo = new ProcessStartInfo
                                {
                                    FileName         = @"C:\Program Files\Java\jdk1.7.0_25\bin\java.exe",
                                    WorkingDirectory = projectFolder,
                                    Arguments        = @"-Djava.util.logging.config.file={0}\bitcoinj.log.properties -jar {0}\bitcoinj.jar".Format2(projectFolder),
                                    UseShellExecute  = false
                                };

                                var javaProcess = Process.Start(javaProcessStartInfo);

                                javaProcess.WaitForExit((int)TimeSpan.FromMinutes(5).TotalMilliseconds);
                                Console.ReadLine();
                            }
                }
        }
Esempio n. 4
0
        public LocalClient(LocalClientType type, BlockchainDaemon blockchainDaemon, IBoundedStorage <NetworkAddressKey, NetworkAddressWithTime> knownAddressStorage)
        {
            this._type = type;

            this.blockchainDaemon = blockchainDaemon;
            this.shutdownToken    = new CancellationTokenSource();

            this.knownAddressCache = new BoundedCache <NetworkAddressKey, NetworkAddressWithTime>
                                     (
                "KnownAddressCache",
                dataStorage: knownAddressStorage,
                maxFlushMemorySize: 5.THOUSAND(),
                maxCacheMemorySize: 500.THOUSAND(),
                sizeEstimator: knownAddress => 40
                                     );

            this.connectWorker        = new Worker("LocalClient.ConnectWorker", ConnectWorker, true, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            this.requestBlocksWorker  = new Worker("LocalClient.RequestBlocksWorker", RequestBlocksWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000));
            this.requestHeadersWorker = new Worker("LocalClient.RequestHeadersWorker", RequestHeadersWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000));
            this.statsWorker          = new Worker("LocalClient.StatsWorker", StatsWorker, true, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30));

            this.blockchainDaemon.OnWinningBlockChanged += OnWinningBlockChanged;

            switch (this.Type)
            {
            case LocalClientType.MainNet:
                Messaging.Port  = 8333;
                Messaging.Magic = Messaging.MAGIC_MAIN;
                break;

            case LocalClientType.TestNet3:
                Messaging.Port  = 18333;
                Messaging.Magic = Messaging.MAGIC_TESTNET3;
                break;

            case LocalClientType.ComparisonToolTestNet:
                Messaging.Port  = 18444;
                Messaging.Magic = Messaging.MAGIC_COMPARISON_TOOL;
                break;
            }
        }