예제 #1
0
        public MaturedBlocksSyncManager(
            IAsyncProvider asyncProvider,
            ICrossChainTransferStore crossChainTransferStore,
            IFederationGatewayClient federationGatewayClient,
            IFederationWalletManager federationWalletManager,
            IInitialBlockDownloadState initialBlockDownloadState,
            INodeLifetime nodeLifetime,
            IConversionRequestRepository conversionRequestRepository,
            ChainIndexer chainIndexer,
            Network network,
            IFederatedPegSettings federatedPegSettings,
            IFederationManager federationManager = null,
            IExternalApiPoller externalApiPoller = null,
            IConversionRequestFeeService conversionRequestFeeService = null)
        {
            this.asyncProvider = asyncProvider;
            this.chainIndexer  = chainIndexer;
            this.conversionRequestRepository = conversionRequestRepository;
            this.crossChainTransferStore     = crossChainTransferStore;
            this.federationGatewayClient     = federationGatewayClient;
            this.federatedPegSettings        = federatedPegSettings;
            this.federationWalletManager     = federationWalletManager;
            this.initialBlockDownloadState   = initialBlockDownloadState;
            this.nodeLifetime = nodeLifetime;
            this.conversionRequestRepository = conversionRequestRepository;
            this.chainIndexer                = chainIndexer;
            this.externalApiPoller           = externalApiPoller;
            this.conversionRequestFeeService = conversionRequestFeeService;
            this.network           = network;
            this.federationManager = federationManager;

            this.logger = LogManager.GetCurrentClassLogger();
        }
        public DepositExtractorTests()
        {
            this.network = new CirrusRegTest();

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

            this.conversionRequestRepository = Substitute.For <IConversionRequestRepository>();

            this.federationSettings = Substitute.For <IFederatedPegSettings>();
            this.federationSettings.IsMainChain.Returns(true);
            this.federationSettings.SmallDepositThresholdAmount.Returns(Money.Coins(10));
            this.federationSettings.NormalDepositThresholdAmount.Returns(Money.Coins(20));
            this.federationSettings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);

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

            IExternalApiClient externalClient = Substitute.For <IExternalApiClient>();

            externalClient.EstimateConversionTransactionFeeAsync().Returns("1.0");
            this.depositExtractor   = new DepositExtractor(this.conversionRequestRepository, this.federationSettings, this.network, this.opReturnDataReader);
            this.transactionBuilder = new TestTransactionBuilder();

            this.retrievalTypeConfirmations = new Dictionary <DepositRetrievalType, int>
            {
                [DepositRetrievalType.Small]            = this.federationSettings.MinimumConfirmationsSmallDeposits,
                [DepositRetrievalType.Normal]           = this.federationSettings.MinimumConfirmationsNormalDeposits,
                [DepositRetrievalType.Large]            = this.federationSettings.MinimumConfirmationsLargeDeposits,
                [DepositRetrievalType.Distribution]     = this.federationSettings.MinimumConfirmationsDistributionDeposits,
                [DepositRetrievalType.ConversionSmall]  = this.federationSettings.MinimumConfirmationsSmallDeposits,
                [DepositRetrievalType.ConversionNormal] = this.federationSettings.MinimumConfirmationsNormalDeposits,
                [DepositRetrievalType.ConversionLarge]  = this.federationSettings.MinimumConfirmationsLargeDeposits
            };
        }
        public MaturedBlocksProviderTests()
        {
            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.logger        = Substitute.For <ILogger>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.consensusManager = Substitute.For <IConsensusManager>();
            this.network          = CirrusNetwork.NetworksSelector.Regtest();

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

            this.transactionBuilder = new TestTransactionBuilder();

            this.addressHelper = new MultisigAddressHelper(this.network, Networks.Strax.Regtest());
            this.targetAddress = this.addressHelper.GetNewTargetChainPubKeyAddress();
            this.opReturnBytes = Encoding.UTF8.GetBytes(this.targetAddress.ToString());

            this.federatedPegSettings = Substitute.For <IFederatedPegSettings>();
            this.federatedPegSettings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);

            this.federatedPegSettings.MinimumConfirmationsSmallDeposits.Returns(5);
            this.federatedPegSettings.MinimumConfirmationsNormalDeposits.Returns(10);
            this.federatedPegSettings.MinimumConfirmationsLargeDeposits.Returns(20);

            this.federatedPegSettings.SmallDepositThresholdAmount.Returns(Money.Coins(10));
            this.federatedPegSettings.NormalDepositThresholdAmount.Returns(Money.Coins(100));
        }
        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);
        }
        public DepositExtractorTests()
        {
            this.network             = CirrusNetwork.NetworksSelector.Regtest();
            this.counterChainNetwork = Networks.Stratis.Regtest();

            this.loggerFactory      = Substitute.For <ILoggerFactory>();
            this.settings           = Substitute.For <IFederatedPegSettings>();
            this.opReturnDataReader = Substitute.For <IOpReturnDataReader>();

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

            this.settings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);

            this.settings.GetWithdrawalTransactionFee(Arg.Any <int>()).ReturnsForAnyArgs((x) =>
            {
                int numInputs = x.ArgAt <int>(0);

                return(FederatedPegSettings.BaseTransactionFee + FederatedPegSettings.InputTransactionFee * numInputs);
            });

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

            this.transactionBuilder = new TestTransactionBuilder();

            this.depositExtractor = new DepositExtractor(
                this.loggerFactory,
                this.settings,
                this.opReturnDataReader);
        }
