public BlockObserverTests()
        {
            this.minimumDepositConfirmations = 10;

            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.federationGatewaySettings.MinimumDepositConfirmations.Returns(this.minimumDepositConfirmations);

            this.federationWalletSyncManager = Substitute.For <IFederationWalletSyncManager>();
            this.federationGatewayClient     = Substitute.For <IFederationGatewayClient>();
            this.chain                = Substitute.ForPartsOf <ConcurrentChain>();
            this.loggerFactory        = Substitute.For <ILoggerFactory>();
            this.opReturnDataReader   = Substitute.For <IOpReturnDataReader>();
            this.consensusManager     = Substitute.For <IConsensusManager>();
            this.withdrawalExtractor  = Substitute.For <IWithdrawalExtractor>();
            this.extractedWithdrawals = TestingValues.GetWithdrawals(2);
            this.withdrawalExtractor.ExtractWithdrawalsFromBlock(null, 0).ReturnsForAnyArgs(this.extractedWithdrawals);

            this.withdrawalReceiver = Substitute.For <IWithdrawalReceiver>();

            this.signals = Substitute.For <ISignals>();
            this.signals.OnBlockConnected.Returns(Substitute.For <EventNotifier <ChainedHeaderBlock> >());

            this.depositExtractor = new DepositExtractor(
                this.loggerFactory,
                this.federationGatewaySettings,
                this.opReturnDataReader);

            this.blockObserver = new BlockObserver(
                this.federationWalletSyncManager,
                this.depositExtractor,
                this.withdrawalExtractor,
                this.withdrawalReceiver,
                this.federationGatewayClient,
                this.signals);
        }
        public void GetMaturedBlocksReturnsDeposits()
        {
            List <ChainedHeaderBlock> blocks = ChainedHeadersHelper.CreateConsecutiveHeadersAndBlocks(10, null, true);

            ChainedHeader tip = blocks.Last().ChainedHeader;

            this.consensusManager.GetBlockData(Arg.Any <List <uint256> >()).Returns(delegate(CallInfo info)
            {
                var hashes = (List <uint256>)info[0];
                return(hashes.Select((hash) => blocks.Single(x => x.ChainedHeader.HashBlock == hash)).ToArray());
            });

            IFederatedPegSettings federatedPegSettings = Substitute.For <IFederatedPegSettings>();

            federatedPegSettings.MinimumConfirmationsNormalDeposits.Returns(0);

            var deposits = new List <IDeposit>()
            {
                new Deposit(new uint256(0), DepositRetrievalType.Normal, 100, "test", 0, new uint256(1))
            };

            IDepositExtractor depositExtractor = Substitute.For <IDepositExtractor>();

            depositExtractor.ExtractBlockDeposits(blocks.First(), DepositRetrievalType.Normal).ReturnsForAnyArgs(new MaturedBlockDepositsModel(new MaturedBlockInfoModel(), deposits));
            this.consensusManager.Tip.Returns(tip);

            // Makes every block a matured block.
            var maturedBlocksProvider = new MaturedBlocksProvider(this.consensusManager, depositExtractor, federatedPegSettings, this.loggerFactory);

            SerializableResult <List <MaturedBlockDepositsModel> > depositsResult = maturedBlocksProvider.RetrieveDeposits(0);

            // This will be double the amount of blocks because the mocked depositExtractor will always return a set of blocks
            // as that is how it has been configured.
            Assert.Equal(33, depositsResult.Value.Count);
        }
Beispiel #3
0
        /// <summary>
        /// Initialize the block observer with the wallet manager and the cross chain monitor.
        /// </summary>
        /// <param name="walletSyncManager">The wallet sync manager to pass new incoming blocks to.</param>
        /// <param name="depositExtractor">The component used to extract the deposits from the blocks appearing on chain.</param>
        /// <param name="withdrawalExtractor">The component used to extract withdrawals from blocks.</param>
        /// <param name="withdrawalReceiver">The component that receives the withdrawals extracted from blocks.</param>
        /// <param name="federationGatewayClient">Client for federation gateway api.</param>
        public BlockObserver(IFederationWalletSyncManager walletSyncManager,
                             IDepositExtractor depositExtractor,
                             IWithdrawalExtractor withdrawalExtractor,
                             IWithdrawalReceiver withdrawalReceiver,
                             IFederationGatewayClient federationGatewayClient,
                             ISignals signals)
        {
            Guard.NotNull(walletSyncManager, nameof(walletSyncManager));
            Guard.NotNull(federationGatewayClient, nameof(federationGatewayClient));
            Guard.NotNull(depositExtractor, nameof(depositExtractor));
            Guard.NotNull(withdrawalExtractor, nameof(withdrawalExtractor));
            Guard.NotNull(withdrawalReceiver, nameof(withdrawalReceiver));

            this.walletSyncManager       = walletSyncManager;
            this.federationGatewayClient = federationGatewayClient;
            this.depositExtractor        = depositExtractor;
            this.withdrawalExtractor     = withdrawalExtractor;
            this.withdrawalReceiver      = withdrawalReceiver;
            this.signals = signals;

            this.cancellationSource = null;
            this.pushBlockTipTask   = null;

            this.signals.OnBlockConnected.Attach(this.OnBlockReceived);

            // TODO: Dispose with Detach ??
        }
