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);
        }
Esempio n. 2
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 ??
        }
        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);
        }
Esempio n. 4
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);
        }
        /// <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;
        }
        public WithdrawalExtractorTests()
        {
            this.network = FederatedPegNetwork.NetworksSelector.Regtest();

            this.loggerFactory      = Substitute.For <ILoggerFactory>();
            this.settings           = Substitute.For <IFederationGatewaySettings>();
            this.opReturnDataReader = Substitute.For <IOpReturnDataReader>();
            this.withdrawalReceiver = Substitute.For <IWithdrawalReceiver>();

            this.addressHelper = new MultisigAddressHelper(this.network);

            this.settings.MultiSigAddress.Returns(this.addressHelper.TargetChainMultisigAddress);
            this.settings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);
            this.settings.FederationPublicKeys.Returns(this.addressHelper.MultisigPrivateKeys.Select(k => k.PubKey).ToArray());

            this.opReturnDataReader.TryGetTargetAddress(null, out string address).Returns(callInfo => { callInfo[1] = null; return(false); });

            this.transactionBuilder = new TestMultisigTransactionBuilder(this.addressHelper);

            this.withdrawalExtractor = new WithdrawalExtractor(
                this.loggerFactory, this.settings, this.opReturnDataReader, this.network);
        }
        /// <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;
        }