예제 #6
0
        public PartialTransactionRequester(
            ILoggerFactory loggerFactory,
            ICrossChainTransferStore crossChainTransferStore,
            IAsyncProvider asyncProvider,
            INodeLifetime nodeLifetime,
            IConnectionManager connectionManager,
            IFederatedPegSettings federatedPegSettings,
            IInitialBlockDownloadState ibdState,
            IFederationWalletManager federationWalletManager)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(crossChainTransferStore, nameof(crossChainTransferStore));
            Guard.NotNull(asyncProvider, nameof(asyncProvider));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(federatedPegSettings, nameof(federatedPegSettings));

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
            this.crossChainTransferStore = crossChainTransferStore;
            this.asyncProvider           = asyncProvider;
            this.nodeLifetime            = nodeLifetime;
            this.connectionManager       = connectionManager;
            this.federatedPegSettings    = federatedPegSettings;
            this.ibdState = ibdState;
            this.federationWalletManager = federationWalletManager;
        }
 public FederatedPegBroadcaster(
     IConnectionManager connectionManager,
     IFederatedPegSettings federatedPegSettings)
 {
     this.connectionManager = connectionManager;
     this.federatedPegSettings = federatedPegSettings;
     this.logger = LogManager.GetCurrentClassLogger();
 }
예제 #8
0
 public WithdrawalExtractor(
     IFederatedPegSettings federatedPegSettings,
     IOpReturnDataReader opReturnDataReader,
     Network network)
 {
     this.multisigAddress    = federatedPegSettings.MultiSigAddress;
     this.opReturnDataReader = opReturnDataReader;
     this.network            = network;
 }
예제 #9
0
 public FederatedPegBroadcaster(
     IConnectionManager connectionManager,
     IFederatedPegSettings federatedPegSettings,
     ILoggerFactory loggerFactory = null)
 {
     this.connectionManager    = connectionManager;
     this.federatedPegSettings = federatedPegSettings;
     this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
 }
        public DepositExtractor(IConversionRequestRepository conversionRequestRepository, IFederatedPegSettings federatedPegSettings, Network network, IOpReturnDataReader opReturnDataReader)
        {
            this.conversionRequestRepository = conversionRequestRepository;
            this.federatedPegSettings        = federatedPegSettings;
            this.network            = network;
            this.opReturnDataReader = opReturnDataReader;

            this.depositsBeingProcessedWithinMaturingWindow = new List <uint256>();
            this.logger = LogManager.GetCurrentClassLogger();
        }
