Ejemplo n.º 1
0
        private async Task <IOperationsFetcher> CreateSutInstanceAsync(
            string inMemoryDatabaseName = "operations_fetcher_tests",
            Func <IOperationsRepository, IOperationRequestsRepository, Task> seedAction = null)
        {
            var options = new DbContextOptionsBuilder <PbfContext>()
                          .UseInMemoryDatabase(inMemoryDatabaseName)
                          .Options;

            var dbFactory = new MsSqlContextFactory <PbfContext>(opts => new PbfContext(options, true), options);

            _operationsRepository = new OperationsRepository(dbFactory);

            _operationRequestsRepository = new OperationRequestsRepository(
                dbFactory,
                new SqlRepositoryHelper(new MemoryCache(new MemoryCacheOptions()), EmptyLogFactory.Instance));

            _executorClient = Mock.Of <IQuorumOperationExecutorClient>();

            if (seedAction != null)
            {
                await seedAction.Invoke(_operationsRepository, _operationRequestsRepository);
            }

            return(new OperationsFetcher(
                       MaxNewOperationsAmount,
                       MaxAcceptedOperationsAmount,
                       _operationsRepository,
                       _operationRequestsRepository
                       ));
        }
Ejemplo n.º 2
0
            public static async Task GetTransfersInProgressAsync_OperationTypeConditionCheck(
                IOperationsRepository repo,
                IOperationRequestsRepository requestsRepo,
                IQuorumOperationExecutorClient executorClient)
            {
                var rnd = new Random();

                var statusUpdater = new OperationStatusUpdater(
                    EmptyLogFactory.Instance,
                    new TransactionScopeHandler(EmptyLogFactory.Instance),
                    repo,
                    executorClient,
                    requestsRepo);

                var o1 = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    1,
                    FakeWalletAddress,
                    OperationType.TokensTransfer,
                    new TokensTransferContext
                {
                    SenderWalletAddress = FakeWalletAddress, RecipientWalletAddress = FakeWalletAddress, Amount = rnd.Next()
                }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[0]);

                var o2 = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    2,
                    FakeWalletAddress,
                    OperationType.CustomerWalletCreation,
                    new CustomerWalletContext { CustomerId = FakeCustomerId, WalletAddress = FakeWalletAddress }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[1]);

                await statusUpdater.SucceedAsync(ValidTransactionHashes[1]);

                var o3 = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    3,
                    FakeWalletAddress,
                    OperationType.CustomerBonusReward,
                    new CustomerBonusRewardContext
                {
                    CustomerId    = FakeCustomerId,
                    WalletAddress = FakeWalletAddress,
                    Amount        = rnd.Next(),
                    MinterAddress = FakeWalletAddress
                }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[2]);

                await statusUpdater.SucceedAsync(ValidTransactionHashes[2]);
            }
Ejemplo n.º 3
0
 public OperationStatusUpdater(ILogFactory logFactory,
                               ITransactionScopeHandler transactionScopeHandler,
                               IOperationsRepository operationsRepository,
                               IQuorumOperationExecutorClient executorClient,
                               IOperationRequestsRepository operationRequestsRepository)
 {
     _transactionScopeHandler     = transactionScopeHandler;
     _operationsRepository        = operationsRepository;
     _executorClient              = executorClient;
     _operationRequestsRepository = operationRequestsRepository;
     _log = logFactory.CreateLog(this);
 }
 public MintEventHandler(
     IRabbitPublisher <BonusRewardDetectedEvent> bonusRewardDetectedPublisher,
     IWalletOwnersRepository walletOwnersRepository,
     IBalanceService balanceService,
     ILogFactory logFactory,
     IQuorumOperationExecutorClient executorClient,
     IOperationsFetcher operationsFetcher)
 {
     _bonusRewardDetectedPublisher = bonusRewardDetectedPublisher;
     _walletOwnersRepository       = walletOwnersRepository;
     _balanceService    = balanceService;
     _executorClient    = executorClient;
     _operationsFetcher = operationsFetcher;
     _log = logFactory.CreateLog(this);
 }
 public BalanceService(
     IQuorumOperationExecutorClient quorumOperationExecutorClient,
     IWalletsService walletsService,
     TimeSpan cacheExpirationPeriod,
     IOperationsFetcher operationsFetcher,
     IRabbitPublisher <CustomerBalanceUpdatedEvent> customerBalanceUpdatedPublisher,
     ILogFactory logFactory, IDistributedCache distributedCache)
 {
     _quorumOperationExecutorClient = quorumOperationExecutorClient;
     _walletsService                  = walletsService;
     _cacheExpirationPeriod           = cacheExpirationPeriod;
     _operationsFetcher               = operationsFetcher;
     _customerBalanceUpdatedPublisher = customerBalanceUpdatedPublisher;
     _distributedCache                = distributedCache;
     _log = logFactory.CreateLog(this);
 }
 public TransferEventHandler(
     IRabbitPublisher <TransferDetectedEvent> transferDetectedPublisher,
     IRabbitPublisher <P2PTransferDetectedEvent> p2PTransferPublisher,
     ILogFactory logFactory,
     IBalanceService balanceService,
     IWalletOwnersRepository walletOwnersRepository,
     IOperationsFetcher operationsFetcher,
     IQuorumOperationExecutorClient executorClient)
 {
     _transferDetectedPublisher = transferDetectedPublisher;
     _p2PTransferPublisher      = p2PTransferPublisher;
     _balanceService            = balanceService;
     _walletOwnersRepository    = walletOwnersRepository;
     _operationsFetcher         = operationsFetcher;
     _executorClient            = executorClient;
     _log = logFactory.CreateLog(this);
 }
