/// <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 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); }
/// <summary> /// Chooses the key we use. /// </summary> /// <param name="keyNum">The key number.</param> protected void SetExtendedKey(int keyNum) { this.extendedKey = this.federationKeys[keyNum]; this.federationGatewaySettings.IsMainChain.Returns(false); this.federationGatewaySettings.MultiSigRedeemScript.Returns(this.redeemScript); this.federationGatewaySettings.MultiSigAddress.Returns(this.redeemScript.Hash.GetAddress(this.network)); this.federationGatewaySettings.PublicKey.Returns(this.extendedKey.PrivateKey.PubKey.ToHex()); this.withdrawalExtractor = new WithdrawalExtractor(this.loggerFactory, this.federationGatewaySettings, this.opReturnDataReader, this.network); }
/// <summary> /// Chooses the key we use. /// </summary> /// <param name="keyNum">The key number.</param> protected void SetExtendedKey(int keyNum) { this.extendedKey = this.federationKeys[keyNum]; this.federatedPegSettings.IsMainChain.Returns(false); this.federatedPegSettings.MultiSigRedeemScript.Returns(this.redeemScript); this.federatedPegSettings.MultiSigAddress.Returns(this.redeemScript.Hash.GetAddress(this.network)); this.federatedPegSettings.PublicKey.Returns(this.extendedKey.PrivateKey.PubKey.ToHex()); this.federatedPegSettings.MaximumPartialTransactionThreshold.Returns(CrossChainTransferStore.MaximumPartialTransactions); this.withdrawalExtractor = new WithdrawalExtractor(this.federatedPegSettings, this.opReturnDataReader, this.network); }
/// <summary> /// The <see cref="WithdrawalHistoryProvider"/> constructor. /// </summary> /// <param name="network">Network we are running on.</param> /// <param name="federatedPegSettings">Federation settings providing access to number of signatures required.</param> /// <param name="mempoolManager">Mempool which provides information about transactions in the mempool.</param> /// <param name="counterChainNetworkWrapper">Counter chain network.</param> public WithdrawalHistoryProvider( Network network, IFederatedPegSettings federatedPegSettings, MempoolManager mempoolManager, CounterChainNetworkWrapper counterChainNetworkWrapper) { this.network = network; this.federatedPegSettings = federatedPegSettings; this.withdrawalExtractor = new WithdrawalExtractor(federatedPegSettings, new OpReturnDataReader(counterChainNetworkWrapper), network); this.mempoolManager = mempoolManager; }
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); }
/// <summary> /// The <see cref="WithdrawalHistoryProvider"/> constructor. /// </summary> /// <param name="network">Network we are running on.</param> /// <param name="federatedPegSettings">Federation settings providing access to number of signatures required.</param> /// <param name="crossChainTransferStore">Store which provides access to the statuses.</param> /// <param name="mempoolManager">Mempool which provides information about transactions in the mempool.</param> /// <param name="loggerFactory">Logger factory.</param> /// <param name="counterChainNetworkWrapper">Counter chain network.</param> public WithdrawalHistoryProvider( Network network, IFederatedPegSettings federatedPegSettings, ICrossChainTransferStore crossChainTransferStore, MempoolManager mempoolManager, ILoggerFactory loggerFactory, CounterChainNetworkWrapper counterChainNetworkWrapper) { this.network = network; this.federatedPegSettings = federatedPegSettings; this.crossChainTransferStore = crossChainTransferStore; this.withdrawalExtractor = new WithdrawalExtractor(federatedPegSettings, new OpReturnDataReader(loggerFactory, counterChainNetworkWrapper), network); this.mempoolManager = mempoolManager; }
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); }
public FederationWalletManager( ILoggerFactory loggerFactory, Network network, ChainIndexer chainIndexer, DataFolder dataFolder, IWalletFeePolicy walletFeePolicy, IAsyncLoopFactory asyncLoopFactory, INodeLifetime nodeLifetime, IDateTimeProvider dateTimeProvider, IFederationGatewaySettings federationGatewaySettings, IWithdrawalExtractor withdrawalExtractor, IBroadcasterManager broadcasterManager = null) // no need to know about transactions the node broadcasted { Guard.NotNull(loggerFactory, nameof(loggerFactory)); Guard.NotNull(network, nameof(network)); Guard.NotNull(chainIndexer, nameof(chainIndexer)); Guard.NotNull(dataFolder, nameof(dataFolder)); Guard.NotNull(walletFeePolicy, nameof(walletFeePolicy)); Guard.NotNull(asyncLoopFactory, nameof(asyncLoopFactory)); Guard.NotNull(nodeLifetime, nameof(nodeLifetime)); Guard.NotNull(federationGatewaySettings, nameof(federationGatewaySettings)); Guard.NotNull(withdrawalExtractor, nameof(withdrawalExtractor)); this.lockObject = new object(); this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.network = network; this.coinType = (CoinType)network.Consensus.CoinType; this.chainIndexer = chainIndexer; this.asyncLoopFactory = asyncLoopFactory; this.nodeLifetime = nodeLifetime; this.fileStorage = new FileStorage <FederationWallet>(dataFolder.WalletPath); this.broadcasterManager = broadcasterManager; this.dateTimeProvider = dateTimeProvider; this.federationGatewaySettings = federationGatewaySettings; this.withdrawalExtractor = withdrawalExtractor; this.outpointLookup = new Dictionary <OutPoint, TransactionData>(); this.isFederationActive = false; // register events if (this.broadcasterManager != null) { this.broadcasterManager.TransactionStateChanged += this.BroadcasterManager_TransactionStateChanged; } }
/// <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 FederationWalletManager( ILoggerFactory loggerFactory, Network network, ChainIndexer chainIndexer, DataFolder dataFolder, IWalletFeePolicy walletFeePolicy, IAsyncProvider asyncProvider, INodeLifetime nodeLifetime, IDateTimeProvider dateTimeProvider, IFederationGatewaySettings federationGatewaySettings, IWithdrawalExtractor withdrawalExtractor) { Guard.NotNull(loggerFactory, nameof(loggerFactory)); Guard.NotNull(network, nameof(network)); Guard.NotNull(chainIndexer, nameof(chainIndexer)); Guard.NotNull(dataFolder, nameof(dataFolder)); Guard.NotNull(walletFeePolicy, nameof(walletFeePolicy)); Guard.NotNull(asyncProvider, nameof(asyncProvider)); Guard.NotNull(nodeLifetime, nameof(nodeLifetime)); Guard.NotNull(federationGatewaySettings, nameof(federationGatewaySettings)); Guard.NotNull(withdrawalExtractor, nameof(withdrawalExtractor)); this.lockObject = new object(); this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.network = network; this.coinType = (CoinType)network.Consensus.CoinType; this.chainIndexer = chainIndexer; this.asyncProvider = asyncProvider; this.nodeLifetime = nodeLifetime; this.fileStorage = new FileStorage <FederationWallet>(dataFolder.WalletPath); this.dateTimeProvider = dateTimeProvider; this.federationGatewaySettings = federationGatewaySettings; this.withdrawalExtractor = withdrawalExtractor; this.outpointLookup = new Dictionary <OutPoint, TransactionData>(); this.isFederationActive = false; }
/// <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; }