Beispiel #4
0
        public void GetMaturedBlocksReturnsDeposits()
        {
            this.blocks = ChainedHeadersHelper.CreateConsecutiveHeadersAndBlocks(10, true, this.mainChainNetwork);

            ChainedHeader tip = this.blocks.Last().ChainedHeader;

            IFederatedPegSettings federatedPegSettings = Substitute.For <IFederatedPegSettings>();

            federatedPegSettings.MinimumConfirmationsNormalDeposits.Returns(0);

            var deposits = new List <IDeposit>()
            {
                new Deposit(new uint256(0), DepositRetrievalType.Normal, 100, "test", DestinationChain.STRAX, 0, new uint256(1))
            };

            // Set the first block up to return 100 normal deposits.
            IDepositExtractor depositExtractor = Substitute.For <IDepositExtractor>();

            depositExtractor.ExtractDepositsFromBlock(this.blocks.First().Block, this.blocks.First().ChainedHeader.Height, new[] { DepositRetrievalType.Normal }).ReturnsForAnyArgs(deposits);
            this.consensusManager.Tip.Returns(tip);

            // Makes every block a matured block.
            var maturedBlocksProvider = new MaturedBlocksProvider(this.consensusManager, depositExtractor, federatedPegSettings);

            SerializableResult <List <MaturedBlockDepositsModel> > depositsResult = maturedBlocksProvider.RetrieveDeposits(0);

            Assert.Equal(11, depositsResult.Value.Count);
        }
