Ejemplo n.º 1
0
        public TransactionPool(ITransactionStorage transactionStorage,
                               IPendingTransactionThresholdValidator pendingTransactionThresholdValidator,
                               ITimestamp timestamp, IEthereumEcdsa ecdsa, ISpecProvider specProvider, ILogManager logManager,
                               int removePendingTransactionInterval = 600,
                               int peerNotificationThreshold        = 20)
        {
            _logger             = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _transactionStorage = transactionStorage ?? throw new ArgumentNullException(nameof(transactionStorage));
            _pendingTransactionThresholdValidator = pendingTransactionThresholdValidator;
            _timestamp    = timestamp ?? throw new ArgumentNullException(nameof(timestamp));
            _ecdsa        = ecdsa ?? throw new ArgumentNullException(nameof(ecdsa));
            _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider));
            _peerNotificationThreshold = peerNotificationThreshold;
            if (removePendingTransactionInterval <= 0)
            {
                return;
            }

            var timer = new Timer(removePendingTransactionInterval * 1000);

            timer.Elapsed += OnTimerElapsed;
            timer.Start();

            _ownTimer           = new Timer(500);
            _ownTimer.Elapsed  += OwnTimerOnElapsed;
            _ownTimer.AutoReset = false;
            _ownTimer.Start();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionService"/> class.
 /// </summary>
 /// <param name="storage">Storage engine to retrieve transactions from</param>
 public SubscriptionService(ITransactionStorage storage)
 {
     this.Storage      = storage;
     this.eventHandler = this.EventHandler;
     this.Storage.TransactionCommitted += this.eventHandler;
     this.subscriptions = new ConcurrentDictionary <Guid, Subscription>();
 }
        /// <summary>
        /// Removes the transaction session.
        /// </summary>
        /// <typeparam name="TStepId">The type of the step id.</typeparam>
        /// <typeparam name="TData">The type of the transaction data.</typeparam>
        /// <param name="storage">The storage.</param>
        /// <param name="session">the session.</param>
#if NET35 || NOASYNC
        public static void RemoveSession <TStepId, TData>(this ITransactionStorage <TData> storage, ITransactionSession <TStepId, TData> session)
        {
            if (storage != null)
            {
                storage.RemoveSession(new TransactionData <TStepId, TData>(session));
            }
        }
        /// <summary>
        /// Notifies that that a new step was prepared to run.
        /// </summary>
        /// <typeparam name="TStepId">The type of the step id.</typeparam>
        /// <typeparam name="TData">The type of the transaction data.</typeparam>
        /// <param name="storage">The storage.</param>
        /// <param name="session">the session.</param>
#if NET35 || NOASYNC
        public static void StepPrepared <TStepId, TData>(this ITransactionStorage <TData> storage, ITransactionSession <TStepId, TData> session)
        {
            if (storage != null)
            {
                storage.StepPrepared(new TransactionData <TStepId, TData>(session));
            }
        }
 public static async Task StepReceding <TStepId, TData>(this ITransactionStorage <TData> storage, ITransactionSession <TStepId, TData> session)
 {
     if (storage != null)
     {
         await storage.StepReceding(new TransactionData <TStepId, TData>(session));
     }
 }