Ejemplo n.º 7
0
            public static async Task GetTransfersInProgressAsync_WalletAddressConditionCheck(
                IOperationsRepository repo,
                IOperationRequestsRepository requestsRepo,
                IQuorumOperationExecutorClient executorClient,
                string includeWalletAddress)
            {
                var rnd = new Random();

                var o = await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    1,
                    includeWalletAddress,
                    OperationType.TokensTransfer,
                    new TokensTransferContext
                {
                    SenderWalletAddress = FakeWalletAddress, RecipientWalletAddress = FakeWalletAddress, Amount = rnd.Next()
                }.ToJson(),
                    DateTime.UtcNow,
                    ValidTransactionHashes[0]);

                await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    2,
                    includeWalletAddress,
                    OperationType.TokensTransfer,
                    new TokensTransferContext
                {
                    SenderWalletAddress = FakeWalletAddress, RecipientWalletAddress = FakeWalletAddress, Amount = rnd.Next()
                }.ToJson(),
                    DateTime.UtcNow,
                    string.Empty);

                await repo.AddAsync(
                    Guid.NewGuid(),
                    FakeCustomerId,
                    3,
                    $"{includeWalletAddress}-{rnd.Next()}",
                    OperationType.CustomerWalletCreation,
                    new CustomerWalletContext { CustomerId = FakeCustomerId, WalletAddress = includeWalletAddress }
                    .ToJson(),
                    DateTime.UtcNow,
                    string.Empty);
            }
 public OperationOrchestratorService(
     int maxDegreeOfParallelism,
     int maxFailuresPerAddress,
     TimeSpan cleanAddressesWithFailuresTimeSpan,
     TimeSpan acceptedOperationsWarningTimeout,
     IPrivateBlockchainFacadeClient privateBlockchainFacadeClient,
     IQuorumOperationExecutorClient operationExecutorClient,
     ILogFactory logFactory)
 {
     _maxDegreeOfParallelism             = maxDegreeOfParallelism;
     _privateBlockchainFacadeClient      = privateBlockchainFacadeClient;
     _operationExecutorClient            = operationExecutorClient;
     _maxFailuresPerAddress              = maxFailuresPerAddress;
     _cleanAddressesWithFailuresTimeSpan = cleanAddressesWithFailuresTimeSpan;
     _acceptedOperationsWarningTimeout   = acceptedOperationsWarningTimeout;
     _log = logFactory.CreateLog(this);
     _addressesWithFailures = new Dictionary <string, ProcessingFailureInfo>();
 }
        /// <summary>
        ///    Get states of specified transactions.
        /// </summary>
        public static async Task <IEnumerable <GetTransactionStateResponse> > GetTransactionStatesAsync(
            this IQuorumOperationExecutorClient client,
            IEnumerable <string> txHashes,
            int batchSize = 8)
        {
            var result  = new List <GetTransactionStateResponse>();
            var batches = txHashes.Batch(batchSize);

            foreach (var batch in batches)
            {
                var getStates = batch
                                .Select(x => client.TransactionsApi.GetTransactionStateAsync(x))
                                .ToList();

                await Task.WhenAll(getStates);

                result.AddRange(getStates.Select(x => x.Result));
            }

            return(result);
        }
Ejemplo n.º 10
0
 public FeesService(IOperationRequestsProducer operationRequestsProducer, IQuorumOperationExecutorClient executorClient)
 {
     _operationRequestsProducer = operationRequestsProducer;
     _executorClient            = executorClient;
 }
Ejemplo n.º 11
0
 public TokensService(IQuorumOperationExecutorClient executorClient, string tokenGatewayAddress)
 {
     _executorClient      = executorClient;
     _tokenGatewayAddress = tokenGatewayAddress;
 }