Beispiel #5
0
        public MaturedBlocksProvider(ILoggerFactory loggerFactory, IDepositExtractor depositExtractor, IConsensusManager consensusManager)
        {
            this.depositExtractor = depositExtractor;
            this.consensusManager = consensusManager;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
        public MaturedBlocksProvider(ILoggerFactory loggerFactory, IDepositExtractor depositExtractor, IConsensusManager consensusManager)
        {
            this.depositExtractor = depositExtractor;
            this.consensusManager = consensusManager;

            this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
        }
 public MaturedBlocksProvider(ILoggerFactory loggerFactory,
                              ConcurrentChain chain, IDepositExtractor depositExtractor, IBlockRepository blockRepository)
 {
     this.chain            = chain;
     this.depositExtractor = depositExtractor;
     this.blockRepository  = blockRepository;
     this.blockCache       = new Dictionary <uint256, Block>();
 }
 public MaturedBlocksProviderTests()
 {
     this.loggerFactory = Substitute.For <ILoggerFactory>();
     this.logger        = Substitute.For <ILogger>();
     this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
     this.depositExtractor = Substitute.For <IDepositExtractor>();
     this.consensusManager = Substitute.For <IConsensusManager>();
 }
        public MaturedBlocksProvider(ILoggerFactory loggerFactory, IDepositExtractor depositExtractor, IConsensusManager consensusManager)
        {
            this.depositExtractor = depositExtractor;
            this.consensusManager = consensusManager;

            this.logger       = loggerFactory.CreateLogger(this.GetType().FullName);
            this.depositCache = new Dictionary <int, MaturedBlockDepositsModel>();
        }
 public MaturedBlocksProviderTests()
 {
     this.loggerFactory = Substitute.For <ILoggerFactory>();
     this.logger        = Substitute.For <ILogger>();
     this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
     this.federationSettings = Substitute.For <IFederationGatewaySettings>();
     this.depositExtractor   = Substitute.For <IDepositExtractor>();
     this.chain           = Substitute.ForPartsOf <ConcurrentChain>();
     this.blockRepository = Substitute.For <IBlockRepository>();
 }
Beispiel #11
0
        public MaturedBlocksProvider(IConsensusManager consensusManager, IDepositExtractor depositExtractor, IFederatedPegSettings federatedPegSettings, ILoggerFactory loggerFactory)
        {
            this.consensusManager     = consensusManager;
            this.depositExtractor     = depositExtractor;
            this.federatedPegSettings = federatedPegSettings;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            // Take a copy of the tip upfront so that we work with the same tip later.
            this.consensusTip = this.consensusManager.Tip;
        }
        public FederationGatewayFeature(
            ILoggerFactory loggerFactory,
            IMaturedBlockReceiver maturedBlockReceiver,
            IMaturedBlockSender maturedBlockSender,
            IMaturedBlocksRequester maturedBlocksRequester,
            IMaturedBlocksProvider maturedBlocksProvider,
            IBlockTipSender blockTipSender,
            Signals signals,
            IDepositExtractor depositExtractor,
            IWithdrawalExtractor withdrawalExtractor,
            IWithdrawalReceiver withdrawalReceiver,
            ILeaderProvider leaderProvider,
            IConnectionManager connectionManager,
            IFederationGatewaySettings federationGatewaySettings,
            IFullNode fullNode,
            IFederationWalletManager federationWalletManager,
            IFederationWalletSyncManager walletSyncManager,
            Network network,
            ConcurrentChain chain,
            INodeStats nodeStats,
            ICrossChainTransferStore crossChainTransferStore,
            IPartialTransactionRequester partialTransactionRequester)
        {
            this.loggerFactory         = loggerFactory;
            this.maturedBlockReceiver  = maturedBlockReceiver;
            this.maturedBlockSender    = maturedBlockSender;
            this.maturedBlockRequester = maturedBlocksRequester;
            this.maturedBlocksProvider = maturedBlocksProvider;
            this.blockTipSender        = blockTipSender;
            this.signals                   = signals;
            this.depositExtractor          = depositExtractor;
            this.withdrawalExtractor       = withdrawalExtractor;
            this.withdrawalReceiver        = withdrawalReceiver;
            this.leaderProvider            = leaderProvider;
            this.connectionManager         = connectionManager;
            this.federationGatewaySettings = federationGatewaySettings;
            this.fullNode                  = fullNode;
            this.chain = chain;
            this.federationWalletManager = federationWalletManager;
            this.walletSyncManager       = walletSyncManager;
            this.network = network;
            this.crossChainTransferStore     = crossChainTransferStore;
            this.partialTransactionRequester = partialTransactionRequester;

            // add our payload
            var payloadProvider = (PayloadProvider)this.fullNode.Services.ServiceProvider.GetService(typeof(PayloadProvider));

            payloadProvider.AddPayload(typeof(RequestPartialTransactionPayload));

            nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component);
            nodeStats.RegisterStats(this.AddInlineStats, StatsType.Inline, 800);
        }
        public FederationGatewayControllerTests()
        {
            this.network = CirrusNetwork.NetworksSelector.Regtest();

            this.crossChainTransferStore = Substitute.For <ICrossChainTransferStore>();
            this.loggerFactory           = Substitute.For <ILoggerFactory>();
            this.logger = Substitute.For <ILogger>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.depositExtractor        = Substitute.For <IDepositExtractor>();
            this.consensusManager        = Substitute.For <IConsensusManager>();
            this.federatedPegSettings    = Substitute.For <IFederatedPegSettings>();
            this.federationWalletManager = Substitute.For <IFederationWalletManager>();
            this.signals = new Signals(this.loggerFactory, null);
        }
        public FederationGatewayControllerTests()
        {
            this.network = FederatedPegNetwork.NetworksSelector.Regtest();

            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.logger        = Substitute.For <ILogger>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.maturedBlockReceiver   = Substitute.For <IMaturedBlockReceiver>();
            this.maturedBlocksRequester = Substitute.For <IMaturedBlocksRequester>();
            this.maturedBlocksProvider  = Substitute.For <IMaturedBlocksProvider>();
            this.leaderProvider         = Substitute.For <ILeaderProvider>();
            this.depositExtractor       = Substitute.For <IDepositExtractor>();
            this.leaderReceiver         = Substitute.For <ILeaderReceiver>();
        }
        public FederationGatewayControllerTests()
        {
            this.network = FederatedPegNetwork.NetworksSelector.Regtest();

            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.logger        = Substitute.For <ILogger>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.leaderProvider            = Substitute.For <ILeaderProvider>();
            this.depositExtractor          = Substitute.For <IDepositExtractor>();
            this.leaderReceiver            = Substitute.For <ILeaderReceiver>();
            this.consensusManager          = Substitute.For <IConsensusManager>();
            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.federationWalletManager   = Substitute.For <IFederationWalletManager>();
            this.federationManager         = new FederationManager(NodeSettings.Default(this.network), this.network, this.loggerFactory);
        }
        public FederationGatewayControllerTests()
        {
            this.network = CirrusNetwork.NetworksSelector.Regtest();

            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.logger        = Substitute.For <ILogger>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.depositExtractor        = Substitute.For <IDepositExtractor>();
            this.consensusManager        = Substitute.For <IConsensusManager>();
            this.federatedPegSettings    = Substitute.For <IFederatedPegSettings>();
            this.federationWalletManager = Substitute.For <IFederationWalletManager>();
            this.keyValueRepository      = Substitute.For <IKeyValueRepository>();
            this.signals           = new Signals(this.loggerFactory, null);
            this.federationManager = new CollateralFederationManager(NodeSettings.Default(this.network), this.network, this.loggerFactory, this.keyValueRepository, this.signals, null, null, null);
        }