예제 #11
0
 public FedMultiSigManualWithdrawalTransactionBuilder(
     Network network,
     IFederatedPegSettings federatedPegSettings,
     IWalletFeePolicy walletFeePolicy,
     IMultisigCoinSelector multisigCoinSelector)
 {
     this.network = network;
     this.federatedPegSettings = federatedPegSettings;
     this.walletFeePolicy      = walletFeePolicy;
     this.multisigCoinSelector = multisigCoinSelector;
 }
예제 #12
0
 /// <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 WithdrawalExtractor(
     ILoggerFactory loggerFactory,
     IFederatedPegSettings federatedPegSettings,
     IOpReturnDataReader opReturnDataReader,
     Network network)
 {
     this.logger             = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
     this.multisigAddress    = federatedPegSettings.MultiSigAddress;
     this.opReturnDataReader = opReturnDataReader;
     this.network            = network;
 }
        public MaturedBlocksProviderTests()
        {
            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.logger        = Substitute.For <ILogger>();
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.conversionRequestRepository = Substitute.For <IConversionRequestRepository>();
            this.consensusManager            = Substitute.For <IConsensusManager>();
            this.network          = new CirrusRegTest();
            this.mainChainNetwork = new StraxRegTest();

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

            this.transactionBuilder = new TestTransactionBuilder();

            this.addressHelper = new MultisigAddressHelper(this.network, this.mainChainNetwork);
            this.targetAddress = this.addressHelper.GetNewTargetChainPubKeyAddress();
            this.opReturnBytes = Encoding.UTF8.GetBytes(InterFluxOpReturnEncoder.Encode(DestinationChain.STRAX, this.targetAddress.ToString()));

            this.federatedPegSettings = Substitute.For <IFederatedPegSettings>();
            this.federatedPegSettings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);

            this.federatedPegSettings.MinimumConfirmationsSmallDeposits.Returns(5);
            this.federatedPegSettings.MinimumConfirmationsNormalDeposits.Returns(10);
            this.federatedPegSettings.MinimumConfirmationsLargeDeposits.Returns(20);

            this.federatedPegSettings.SmallDepositThresholdAmount.Returns(Money.Coins(10));
            this.federatedPegSettings.NormalDepositThresholdAmount.Returns(Money.Coins(100));

            this.consensusManager.GetBlocksAfterBlock(Arg.Any <ChainedHeader>(), MaturedBlocksProvider.MaturedBlocksBatchSize, Arg.Any <CancellationTokenSource>()).Returns(delegate(CallInfo info)
            {
                var chainedHeader = (ChainedHeader)info[0];
                if (chainedHeader == null)
                {
                    return(this.blocks.Where(x => x.ChainedHeader.Height <= this.consensusManager.Tip.Height).ToArray());
                }

                return(this.blocks.SkipWhile(x => x.ChainedHeader.Height <= chainedHeader.Height).Where(x => x.ChainedHeader.Height <= this.consensusManager.Tip.Height).ToArray());
            });

            this.retrievalTypeConfirmations = new Dictionary <DepositRetrievalType, int>
            {
                [DepositRetrievalType.Small]  = this.federatedPegSettings.MinimumConfirmationsSmallDeposits,
                [DepositRetrievalType.Normal] = this.federatedPegSettings.MinimumConfirmationsNormalDeposits,
                [DepositRetrievalType.Large]  = this.federatedPegSettings.MinimumConfirmationsLargeDeposits,
            };

            this.retrievalTypeConfirmations[DepositRetrievalType.Distribution]     = this.federatedPegSettings.MinimumConfirmationsDistributionDeposits;
            this.retrievalTypeConfirmations[DepositRetrievalType.ConversionSmall]  = this.federatedPegSettings.MinimumConfirmationsSmallDeposits;
            this.retrievalTypeConfirmations[DepositRetrievalType.ConversionNormal] = this.federatedPegSettings.MinimumConfirmationsNormalDeposits;
            this.retrievalTypeConfirmations[DepositRetrievalType.ConversionLarge]  = this.federatedPegSettings.MinimumConfirmationsLargeDeposits;
        }