예제 #1
0
 public DepositExtractor(IFederatedPegSettings federatedPegSettings, Network network, IOpReturnDataReader opReturnDataReader)
 {
     this.depositScript        = federatedPegSettings.MultiSigRedeemScript.PaymentScript;
     this.federatedPegSettings = federatedPegSettings;
     this.network            = network;
     this.opReturnDataReader = opReturnDataReader;
 }
 public WithdrawalExtractor(IFederatedPegSettings federatedPegSettings, IConversionRequestRepository conversionRequestRepository, IOpReturnDataReader opReturnDataReader, Network network)
 {
     this.multisigAddress             = federatedPegSettings.MultiSigAddress;
     this.conversionRequestRepository = conversionRequestRepository;
     this.opReturnDataReader          = opReturnDataReader;
     this.network = network;
 }
        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 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 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 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);
        }
예제 #7
0
        public CrossChainTransactionMonitor(
            ILoggerFactory loggerFactory,
            Network network,
            ConcurrentChain concurrentChain,
            FederationGatewaySettings federationGatewaySettings,
            IMonitorChainSessionManager monitorChainSessionManager,
            ICounterChainSessionManager counterChainSessionManager,
            IInitialBlockDownloadState initialBlockDownloadState,
            IOpReturnDataReader opReturnDataReader,
            ICrossChainTransactionAuditor crossChainTransactionAuditor = null)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(monitorChainSessionManager, nameof(monitorChainSessionManager));
            Guard.NotNull(counterChainSessionManager, nameof(counterChainSessionManager));
            Guard.NotNull(federationGatewaySettings, nameof(federationGatewaySettings));
            Guard.NotNull(concurrentChain, nameof(concurrentChain));
            Guard.NotNull(initialBlockDownloadState, nameof(initialBlockDownloadState));
            Guard.NotNull(opReturnDataReader, nameof(opReturnDataReader));
            Guard.NotNull(crossChainTransactionAuditor, nameof(crossChainTransactionAuditor));

            this.logger  = loggerFactory.CreateLogger(this.GetType().FullName);
            this.network = network;
            this.monitorChainSessionManager   = monitorChainSessionManager;
            this.counterChainSessionManager   = counterChainSessionManager;
            this.federationGatewaySettings    = federationGatewaySettings;
            this.concurrentChain              = concurrentChain;
            this.initialBlockDownloadState    = initialBlockDownloadState;
            this.opReturnDataReader           = opReturnDataReader;
            this.crossChainTransactionAuditor = crossChainTransactionAuditor;
        }
        public RewardClaimerTests()
        {
            this.network = new StraxRegTest
            {
                RewardClaimerBatchActivationHeight = 40,
                RewardClaimerBlockInterval         = 10
            };

            this.addressHelper               = new MultisigAddressHelper(this.network, new CirrusRegTest());
            this.broadCasterManager          = Substitute.For <IBroadcasterManager>();
            this.chainIndexer                = new ChainIndexer(this.network);
            this.consensusManager            = Substitute.For <IConsensusManager>();
            this.dbreezeSerializer           = new DBreezeSerializer(this.network.Consensus.ConsensusFactory);
            this.conversionRequestRepository = Substitute.For <IConversionRequestRepository>();

            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.signals       = new Signals(this.loggerFactory, null);

            this.initialBlockDownloadState = Substitute.For <IInitialBlockDownloadState>();
            this.initialBlockDownloadState.IsInitialBlockDownload().Returns(false);

            this.opReturnDataReader = new OpReturnDataReader(new CirrusRegTest());

            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));
        }
