Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoBuilder"/> class.
 /// </summary>
 public MongoBuilder(ILogger <MongoBuilder> logger, IStorage data, IOptions <IndexerSettings> nakoConfiguration)
     : base(logger)
 {
     log           = logger;
     mongoData     = (MongoData)data;
     configuration = nakoConfiguration.Value;
 }
 public MongoStorageOperations(IStorage storage, IOptions <IndexerSettings> configuration, SyncConnection syncConnection)
 {
     data = (MongoData)storage;
     this.configuration  = configuration.Value;
     this.storage        = storage;
     this.syncConnection = syncConnection;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SyncConnection"/> class.
        /// </summary>
        public SyncConnection(IOptions <IndexerSettings> config, IOptions <ChainSettings> chainConfig, IOptions <NetworkSettings> networkConfig)
        {
            IndexerSettings configuration        = config.Value;
            ChainSettings   chainConfiguration   = chainConfig.Value;
            NetworkSettings networkConfiguration = networkConfig.Value;

            Symbol   = chainConfiguration.Symbol;
            Password = configuration.RpcPassword;

            // Take the RPC Port from the Indexer configuration, if it is specified. Otherwise we'll use the default for this chain.
            RpcAccessPort = configuration.RpcAccessPort != 0 ? configuration.RpcAccessPort : networkConfiguration.RPCPort;
            ApiAccessPort = networkConfiguration.APIPort;

            ServerDomain = configuration.RpcDomain.Replace("{Symbol}", chainConfiguration.Symbol.ToLower());
            User         = configuration.RpcUser;
            Secure       = configuration.RpcSecure;

            if (string.IsNullOrWhiteSpace(networkConfiguration.NetworkType))
            {
                Network        = new NetworkConfig(configuration, chainConfiguration, networkConfiguration);
                HasNetworkType = false;
            }
            else
            {
                Network        = (Network)Activator.CreateInstance(Type.GetType(networkConfiguration.NetworkType));
                HasNetworkType = true;
            }

            RecentItems = new Buffer <(DateTime Inserted, TimeSpan Duration, long Size)>(5000);
        }
        private void SetDefaultSettings()
        {
            if (Program.DefaultTaskSettings != null)
            {
                TaskSettings defaultTaskSettings = Program.DefaultTaskSettings.Copy();

                if (UseDefaultAfterCaptureJob)
                {
                    AfterCaptureJob = defaultTaskSettings.AfterCaptureJob;
                }

                if (UseDefaultAfterUploadJob)
                {
                    AfterUploadJob = defaultTaskSettings.AfterUploadJob;
                }

                if (UseDefaultDestinations)
                {
                    ImageDestination                   = defaultTaskSettings.ImageDestination;
                    TextDestination                    = defaultTaskSettings.TextDestination;
                    FileDestination                    = defaultTaskSettings.FileDestination;
                    URLShortenerDestination            = defaultTaskSettings.URLShortenerDestination;
                    SocialNetworkingServiceDestination = defaultTaskSettings.SocialNetworkingServiceDestination;
                }

                if (UseDefaultGeneralSettings)
                {
                    GeneralSettings = defaultTaskSettings.GeneralSettings;
                }

                if (UseDefaultImageSettings)
                {
                    ImageSettings = defaultTaskSettings.ImageSettings;
                }

                if (UseDefaultCaptureSettings)
                {
                    CaptureSettings = defaultTaskSettings.CaptureSettings;
                }
                if (UseDefaultUploadSettings)
                {
                    UploadSettings = defaultTaskSettings.UploadSettings;
                }

                if (UseDefaultActions)
                {
                    ExternalPrograms = defaultTaskSettings.ExternalPrograms;
                }

                if (UseDefaultIndexerSettings)
                {
                    IndexerSettings = defaultTaskSettings.IndexerSettings;
                }

                if (UseDefaultAdvancedSettings)
                {
                    AdvancedSettings = defaultTaskSettings.AdvancedSettings;
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyncServer"/> class.
 /// </summary>
 public SyncServer(ILogger <SyncServer> logger, IOptions <IndexerSettings> configuration, IOptions <ChainSettings> chainConfiguration, IServiceScopeFactory scopeFactory)
 {
     log = logger;
     this.configuration      = configuration.Value;
     this.chainConfiguration = chainConfiguration.Value;
     this.scopeFactory       = scopeFactory;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatsHandler"/> class.
 /// </summary>
 public StatsHandler(SyncConnection connection, IStorage storage, IOptions <IndexerSettings> configuration, IOptions <ChainSettings> chainConfiguration)
 {
     this.storage            = storage;
     syncConnection          = connection;
     this.configuration      = configuration.Value;
     this.chainConfiguration = chainConfiguration.Value;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MongoBuilder"/> class.
 /// </summary>
 public MongoBuilder(ILogger <MongoBuilder> logger, IMongoDb data, IOptions <IndexerSettings> nakoConfiguration, IOptions <ChainSettings> chainSettings)
     : base(logger)
 {
     log                = logger;
     mongoDb            = data;
     configuration      = nakoConfiguration.Value;
     chainConfiguration = chainSettings.Value;
 }
Exemplo n.º 8
0
 protected IndexerTableTask(
     AzureStorageClient storageClient,
     IndexerSettings settings)
     : base(settings)
 {
     StorageClient = storageClient ?? throw new ArgumentNullException(nameof(storageClient));
     _retry        = Policy.Handle <StorageException>()
                     .WaitAndRetryAsync(15, backoff => TimeSpan.FromSeconds(Math.Pow(2, backoff)));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlockFinder"/> class.
 /// </summary>
 public BlockFinder(IOptions <IndexerSettings> configuration, ISyncOperations syncOperations, SyncConnection syncConnection, ILogger <BlockFinder> logger)
     : base(configuration, logger)
 {
     log = logger;
     this.syncConnection = syncConnection;
     this.syncOperations = syncOperations;
     config = configuration.Value;
     watch  = Stopwatch.Start();
 }
 public CheckpointStore(
     IFullNode node,
     AzureStorageClient storageClient,
     IndexerSettings settings)
 {
     _network           = node.Network;
     _storageClient     = storageClient;
     _saveProgress      = !settings.IgnoreCheckpoints;
     _cancellationToken = node.NodeLifetime.ApplicationStopping;
 }
Exemplo n.º 11
0
 public AddressTask(
     Network network,
     IBlockRepository blockRepository,
     AzureStorageClient storageClient,
     IndexerSettings settings)
     : base(storageClient, settings)
 {
     _network         = network;
     _blockRepository = blockRepository;
 }
Exemplo n.º 12
0
 public AzureStorageClient(
     IFullNode node,
     IndexerSettings settings,
     ILoggerFactory loggerFactory)
 {
     Network   = node.Network;
     _settings = settings;
     _logger   = loggerFactory.CreateLogger <AzureStorageClient>();
     SetStorageDefaults();
 }
Exemplo n.º 13
0
        public NetworkConfig(IndexerSettings config, ChainSettings chainConfig, NetworkSettings networkConfig)
        {
            CoinTicker = chainConfig.Symbol;

            var consensusFactory = (ConsensusFactory)Activator.CreateInstance(Type.GetType(networkConfig.NetworkConsensusFactoryType));

            Consensus = new Consensus.Consensus(
                consensusFactory: consensusFactory,
                consensusOptions: null,
                coinType: 0,
                hashGenesisBlock: uint256.Zero,
                subsidyHalvingInterval: 0,
                majorityEnforceBlockUpgrade: 0,
                majorityRejectBlockOutdated: 0,
                majorityWindow: 0,
                buriedDeployments: null,
                bip9Deployments: null,
                bip34Hash: uint256.Zero,
                minerConfirmationWindow: 0,
                maxReorgLength: 0,
                defaultAssumeValid: uint256.Zero,
                maxMoney: 0,
                coinbaseMaturity: 0,
                premineHeight: 0,
                premineReward: 0,
                proofOfWorkReward: 0,
                targetTimespan: TimeSpan.Zero,
                targetSpacing: TimeSpan.Zero,
                powAllowMinDifficultyBlocks: false,
                posNoRetargeting: false,
                powNoRetargeting: false,
                powLimit: new Target(uint256.Zero),
                minimumChainWork: null,
                isProofOfStake: consensusFactory is PosConsensusFactory,
                lastPowBlock: 0,
                proofOfStakeLimit: null,
                proofOfStakeLimitV2: null,
                proofOfStakeReward: 0,
                proofOfStakeTimestampMask: 0x0000003F // 64 sec
                );

            Base58Prefixes = new byte[12][];
            Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (networkConfig.NetworkPubkeyAddressPrefix) };
            Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (networkConfig.NetworkScriptAddressPrefix) };

            Bech32Encoders = new Bech32Encoder[2];
            var encoder = new Bech32Encoder(networkConfig.NetworkWitnessPrefix);

            Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
            Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;

            // TODO
            //StandardScripts.RegisterStandardScriptTemplate(ColdStakingScriptTemplate);
        }
Exemplo n.º 14
0
 public IndexerTaskFactory(
     FullNode node,
     IBlockRepository blockRepository,
     AzureStorageClient storageClient,
     IndexerSettings settings)
 {
     _network         = node.Network;
     _blockRepository = blockRepository;
     _storageClient   = storageClient;
     _settings        = settings;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Notifier"/> class.
 /// </summary>
 public Notifier(IOptions <IndexerSettings> configuration, IOptions <ChainSettings> chainConfiguration, ILogger <Notifier> logger, IStorage storage)
     : base(configuration, logger)
 {
     this.configuration      = configuration.Value;
     this.chainConfiguration = chainConfiguration.Value;
     log          = logger;
     this.storage = storage;
     watch        = Stopwatch.Start();
     client       = new Lazy <HttpClient>(() => new HttpClient(new HttpClientHandler {
         ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) => errors == SslPolicyErrors.None || errors == SslPolicyErrors.RemoteCertificateNameMismatch
     }));
 }
Exemplo n.º 16
0
 public BlockIndexer(
     IOptions <IndexerSettings> configuration,
     ILogger <BlockIndexer> logger,
     IStorage data, IMongoDb db)
     : base(configuration, logger)
 {
     log       = logger;
     this.data = data;
     this.db   = db;
     config    = configuration.Value;
     watch     = Stopwatch.Start();
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SyncOperations"/> class.
        /// </summary>
        public SyncOperations(IStorage storage, ILogger <SyncOperations> logger, IOptions <IndexerSettings> configuration, IMemoryCache cache)
        {
            this.configuration = configuration.Value;
            log          = logger;
            this.storage = storage;
            this.cache   = cache;

            // Register the cold staking template.
            StandardScripts.RegisterStandardScriptTemplate(ColdStakingScriptTemplate.Instance);

            watch        = Stopwatch.Start();
            cacheOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(CacheKeys.BlockCountTime);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MempoolPuller"/> class.
 /// </summary>
 public MempoolPuller(
     IOptions <IndexerSettings> configuration,
     ISyncOperations syncOperations,
     SyncConnection syncConnection,
     ILogger <MempoolPuller> logger,
     IStorageOperations storageOperations)
     : base(configuration, logger)
 {
     log = logger;
     this.storageOperations = storageOperations;
     this.syncConnection    = syncConnection;
     this.syncOperations    = syncOperations;
     config = configuration.Value;
     watch  = Stopwatch.Start();
 }
Exemplo n.º 19
0
 public Indexer(
     INodeBlockFetcherFactory blockFetcherFactory,
     IIndexerTaskFactory taskFactory,
     ICheckpointStore checkpointStore,
     ConcurrentChain chain,
     IndexerSettings settings,
     ILoggerFactory loggerFactor)
 {
     this._blockFetcherFactory = blockFetcherFactory;
     this._chain           = chain;
     this._settings        = settings;
     this._logger          = loggerFactor.CreateLogger <Indexer>();
     this._taskFactory     = taskFactory;
     this._checkpointStore = checkpointStore;
 }
Exemplo n.º 20
0
        public MongoData(ILogger <MongoStorageOperations> logger, SyncConnection connection, IOptions <IndexerSettings> nakoConfiguration, IOptions <ChainSettings> chainConfiguration)
        {
            configuration           = nakoConfiguration.Value;
            this.chainConfiguration = chainConfiguration.Value;

            syncConnection = connection;
            log            = logger;
            mongoClient    = new MongoClient(configuration.ConnectionString.Replace("{Symbol}", this.chainConfiguration.Symbol.ToLower()));

            string dbName = configuration.DatabaseNameSubfix ? "Blockchain" + this.chainConfiguration.Symbol : "Blockchain";

            mongoDatabase      = mongoClient.GetDatabase(dbName);
            MemoryTransactions = new ConcurrentDictionary <string, NBitcoin.Transaction>();

            // Make sure we only create a single instance of the watcher.
            watch = Stopwatch.Start();
        }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatsHandler"/> class.
 /// </summary>
 public StatsHandler(
     SyncConnection connection,
     IStorage storage,
     IOptions <NetworkSettings> networkConfig,
     IOptions <IndexerSettings> configuration,
     IOptions <ChainSettings> chainConfiguration,
     ICryptoClientFactory clientFactory,
     GlobalState globalState)
 {
     this.storage            = storage;
     this.clientFactory      = clientFactory;
     this.globalState        = globalState;
     syncConnection          = connection;
     this.configuration      = configuration.Value;
     this.chainConfiguration = chainConfiguration.Value;
     this.networkConfig      = networkConfig.Value;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Creates a new instance of the Azure Indexer feature
 /// </summary>
 /// <param name="fullNode"></param>
 /// <param name="storageClient"></param>
 /// <param name="azureIndexerLoop"></param>
 /// <param name="nodeSettings"></param>
 /// <param name="indexerSettings"></param>
 /// <param name="storeSettings"></param>
 /// <param name="loggerFactory"></param>
 public AzureIndexerFeature(
     FullNode fullNode,
     AzureStorageClient storageClient,
     AzureIndexerLoop azureIndexerLoop,
     NodeSettings nodeSettings,
     IndexerSettings indexerSettings,
     StoreSettings storeSettings,
     ILoggerFactory loggerFactory)
 {
     this._fullNode        = fullNode;
     this._storageClient   = storageClient;
     this._indexerLoop     = azureIndexerLoop;
     this._nodeSettings    = nodeSettings;
     this._indexerSettings = indexerSettings;
     this._storeSettings   = storeSettings;
     this._logger          = loggerFactory.CreateLogger <AzureIndexerFeature>();
 }
 public MongoStorageOperations(
     SyncConnection syncConnection,
     IMongoDb storage,
     IUtxoCache utxoCache,
     IOptions <IndexerSettings> configuration,
     GlobalState globalState,
     IMapMongoBlockToStorageBlock mongoBlockToStorageBlock,
     IScriptInterpeter scriptInterpeter,
     IStorage storage1)
 {
     this.syncConnection           = syncConnection;
     this.globalState              = globalState;
     this.scriptInterpeter         = scriptInterpeter;
     this.storage                  = storage1;
     this.mongoBlockToStorageBlock = mongoBlockToStorageBlock;
     this.configuration            = configuration.Value;
     db = storage;
 }
Exemplo n.º 24
0
        public static void OpenDirectoryIndexer(TaskSettings taskSettings = null)
        {
            if (taskSettings == null)
            {
                taskSettings = TaskSettings.GetDefaultTaskSettings();
            }

            IndexerSettings indexerSettings = taskSettings.ToolsSettingsReference.IndexerSettings;

            indexerSettings.BinaryUnits = Program.Settings.BinaryUnits;
            DirectoryIndexerForm form = new DirectoryIndexerForm(indexerSettings);

            form.UploadRequested += source =>
            {
                WorkerTask task = WorkerTask.CreateTextUploaderTask(source, taskSettings);
                task.Info.FileName = Path.ChangeExtension(task.Info.FileName, indexerSettings.Output.ToString().ToLowerInvariant());
                TaskManager.Start(task);
            };
            form.Show();
        }
Exemplo n.º 25
0
        public NetworkConfig(IndexerSettings config, ChainSettings chainConfig, NetworkSettings networkConfig)
        {
            CoinTicker = chainConfig.Symbol;

            var consensusFactory = (ConsensusFactory)Activator.CreateInstance(Type.GetType(networkConfig.NetworkConsensusFactoryType));

            Consensus = new ConsensusConfig(config, consensusFactory);

            Base58Prefixes = new byte[12][];
            Base58Prefixes[(int)Base58Type.PUBKEY_ADDRESS] = new byte[] { (networkConfig.NetworkPubkeyAddressPrefix) };
            Base58Prefixes[(int)Base58Type.SCRIPT_ADDRESS] = new byte[] { (networkConfig.NetworkScriptAddressPrefix) };

            Bech32Encoders = new Bech32Encoder[2];
            var encoder = new Bech32Encoder(networkConfig.NetworkWitnessPrefix);

            Bech32Encoders[(int)Bech32Type.WITNESS_PUBKEY_ADDRESS] = encoder;
            Bech32Encoders[(int)Bech32Type.WITNESS_SCRIPT_ADDRESS] = encoder;

            // TODO
            //StandardScripts.RegisterStandardScriptTemplate(ColdStakingScriptTemplate);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SyncOperations"/> class.
        /// </summary>
        public SyncOperations(
            IStorage storage,
            ILogger <SyncOperations> logger,
            IOptions <IndexerSettings> configuration,
            IMemoryCache cache,
            GlobalState globalState, ICryptoClientFactory clientFactory,
            ISyncBlockTransactionOperationBuilder blockInfoEnrichment, IMongoDb db)
        {
            this.configuration = configuration.Value;
            log                         = logger;
            this.storage                = storage;
            this.cache                  = cache;
            this.globalState            = globalState;
            this.clientFactory          = clientFactory;
            transactionOperationBuilder = blockInfoEnrichment;
            this.db                     = db;

            // Register the cold staking template.
            StandardScripts.RegisterStandardScriptTemplate(ColdStakingScriptTemplate.Instance);

            cacheOptions = new MemoryCacheEntryOptions().SetAbsoluteExpiration(CacheKeys.BlockCountTime);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SyncConnection"/> class.
        /// </summary>
        public SyncConnection(IOptions <IndexerSettings> config, IOptions <ChainSettings> chainConfig, IOptions <NetworkSettings> networkConfig)
        {
            IndexerSettings configuration        = config.Value;
            ChainSettings   chainConfiguration   = chainConfig.Value;
            NetworkSettings networkConfiguration = networkConfig.Value;

            Symbol   = chainConfiguration.Symbol;
            Password = configuration.RpcPassword;

            // Take the RPC Port from the Indexer configuration, if it is specified. Otherwise we'll use the default for this chain.
            RpcAccessPort = configuration.RpcAccessPort != 0 ? configuration.RpcAccessPort : networkConfiguration.RPCPort;

            ServerDomain    = configuration.RpcDomain.Replace("{Symbol}", chainConfiguration.Symbol.ToLower());
            User            = configuration.RpcUser;
            Secure          = configuration.RpcSecure;
            StartBlockIndex = configuration.StartBlockIndex;

            // This can be replaced with a specific the network class of a specific coin
            // Or use the config values to simulate the network class.
            Network = new NetworkConfig(configuration, chainConfiguration, networkConfiguration);

            RecentItems = new Buffer <(DateTime Inserted, TimeSpan Duration, long Size)>(5000);
        }
Exemplo n.º 28
0
 public ConsensusConfig(IndexerSettings config, ConsensusFactory consensusFactory) : base(
         consensusFactory: consensusFactory,
         consensusOptions: null,
         coinType: 0,
         hashGenesisBlock: uint256.Zero,
         subsidyHalvingInterval: 0,
         majorityEnforceBlockUpgrade: 0,
         majorityRejectBlockOutdated: 0,
         majorityWindow: 0,
         buriedDeployments: null,
         bip9Deployments: null,
         bip34Hash: uint256.Zero,
         ruleChangeActivationThreshold: 0,
         minerConfirmationWindow: 0,
         maxReorgLength: 0,
         defaultAssumeValid: uint256.Zero,
         maxMoney: 0,
         coinbaseMaturity: 0,
         premineHeight: 0,
         premineReward: 0,
         proofOfWorkReward: 0,
         powTargetTimespan: TimeSpan.Zero,
         powTargetSpacing: TimeSpan.Zero,
         powAllowMinDifficultyBlocks: false,
         posNoRetargeting: false,
         powNoRetargeting: false,
         powLimit: new Target(uint256.Zero),
         minimumChainWork: null,
         isProofOfStake: consensusFactory is PosConsensusFactory,
         lastPowBlock: 0,
         proofOfStakeLimit: null,
         proofOfStakeLimitV2: null,
         proofOfStakeReward: 0
         )
 {
 }
Exemplo n.º 29
0
 protected IndexerTask(
     IndexerSettings settings)
 {
     Settings = settings;
 }
Exemplo n.º 30
0
 public BlockSummaryTask(
     AzureStorageClient storageClient,
     IndexerSettings settings)
     : base(storageClient, settings)
 {
 }