Beispiel #17
0
        public BlockObserverTests()
        {
            this.minimumDepositConfirmations = 10;

            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.federationGatewaySettings.MinimumDepositConfirmations.Returns(this.minimumDepositConfirmations);

            this.leaderProvider = Substitute.For <ILeaderProvider>();
            this.federationWalletSyncManager = Substitute.For <IFederationWalletSyncManager>();
            this.fullNode              = Substitute.For <IFullNode>();
            this.maturedBlockSender    = Substitute.For <IMaturedBlockSender>();
            this.maturedBlocksProvider = Substitute.For <IMaturedBlocksProvider>();
            this.blockTipSender        = Substitute.For <IBlockTipSender>();
            this.chain = Substitute.ForPartsOf <ConcurrentChain>();
            this.fullNode.NodeService <ConcurrentChain>().Returns(this.chain);
            this.loggerFactory      = Substitute.For <ILoggerFactory>();
            this.opReturnDataReader = Substitute.For <IOpReturnDataReader>();

            this.withdrawalExtractor  = Substitute.For <IWithdrawalExtractor>();
            this.extractedWithdrawals = TestingValues.GetWithdrawals(2);
            this.withdrawalExtractor.ExtractWithdrawalsFromBlock(null, 0)
            .ReturnsForAnyArgs(this.extractedWithdrawals);

            this.withdrawalReceiver = Substitute.For <IWithdrawalReceiver>();

            this.depositExtractor = new DepositExtractor(
                this.loggerFactory,
                this.federationGatewaySettings,
                this.opReturnDataReader,
                this.fullNode);

            this.maturedBlocksProvider = new MaturedBlocksProvider(
                this.loggerFactory,
                this.chain,
                this.depositExtractor,
                Substitute.For <IBlockRepository>());

            this.blockObserver = new BlockObserver(
                this.federationWalletSyncManager,
                this.depositExtractor,
                this.withdrawalExtractor,
                this.withdrawalReceiver,
                this.maturedBlockSender,
                this.maturedBlocksProvider,
                this.blockTipSender);
        }
