/// <inheritdoc />
        public async Task BroadcastTransactionsAsync(ILeaderProvider leaderProvider)
        {
            if (this.publicKey != leaderProvider.CurrentLeaderKey.ToString())
            {
                return;
            }

            Dictionary <uint256, Transaction> transactions = await this.store.GetTransactionsByStatusAsync(CrossChainTransferStatus.FullySigned).ConfigureAwait(false);

            if (!transactions.Any())
            {
                this.logger.LogTrace("Signed multisig transactions do not exist in the CrossChainTransfer store.");
                return;
            }

            foreach (KeyValuePair <uint256, Transaction> transaction in transactions)
            {
                TxMempoolInfo txInfo = await this.mempoolManager.InfoAsync(transaction.Key).ConfigureAwait(false);

                if (txInfo != null)
                {
                    this.logger.LogTrace("Transaction ID '{0}' already in the mempool.", transaction.Key);
                    continue;
                }

                await this.broadcasterManager.BroadcastTransactionAsync(transaction.Value).ConfigureAwait(false);
            }
        }
 public LeaderReceiverTests()
 {
     this.loggerFactory = Substitute.For <ILoggerFactory>();
     this.logger        = Substitute.For <ILogger>();
     this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
     this.leaderProvider = Substitute.For <ILeaderProvider>();
 }
        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 = 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 SignedMultisigTransactionBroadcasterTests()
        {
            this.loggerFactory             = Substitute.For <ILoggerFactory>();
            this.logger                    = Substitute.For <ILogger>();
            this.leaderReceiver            = Substitute.For <ILeaderReceiver>();
            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.leaderReceiverSubscription = Substitute.For <IDisposable>();
            this.store = Substitute.For <ICrossChainTransferStore>();
            this.broadcasterManager = Substitute.For <IBroadcasterManager>();
            this.leaderProvider     = Substitute.For <ILeaderProvider>();

            // Setup MempoolManager.
            this.dateTimeProvider = Substitute.For <IDateTimeProvider>();
            this.nodeSettings     = new NodeSettings(networksSelector: FederatedPegNetwork.NetworksSelector, protocolVersion: NBitcoin.Protocol.ProtocolVersion.ALT_PROTOCOL_VERSION);

            this.mempoolSettings = new MempoolSettings(this.nodeSettings)
            {
                MempoolExpiry = MempoolValidator.DefaultMempoolExpiry
            };

            this.blockPolicyEstimator = new BlockPolicyEstimator(
                this.mempoolSettings,
                this.loggerFactory,
                this.nodeSettings);

            this.txMempool = new TxMempool(
                this.dateTimeProvider,
                this.blockPolicyEstimator,
                this.loggerFactory,
                this.nodeSettings);

            this.mempoolValidator   = Substitute.For <IMempoolValidator>();
            this.mempoolPersistence = Substitute.For <IMempoolPersistence>();
            this.coinView           = Substitute.For <ICoinView>();

            this.mempoolManager = new MempoolManager(
                new MempoolSchedulerLock(),
                this.txMempool,
                this.mempoolValidator,
                this.dateTimeProvider,
                this.mempoolSettings,
                this.mempoolPersistence,
                this.coinView,
                this.loggerFactory,
                this.nodeSettings.Network);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 public FederationGatewayController(
     ILoggerFactory loggerFactory,
     Network network,
     ILeaderProvider leaderProvider,
     IMaturedBlocksProvider maturedBlocksProvider,
     ILeaderReceiver leaderReceiver,
     IFederationGatewaySettings federationGatewaySettings,
     IFederationWalletManager federationWalletManager,
     FederationManager federationManager = null)
 {
     this.logger                    = loggerFactory.CreateLogger(this.GetType().FullName);
     this.network                   = network;
     this.leaderProvider            = leaderProvider;
     this.maturedBlocksProvider     = maturedBlocksProvider;
     this.leaderReceiver            = leaderReceiver;
     this.federationGatewaySettings = federationGatewaySettings;
     this.federationWalletManager   = federationWalletManager;
     this.federationManager         = federationManager;
 }
Exemplo n.º 9
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;
 }
 /// <inheritdoc />
 public void PushLeader(ILeaderProvider leaderProvider)
 {
     this.logger.LogInformation("Received federated leader: {0}.", leaderProvider.CurrentLeaderKey);
     this.leaderProvidersStream.OnNext(leaderProvider);
 }
Exemplo n.º 11
0
 /// <inheritdoc />
 public void ReceiveLeader(ILeaderProvider leaderProvider)
 {
     this.logger.LogDebug("Received federated leader: {0}", leaderProvider.CurrentLeader);
     this.leaderProvidersStream.OnNext(leaderProvider);
 }