예제 #9
0
        public DepositExtractorTests()
        {
            this.network = new CirrusRegTest();

            ILoggerFactory loggerFactory = Substitute.For <ILoggerFactory>();

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

            this.federationSettings = Substitute.For <IFederatedPegSettings>();
            this.federationSettings.SmallDepositThresholdAmount.Returns(Money.Coins(10));
            this.federationSettings.NormalDepositThresholdAmount.Returns(Money.Coins(20));

            this.federationSettings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);
            this.federationSettings.GetWithdrawalTransactionFee(Arg.Any <int>()).ReturnsForAnyArgs((x) =>
            {
                int numInputs = x.ArgAt <int>(0);
                return(FederatedPegSettings.BaseTransactionFee + FederatedPegSettings.InputTransactionFee * numInputs);
            });

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

            this.depositExtractor   = new DepositExtractor(loggerFactory, this.federationSettings, this.opReturnDataReader);
            this.transactionBuilder = new TestTransactionBuilder();
        }
        /// <summary>
        /// Initializes the cross-chain transfer tests.
        /// </summary>
        /// <param name="network">The network to run the tests for.</param>
        public CrossChainTestBase(Network network = null, Network counterChainNetwork = null)
        {
            this.network             = network ?? FederatedPegNetwork.NetworksSelector.Regtest();
            this.counterChainNetwork = counterChainNetwork ?? Networks.Stratis.Regtest();
            this.federatedPegOptions = new FederatedPegOptions(counterChainNetwork);

            NetworkRegistration.Register(this.network);

            this.loggerFactory = Substitute.For <ILoggerFactory>();
            this.nodeLifetime  = new NodeLifetime();
            this.logger        = Substitute.For <ILogger>();
            this.signals       = Substitute.For <ISignals>();
            this.asyncProvider = new AsyncProvider(this.loggerFactory, this.signals, this.nodeLifetime);
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.dateTimeProvider                   = DateTimeProvider.Default;
            this.opReturnDataReader                 = new OpReturnDataReader(this.loggerFactory, this.federatedPegOptions);
            this.blockRepository                    = Substitute.For <IBlockRepository>();
            this.fullNode                           = Substitute.For <IFullNode>();
            this.withdrawalTransactionBuilder       = Substitute.For <IWithdrawalTransactionBuilder>();
            this.federationWalletManager            = Substitute.For <IFederationWalletManager>();
            this.federationWalletSyncManager        = Substitute.For <IFederationWalletSyncManager>();
            this.FederationWalletTransactionHandler = Substitute.For <IFederationWalletTransactionHandler>();
            this.walletFeePolicy                    = Substitute.For <IWalletFeePolicy>();
            this.connectionManager                  = Substitute.For <IConnectionManager>();
            this.dBreezeSerializer                  = new DBreezeSerializer(this.network.Consensus.ConsensusFactory);
            this.ibdState                           = Substitute.For <IInitialBlockDownloadState>();
            this.wallet = null;
            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.ChainIndexer = new ChainIndexer(this.network);

            this.federationGatewaySettings.TransactionFee.Returns(new Money(0.01m, MoneyUnit.BTC));

            // Generate the keys used by the federation members for our tests.
            this.federationKeys = new[]
            {
                "ensure feel swift crucial bridge charge cloud tell hobby twenty people mandate",
                "quiz sunset vote alley draw turkey hill scrap lumber game differ fiction",
                "exchange rent bronze pole post hurry oppose drama eternal voice client state"
            }.Select(m => HdOperations.GetExtendedKey(m)).ToArray();

            SetExtendedKey(0);

            this.fundingTransactions = new List <Transaction>();

            this.blockDict = new Dictionary <uint256, Block>();
            this.blockDict[this.network.GenesisHash] = this.network.GetGenesis();

            this.blockRepository.GetBlocks(Arg.Any <List <uint256> >()).ReturnsForAnyArgs((x) =>
            {
                var hashes = x.ArgAt <List <uint256> >(0);
                var blocks = new List <Block>();
                for (int i = 0; i < hashes.Count; i++)
                {
                    blocks.Add(this.blockDict.TryGetValue(hashes[i], out Block block) ? block : null);
                }

                return(blocks);
            });
        }
예제 #11
0
 public WithdrawalExtractor(
     IFederatedPegSettings federatedPegSettings,
     IOpReturnDataReader opReturnDataReader,
     Network network)
 {
     this.multisigAddress    = federatedPegSettings.MultiSigAddress;
     this.opReturnDataReader = opReturnDataReader;
     this.network            = network;
 }
        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();
        }
 public WithdrawalExtractor(
     ILoggerFactory loggerFactory,
     IFederatedPegSettings federatedPegSettings,
     IOpReturnDataReader opReturnDataReader,
     Network network)
 {
     this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
     this.multisigAddress    = federatedPegSettings.MultiSigAddress;
     this.opReturnDataReader = opReturnDataReader;
     this.network            = network;
 }
예제 #14
0
 public WithdrawalExtractor(
     ILoggerFactory loggerFactory,
     IFederationGatewaySettings federationGatewaySettings,
     IOpReturnDataReader opReturnDataReader,
     Network network)
 {
     this.logger             = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
     this.multisigAddress    = federationGatewaySettings.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;
        }
 public DepositExtractor(
     ILoggerFactory loggerFactory,
     IFederatedPegSettings federatedPegSettings,
     IOpReturnDataReader opReturnDataReader)
 {
     this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
     // Note: MultiSigRedeemScript.PaymentScript equals MultiSigAddress.ScriptPubKey
     this.depositScript =
         federatedPegSettings.MultiSigRedeemScript?.PaymentScript ??
         federatedPegSettings.MultiSigAddress?.ScriptPubKey;
     this.opReturnDataReader          = opReturnDataReader;
     this.MinimumDepositConfirmations = federatedPegSettings.MinimumDepositConfirmations;
 }
예제 #17
0
 public DepositExtractor(
     ILoggerFactory loggerFactory,
     IFederationGatewaySettings federationGatewaySettings,
     IOpReturnDataReader opReturnDataReader)
 {
     this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
     // Note: MultiSigRedeemScript.PaymentScript equals MultiSigAddress.ScriptPubKey
     this.depositScript =
         federationGatewaySettings?.MultiSigRedeemScript?.PaymentScript ??
         federationGatewaySettings?.MultiSigAddress?.ScriptPubKey;
     this.opReturnDataReader          = opReturnDataReader;
     this.settings                    = federationGatewaySettings;
     this.MinimumDepositConfirmations = federationGatewaySettings.MinimumDepositConfirmations;
 }