Beispiel #18
0
 public FederationGatewayController(
     ILoggerFactory loggerFactory,
     IMaturedBlockReceiver maturedBlockReceiver,
     IMaturedBlocksRequester maturedBlocksRequester,
     ILeaderProvider leaderProvider,
     ConcurrentChain chain,
     IMaturedBlocksProvider maturedBlocksProvider,
     IDepositExtractor depositExtractor,
     ILeaderReceiver leaderReceiver)
 {
     this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
     this.maturedBlockReceiver   = maturedBlockReceiver;
     this.maturedBlocksRequester = maturedBlocksRequester;
     this.leaderProvider         = leaderProvider;
     this.chain = chain;
     this.maturedBlocksProvider = maturedBlocksProvider;
     this.depositExtractor      = depositExtractor;
     this.leaderReceiver        = leaderReceiver;
 }
        public MaturedBlocksProvider(IConsensusManager consensusManager, IDepositExtractor depositExtractor, IFederatedPegSettings federatedPegSettings, ILoggerFactory loggerFactory)
        {
            this.consensusManager     = consensusManager;
            this.depositExtractor     = depositExtractor;
            this.federatedPegSettings = federatedPegSettings;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            // Take a copy of the tip upfront so that we work with the same tip later.
            this.deposits = new ConcurrentDictionary <int, BlockDeposits>();
            this.retrievalTypeConfirmations = new Dictionary <DepositRetrievalType, int>
            {
                [DepositRetrievalType.Small]  = this.federatedPegSettings.MinimumConfirmationsSmallDeposits,
                [DepositRetrievalType.Normal] = this.federatedPegSettings.MinimumConfirmationsNormalDeposits,
                [DepositRetrievalType.Large]  = this.federatedPegSettings.MinimumConfirmationsLargeDeposits
            };

            if (this.federatedPegSettings.IsMainChain)
            {
                this.retrievalTypeConfirmations[DepositRetrievalType.Distribution] = this.federatedPegSettings.MinimumConfirmationsDistributionDeposits;
            }
        }
        /// <summary>
        /// Initialize the block observer with the wallet manager and the cross chain monitor.
        /// </summary>
        /// <param name="walletSyncManager">The wallet sync manager to pass new incoming blocks to.</param>
        /// <param name="depositExtractor">The component used to extract the deposits from the blocks appearing on chain.</param>
        /// <param name="withdrawalExtractor">The component used to extract withdrawals from blocks.</param>
        /// <param name="withdrawalReceiver">The component that receives the withdrawals extracted from blocks.</param>
        /// <param name="federationGatewayClient">Client for federation gateway api.</param>
        public BlockObserver(IFederationWalletSyncManager walletSyncManager,
                             IDepositExtractor depositExtractor,
                             IWithdrawalExtractor withdrawalExtractor,
                             IWithdrawalReceiver withdrawalReceiver,
                             IFederationGatewayClient federationGatewayClient)
        {
            Guard.NotNull(walletSyncManager, nameof(walletSyncManager));
            Guard.NotNull(federationGatewayClient, nameof(federationGatewayClient));
            Guard.NotNull(depositExtractor, nameof(depositExtractor));
            Guard.NotNull(withdrawalExtractor, nameof(withdrawalExtractor));
            Guard.NotNull(withdrawalReceiver, nameof(withdrawalReceiver));

            this.walletSyncManager       = walletSyncManager;
            this.federationGatewayClient = federationGatewayClient;
            this.depositExtractor        = depositExtractor;
            this.withdrawalExtractor     = withdrawalExtractor;
            this.withdrawalReceiver      = withdrawalReceiver;

            this.cancellationSource = null;
            this.pushBlockTipTask   = null;
        }
        /// <summary>
        /// Initialize the block observer with the wallet manager and the cross chain monitor.
        /// </summary>
        /// <param name="walletSyncManager">The wallet sync manager to pass new incoming blocks to.</param>
        /// <param name="depositExtractor">The component used to extract the deposits from the blocks appearing on chain.</param>
        /// <param name="withdrawalExtractor">The component used to extract withdrawals from blocks.</param>
        /// <param name="withdrawalReceiver">The component that receives the withdrawals extracted from blocks.</param>
        /// <param name="maturedBlockSender">Service responsible for publishing newly matured blocks.</param>
        /// <param name="blockTipSender">Service responsible for publishing the block tip.</param>
        public BlockObserver(IFederationWalletSyncManager walletSyncManager,
                             IDepositExtractor depositExtractor,
                             IWithdrawalExtractor withdrawalExtractor,
                             IWithdrawalReceiver withdrawalReceiver,
                             IMaturedBlockSender maturedBlockSender,
                             IMaturedBlocksProvider maturedBlocksProvider,
                             IBlockTipSender blockTipSender)
        {
            Guard.NotNull(walletSyncManager, nameof(walletSyncManager));
            Guard.NotNull(maturedBlockSender, nameof(maturedBlockSender));
            Guard.NotNull(maturedBlocksProvider, nameof(maturedBlocksProvider));
            Guard.NotNull(blockTipSender, nameof(blockTipSender));
            Guard.NotNull(depositExtractor, nameof(depositExtractor));
            Guard.NotNull(withdrawalExtractor, nameof(withdrawalExtractor));
            Guard.NotNull(withdrawalReceiver, nameof(withdrawalReceiver));

            this.walletSyncManager     = walletSyncManager;
            this.maturedBlockSender    = maturedBlockSender;
            this.maturedBlocksProvider = maturedBlocksProvider;
            this.depositExtractor      = depositExtractor;
            this.withdrawalExtractor   = withdrawalExtractor;
            this.withdrawalReceiver    = withdrawalReceiver;
            this.blockTipSender        = blockTipSender;
        }