public TransactionConfirmationWatcherTests()
        {
            this.callbackRepository = Substitute.For <ICallbackRepository>();
            this.ruleRepository     = Substitute.ForPartsOf <FakeRuleRepository>();

            this.blockStorage = Substitute.For <IBlocksStorage>();
            this.blockStorage
            .GetAsync(Arg.Any <uint256>(), Arg.Any <CancellationToken>())
            .Returns(info => mockedBlocks[info.ArgAt <uint256>(0)].ToValueTuple());

            this.callbackExecuter = Substitute.For <ICallbackExecuter>();
            this.logger           = Substitute.For <ILogger <TransactionConfirmationWatcher> >();
            this.watchRepository  = new FakeWatchRepository();

            this.handler = this.subject = new TransactionConfirmationWatcher
                                          (
                this.callbackRepository,
                this.ruleRepository,
                this.blockStorage,
                this.callbackExecuter,
                this.watchRepository,
                this.logger
                                          );
            this.blockListener = this.subject;
            this.defaultUrl    = new Uri("http://zcoin.io");

            MockCallbackRepository();
        }
 public FakeConfirmationWatcher(
     IConfirmationWatcherHandler <object, Watch <object>, object> handler,
     IBlocksStorage blocks) : base(handler, blocks)
 {
     StubbedCreateWatchesAsync  = new Mock <Func <Block, int, CancellationToken, Task <IEnumerable <Watch <object> > > > >();
     StubbedExecuteWatchesAsync = new Mock <Func <IEnumerable <Watch <object> >, Block, int, BlockEventType, CancellationToken, Task <ISet <Watch <object> > > > >();
 }
Пример #3
0
        public BalanceWatcher(IBalanceWatcherHandler <TContext, TAmount> handler, IBlocksStorage blocks)
            : base(handler, blocks)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            this.handler = handler;
        }
        public TransactionConfirmationWatcher(
            ITransactionConfirmationWatcherHandler <TContext> handler,
            IBlocksStorage blocks) : base(handler, blocks)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            this.handler = handler;
        }
Пример #5
0
        public TransactionConfirmationWatcher(
            ICallbackRepository callbackRepository,
            IRuleRepository ruleRepository,
            IBlocksStorage blocks,
            ICallbackExecuter callbackExecuter,
            IWatchRepository watchRepository,
            ILogger <TransactionConfirmationWatcher> logger)
        {
            if (callbackRepository == null)
            {
                throw new ArgumentNullException(nameof(callbackRepository));
            }

            if (ruleRepository == null)
            {
                throw new ArgumentNullException(nameof(ruleRepository));
            }

            if (blocks == null)
            {
                throw new ArgumentNullException(nameof(blocks));
            }

            if (callbackExecuter == null)
            {
                throw new ArgumentNullException(nameof(callbackExecuter));
            }

            if (watchRepository == null)
            {
                throw new ArgumentNullException(nameof(watchRepository));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.callbackRepository = callbackRepository;
            this.ruleRepository     = ruleRepository;
            this.watchRepository    = watchRepository;
            this.callbackExecuter   = callbackExecuter;
            this.logger             = logger;

            this.watcher = new Zcoin.Watching.TransactionConfirmationWatcher <Rule>
                           (
                this,
                blocks
                           );

            this.timers    = new Dictionary <uint256, Dictionary <Guid, Timer> >();
            this.timerLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
        }
Пример #6
0
        protected ConfirmationWatcher(
            IConfirmationWatcherHandler <TContext, TWatch, TConfirm> handler,
            IBlocksStorage blocks) : base(handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            if (blocks == null)
            {
                throw new ArgumentNullException(nameof(blocks));
            }

            this.handler = handler;
            this.blocks  = blocks;
        }
 public BlocksSynchronizerTests()
 {
     this.exceptionHandler = new Mock <IBackgroundServiceExceptionHandler>();
     this.logger           = Substitute.For <ILogger <BlocksSynchronizer> >();
     this.retriever        = Substitute.For <IBlocksRetriever>();
     this.storage          = Substitute.For <IBlocksStorage>();
     this.listener1        = Substitute.For <IBlockListener>();
     this.listener2        = Substitute.For <IBlockListener>();
     this.subject          = new BlocksSynchronizer(
         this.exceptionHandler.Object,
         ZcoinNetworks.Instance.Regtest,
         this.logger,
         this.retriever,
         this.storage,
         new[] { this.listener1, this.listener2 }
         );
 }
Пример #8
0
        public BlocksSynchronizer(
            IBackgroundServiceExceptionHandler exceptionHandler,
            Network network,
            ILogger <BlocksSynchronizer> logger,
            IBlocksRetriever retriever,
            IBlocksStorage storage,
            IEnumerable <IBlockListener> listeners)
            : base(exceptionHandler)
        {
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (retriever == null)
            {
                throw new ArgumentNullException(nameof(retriever));
            }

            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            if (listeners == null)
            {
                throw new ArgumentNullException(nameof(listeners));
            }

            this.logger       = logger;
            this.retriever    = retriever;
            this.storage      = storage;
            this.listeners    = listeners;
            this.chainNetwork = network;
        }
Пример #9
0
        public TokenReceivingWatcher(
            PropertyId property,
            ILogger <TokenReceivingWatcher> logger,
            IBlocksStorage blocks,
            IReceivingAddressPool addressPool,
            ITransactionRetriever exodusRetriever,
            IRuleRepository rules,
            IWatchRepository watches,
            ICallbackRepository callbacks,
            ICallbackExecuter callbackExecutor,
            ITimerScheduler timerScheduler)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (addressPool == null)
            {
                throw new ArgumentNullException(nameof(addressPool));
            }

            if (exodusRetriever == null)
            {
                throw new ArgumentNullException(nameof(exodusRetriever));
            }

            if (rules == null)
            {
                throw new ArgumentNullException(nameof(rules));
            }

            if (watches == null)
            {
                throw new ArgumentNullException(nameof(watches));
            }

            if (callbacks == null)
            {
                throw new ArgumentNullException(nameof(callbacks));
            }

            if (callbackExecutor == null)
            {
                throw new ArgumentNullException(nameof(callbackExecutor));
            }

            if (timerScheduler == null)
            {
                throw new ArgumentNullException(nameof(timerScheduler));
            }

            this.property         = property;
            this.logger           = logger;
            this.addressPool      = addressPool;
            this.exodusRetriever  = exodusRetriever;
            this.rules            = rules;
            this.watches          = watches;
            this.callbacks        = callbacks;
            this.callbackExecutor = callbackExecutor;
            this.timerScheduler   = timerScheduler;
            this.watchings        = new Dictionary <BitcoinAddress, Watching>();
            this.engine           = new BalanceWatcher <Rule, PropertyAmount>(this, blocks);
            this.semaphore        = new SemaphoreSlim(1, 1);
            this.stopped          = true;
        }