예제 #18
0
 public DepositExtractor(
     ILoggerFactory loggerFactory,
     IFederationGatewaySettings federationGatewaySettings,
     IOpReturnDataReader opReturnDataReader,
     IFullNode fullNode)
 {
     this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
     // Note: MultiSigRedeemScript.PaymentScript equals MultiSigAddress.ScriptPubKey
     this.depositScript =
         federationGatewaySettings?.MultiSigRedeemScript?.PaymentScript ??
         federationGatewaySettings?.MultiSigAddress?.ScriptPubKey;
     this.opReturnDataReader          = opReturnDataReader;
     this.MinimumDepositConfirmations = federationGatewaySettings.MinimumDepositConfirmations;
     this.chain = fullNode.NodeService <ConcurrentChain>();
 }
예제 #19
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);
        }
        public DepositExtractorTests()
        {
            this.network = new CirrusRegTest();

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

            this.federationSettings = Substitute.For <IFederatedPegSettings>();
            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); });

            this.depositExtractor   = new DepositExtractor(this.federationSettings, this.network, this.opReturnDataReader);
            this.transactionBuilder = new TestTransactionBuilder();
        }
        public WithdrawalExtractorTests()
        {
            this.network             = CirrusNetwork.NetworksSelector.Regtest();
            this.counterChainNetwork = Networks.Stratis.Regtest();

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

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

            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);
        }
        public DepositExtractorTests()
        {
            this.network = FederatedPegNetwork.NetworksSelector.Regtest();

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

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

            this.settings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);
            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);
        }
예제 #23
0
        public static bool TryGetTarget(Transaction transaction, IOpReturnDataReader opReturnDataReader, out bool conversion, out string targetAddress, out int targetChain)
        {
            conversion  = false;
            targetChain = 0 /* DestinationChain.STRAX */;

            // Check the common case first.
            if (!opReturnDataReader.TryGetTargetAddress(transaction, out targetAddress))
            {
                byte[] opReturnBytes = OpReturnDataReader.SelectBytesContentFromOpReturn(transaction).FirstOrDefault();

                if (opReturnBytes != null && InterFluxOpReturnEncoder.TryDecode(opReturnBytes, out int destinationChain, out targetAddress))
                {
                    targetChain = destinationChain;
                }
                else
                {
                    return(false);
                }

                conversion = true;
            }
예제 #24
0
        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).ReturnsForAnyArgs((string)null);

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

            this.withdrawalExtractor = new WithdrawalExtractor(
                this.loggerFactory, this.settings, this.opReturnDataReader, this.network);
        }
        public static bool TryGetTarget(Transaction transaction, IOpReturnDataReader opReturnDataReader, out bool conversion, out string targetAddress, out int targetChain)
        {
            conversion  = false;
            targetChain = 0 /* DestinationChain.STRAX */;

            // First check cross chain transfers from the STRAX to Cirrus network or vice versa.
            if (!opReturnDataReader.TryGetTargetAddress(transaction, out targetAddress))
            {
                // Else try and validate the destination adress by the destination chain.
                byte[] opReturnBytes = OpReturnDataReader.SelectBytesContentFromOpReturn(transaction).FirstOrDefault();

                if (opReturnBytes != null && InterFluxOpReturnEncoder.TryDecode(opReturnBytes, out int destinationChain, out targetAddress))
                {
                    targetChain = destinationChain;
                }
                else
                {
                    return(false);
                }

                conversion = true;
            }
        public DepositExtractorTests()
        {
            this.network = FederatedPegNetwork.NetworksSelector.Regtest();

            this.loggerFactory      = Substitute.For <ILoggerFactory>();
            this.settings           = Substitute.For <IFederationGatewaySettings>();
            this.opReturnDataReader = Substitute.For <IOpReturnDataReader>();
            this.fullNode           = Substitute.For <IFullNode>();
            this.fullNode.NodeService <ConcurrentChain>().Returns(this.chain);

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

            this.settings.MultiSigRedeemScript.Returns(this.addressHelper.PayToMultiSig);
            this.opReturnDataReader.TryGetTargetAddress(null).ReturnsForAnyArgs((string)null);

            this.transactionBuilder = new TestTransactionBuilder();

            this.depositExtractor = new DepositExtractor(
                this.loggerFactory,
                this.settings,
                this.opReturnDataReader,
                this.fullNode);
        }
예제 #27
0
 public DepositExtractor(IFederatedPegSettings federatedPegSettings, Network network, IOpReturnDataReader opReturnDataReader)
 {
     this.federatedPegSettings = federatedPegSettings;
     this.network            = network;
     this.opReturnDataReader = opReturnDataReader;
 }