Ejemplo n.º 6
0
        public override async Task OnActivateAsync()
        {
            GrainType          = GetType();
            transactionStorage = ServiceProvider.GetService <ITransactionStorage>();
            var inputList = await transactionStorage.GetList <Input>(GrainType.FullName);

            foreach (var input in inputList)
            {
                inputDict.TryAdd(input.TransactionId, input);
            }
            RegisterTimer(async state =>
            {
                foreach (var commit in inputDict.Values.ToList())
                {
                    var actors = GetTransactionActors(commit.Data);
                    try
                    {
                        await AutoCommit(commit, actors);
                    }
                    catch (Exception ex)
                    {
                        await Rollback(commit, actors);
                        Logger.LogCritical(ex, ex.Message);
                    }
                }
            }, null, new TimeSpan(0, 5, 0), new TimeSpan(0, 1, 0));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpServer"/> class.
 /// </summary>
 /// <param name="baseAddress">Base listening address of HTTP server</param>
 /// <param name="storage">Storage engine used</param>
 public HttpServer(string baseAddress, ITransactionStorage storage)
     : this()
 {
     this.baseAddress         = baseAddress;
     this.Storage             = storage;
     this.subscriptionService = new SubscriptionService(storage);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a transaction.
        /// </summary>
        /// <typeparam name="TStepId">The type of the step id.</typeparam>
        /// <typeparam name="TData">The type of the transaction data.</typeparam>
        /// <param name="options">The action to set options.</param>
        /// <returns>The transaction.</returns>
        public ITransaction <TStepId, TData> Create <TStepId, TData>(Action <ICreateTransactionContext <TStepId, TData> > options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            ICreateTransactionContext <TStepId, TData> context = new CreateTransactionContext <TStepId, TData>();

            options(context);
            ILogger logger = this.CreateLogger <TStepId, TData>(context);
            ITransactionCreateInfo <TStepId>   info        = this.CreateTransactionInfo <TStepId, TData>(context);
            CreatePartContext <TStepId, TData> partContext = new CreatePartContext <TStepId, TData>()
            {
                Context = context,
                Logger  = logger,
                Info    = info
            };
            ITransactionDefinition <TStepId, TData> definition   = this.CreateDefinition <TStepId, TData>(partContext);
            ITransactionStorage <TData>             stateStorage = this.CreateStateStorage <TStepId, TData>(partContext);

            TransactionContext <TStepId, TData> transactionContext = new TransactionContext <TStepId, TData>()
            {
                Logger         = logger,
                Info           = info,
                Definition     = definition,
                SessionStorage = stateStorage
            };

            return(new Transaction <TStepId, TData>(transactionContext));
        }
Ejemplo n.º 9
0
 public void Setup()
 {
     _transactionStorage = new MemoryTransactionStorage(new RegularTransactionFactory());
     _storage            = new MemoryBarCodeStorage(new BarCodeFactory(), _transactionStorage);
     _storage.CreateBarCode("55555555555", false, 0);
     _storage.CreateBarCode("44444444444", true, 5);
 }
Ejemplo n.º 10
0
        public ScriptingProvider(ITransactionStorage storage)
        {
            this._transactionCommittedEventHandler = this.OnTransactionCommitted;
            this._runners  = new ConcurrentDictionary <string, IScriptRunner>(StringComparer.OrdinalIgnoreCase);
            this._compiled = new ConcurrentDictionary <string, Action <IDependencyResolver> >(StringComparer.OrdinalIgnoreCase);

            this._storage = storage;
        }
Ejemplo n.º 11
0
 public ConfigurationService(IEncodedBlocksStorage encodedBlocksStorage, ITransactionStorage transactionStorage,
                             IServiceProvider serviceProvider, IConfiguration configuration, IBackgroundQueue queue)
 {
     _encodedBlocksStorage = encodedBlocksStorage;
     _transactionStorage   = transactionStorage;
     _serviceProvider      = serviceProvider;
     _configuration        = configuration;
     _queue = queue;
 }
Ejemplo n.º 12
0
 public TransactionService(IConfigurationService configurationService, IBlockchainService blockchainService,
                           IMiningService miningService, IMiningQueue queue, ITransactionStorage transactionStorage)
     : base(configurationService)
 {
     _transactionStorage = transactionStorage;
     _blockchainService  = blockchainService;
     _miningService      = miningService;
     _queue = queue;
 }
Ejemplo n.º 13
0
        public IEnumerable <ITransaction> GetTransactions(ITransactionStorage transactionStorage)
        {
            var temp = ApplyFilterByDate(transactionStorage);

            temp = ApplyFilterByAccount(temp);
            temp = ApplyFilterByCategory(temp);

            return(temp);
        }
Ejemplo n.º 14
0
 public CategoryTransactionsReportViewModel(IAccountStorage accountStorage, ICategoryStorage categoryStorage, ITransactionStorage transactionStorage)
 {
     _accountStorage     = accountStorage ?? throw new ArgumentNullException(nameof(accountStorage));
     _categoryStorage    = categoryStorage ?? throw new ArgumentNullException(nameof(categoryStorage));;
     _transactionStorage = transactionStorage ?? throw new ArgumentNullException(nameof(transactionStorage));
     _filteredSource     = new TransactionFilteredSource(DateTime.Now, DateTime.Now);
     Accounts            = new ObservableCollection <IAccount>(_accountStorage.GetAllAccounts());
     Categories          = new ObservableCollection <ICategory>(_categoryStorage.MakeFlatCategoryTree());
     StartDate           = DateTimeOffset.Now;
     EndDate             = StartDate;
 }
Ejemplo n.º 15
0
 public void Setup()
 {
     _genesisBlock                 = Build.A.Block.WithNumber(0).TestObject;
     _remoteBlockTree              = Build.A.BlockTree(_genesisBlock).OfChainLength(0).TestObject;
     _logManager                   = LimboLogs.Instance;
     _specProvider                 = RopstenSpecProvider.Instance;
     _ethereumEcdsa                = new EthereumEcdsa(_specProvider, _logManager);
     _noTransactionStorage         = NullTransactionStorage.Instance;
     _inMemoryTransactionStorage   = new InMemoryTransactionStorage();
     _persistentTransactionStorage = new PersistentTransactionStorage(new MemDb(), _specProvider);
 }
Ejemplo n.º 16
0
 public void Setup()
 {
     _factory            = new BarCodeFactory();
     _accountStorage     = new SqLiteAccountStorage(new RegularAccountFactory());
     _categoryStorage    = new SqLiteCategoryStorage(new RegularCategoryFactory());
     _transactionStorage =
         new SqLiteTransactionStorage(new RegularTransactionFactory(), _accountStorage, _categoryStorage);
     _storage = new SqLiteBarCodeStorage(
         new BarCodeFactory(), _transactionStorage);
     _storage.DeleteAllData();
 }
Ejemplo n.º 17
0
        public void Setup()
        {
            var accountFactory  = new RegularAccountFactory();
            var categoryFactory = new RegularCategoryFactory();

            _accountStorage  = new CachedAccountStorage(new SqLiteAccountStorage(accountFactory));
            _categoryStorage = new CachedCategoryStorage(new SqLiteCategoryStorage(categoryFactory));
            var transactionFactory = new RegularTransactionFactory();

            _storage = new CachedTransactionStorage(new SqLiteTransactionStorage(transactionFactory, _accountStorage, _categoryStorage));
            _storage.DeleteAllData();
            CreateTransaction();
        }
Ejemplo n.º 18
0
 public void Setup()
 {
     accountStorage     = new CachedAccountStorage(new SqLiteAccountStorage(new RegularAccountFactory()));
     categoryStorage    = new CachedCategoryStorage(new SqLiteCategoryStorage(new RegularCategoryFactory()));
     transactionFactory = new RegularTransactionFactory();
     storage            = new CachedTransactionStorage(new SqLiteTransactionStorage(transactionFactory, accountStorage, categoryStorage));
     categoryStorage.DeleteAllData();
     accountStorage.DeleteAllData();
     storage.DeleteAllData();
     transaction       = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
     childTransaction  = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
     childTransaction1 = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
 }
Ejemplo n.º 19
0
        private Transactions AddAndFilterTransactions(ITransactionStorage storage, params ITransactionFilter[] filters)
        {
            _transactionPool = CreatePool(storage);
            foreach (var filter in filters ?? Enumerable.Empty <ITransactionFilter>())
            {
                _transactionPool.AddFilter(filter);
            }

            var pendingTransactions  = AddTransactionsToPool();
            var filteredTransactions = GetTransactionsFromStorage(storage, pendingTransactions);

            return(new Transactions(pendingTransactions, filteredTransactions));
        }
Ejemplo n.º 20
0
 public MiningService(IBlockchainService blockchainService, IConsensusService consensusService,
                      IStatisticService statisticService, IServiceProvider serviceProvider, IBlockProvider blockProvider,
                      IMiningQueue miningQueue, IBackgroundQueue backgroundQueue, IConfigurationService configurationService,
                      ITransactionStorage transactionStorage) : base(configurationService)
 {
     _blockchainService  = blockchainService;
     _consensusService   = consensusService;
     _statisticService   = statisticService;
     _serviceProvider    = serviceProvider;
     _blockProvider      = blockProvider;
     _miningQueue        = miningQueue;
     _backgroundQueue    = backgroundQueue;
     _transactionStorage = transactionStorage;
 }
Ejemplo n.º 21
0
        public Report1ViewModel(IAccountStorage accountStorage, ICategoryStorage categoryStorage, ITransactionStorage transactionStorage)
        {
            _accountStorage     = accountStorage ?? throw new ArgumentNullException(nameof(accountStorage));
            _categoryStorage    = categoryStorage ?? throw new ArgumentNullException(nameof(categoryStorage));;
            _transactionStorage = transactionStorage ?? throw new ArgumentNullException(nameof(transactionStorage));

            Accounts     = new ObservableCollection <IAccount>(_accountStorage.GetAllAccounts());
            Account      = Accounts.FirstOrDefault();
            ReportPeriod = new ObservableCollection <string>
            {
                "All period",
                "Today",
                "Yesterday",
                "This Month",
                "Last Month"
            };
        }
Ejemplo n.º 22
0
        public static IBarCode Convert(IDictionary <string, object> line, IBarCodeFactory barCodeFactory,
                                       ITransactionStorage transactionStorage)
        {
            var code           = line["code"].ToString();
            var isWeight       = ((long)line["isWeight"] == 1);
            var numberOfDigits = System.Convert.ToInt32((long)line["numberOfDigits"]);
            var transactionId  = (line["transactionId"] is System.DBNull) ? 0 : (long)line["transactionId"];

            var barCode = barCodeFactory.CreateBarCode(code, isWeight, numberOfDigits);

            if (transactionId != 0)
            {
                barCode.Transaction = transactionStorage.GetAllTransactions().FirstOrDefault(x => x.Id == transactionId);
            }
            barCode.Id = (long)line["id"];

            return(barCode);
        }
Ejemplo n.º 23
0
        public MainWindow(IPOExchangeInstitution ipoExchangeInstitution)
        {
            _ipoExchangeInstitution = ipoExchangeInstitution;

            _bank = Injector.Get <IBank>();
            _bank.SetChainChangeListener(this);

            _chainStorage       = Injector.Get <IChainStorage>();
            _transactionStorage = Injector.Get <ITransactionStorage>();

            InitializeComponent();
            FillExchangeUsersList();
            FillBaseData();
            FillCompanies();

            _exchangeTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(300)
            };
            _exchangeTimer.Tick += _exchangeTimer_Tick;

            _ipoExchangeInstitution.ExchangeStepExecuted += IpoExchangeInstitutionOnExchangeStepExecuted;
        }
Ejemplo n.º 24
0
        public TransactionPool(ITransactionStorage transactionStorage,
                               IPendingTransactionThresholdValidator pendingTransactionThresholdValidator,
                               ITimestamp timestamp, IEthereumSigner signer, ILogManager logManager,
                               int removePendingTransactionInterval = 600,
                               int peerNotificationThreshold        = 20)
        {
            _logger             = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _transactionStorage = transactionStorage;
            _pendingTransactionThresholdValidator = pendingTransactionThresholdValidator;
            _timestamp = timestamp;
            _signer    = signer;
            _peerNotificationThreshold = peerNotificationThreshold;
            if (removePendingTransactionInterval <= 0)
            {
                return;
            }

            var timer = new Timer {
                Interval = removePendingTransactionInterval * 1000
            };

            timer.Elapsed += OnTimerElapsed;
            timer.Start();
        }
Ejemplo n.º 25
0
 public Report2(ITransactionStorage transactionStorage)
 {
     _transactionStorage = transactionStorage;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionHandlingController"/> class.
 /// </summary>
 /// <param name="storage">Storage engine used by the controller</param>
 public TransactionHandlingController(ITransactionStorage storage)
 {
     this.storage = storage;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Transaction"/> class.
 /// </summary>
 /// <param name="data">Reference to mutable data for transaction</param>
 /// <param name="storage">Storage engine that produced the transaction</param>
 public Transaction(ref TransactionData data, ITransactionStorage storage)
 {
     this.data    = data;
     this.Storage = storage;
 }
Ejemplo n.º 28
0
 private static IEnumerable <Transaction> GetTransactionsFromStorage(ITransactionStorage storage,
                                                                     IEnumerable <Transaction> transactions)
 => transactions.Select(t => storage.Get(t.Hash)).Where(t => !(t is null)).ToArray();
Ejemplo n.º 29
0
 private TransactionPool CreatePool(ITransactionStorage transactionStorage)
 => new TransactionPool(transactionStorage, new PendingTransactionThresholdValidator(),
                        new Timestamp(), _ethereumEcdsa, _specProvider, _logManager);
 public TransactionRepository(ITransactionStorage transactionStorage)
 {
     _transactionStorage = transactionStorage;
 }