internal static void AddTransactionToLedger(Bank bank, Transaction transaction) { bank.Ledger.Add(transaction); int from = bank.AllAccounts.FindIndex(x => x.accountID == transaction.FromAccount.accountID); int to = bank.AllAccounts.FindIndex(x => x.accountID == transaction.ToAccount.accountID); bank.AllAccounts[from].ChangeMoney(transaction); bank.AllAccounts[to].ChangeMoney(transaction); OnTransactionProcessed?.Invoke(transaction); }
private IEnumerator TransactionPolling(string txHash) { //create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(Url); //checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(txHash, 2)); Logger("Transaction mined"); onTransactionDelegate?.Invoke(txHash); }
public void Run() { var cancellationToken = _cancellationTokenSource.Token; Task.Factory.StartNew(async() => { while (!cancellationToken.IsCancellationRequested) { if (!_unverifiedTransactionPool.Any()) { await _asyncDelayer.Delay(DefaultTransactionPollingInterval, cancellationToken); continue; } var unverifiedTransactionHashes = _unverifiedTransactionPool.Keys; var transactionPool = _verifiedTransactionPool.Concat( _unverifiedTransactionPool.Values.Where(t => unverifiedTransactionHashes.Contains(t.Hash))) .ToArray(); foreach (var transactionHash in unverifiedTransactionHashes) { if (!_unverifiedTransactionPool.TryGetValue(transactionHash, out var transaction)) { continue; } var valid = this._transactionVerifier.Verify(transaction); if (transactionPool .Where(t => t.Hash != transactionHash) .Where(p => p != transaction) .SelectMany(p => p.Inputs) .Intersect(transaction.Inputs) .Any()) { valid = false; } if (valid) { _verifiedTransactionPool.Add(transaction); } _unverifiedTransactionPool.TryRemove(transactionHash, out _); OnTransactionProcessed?.Invoke(this, transaction); } } }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
/// <summary> /// Initializes a new instance of the <see cref="MerchantProcessor" /> class. /// </summary> /// <param name="transaction">The transaction.</param> protected MerchantProcessor(IMerchantTransaction transaction) { SharedTransactionScope = transaction; Solvers = new List <ISolverBase <IMerchantTransaction> >() { new RomanSolver(SharedTransactionScope), new UnitSolver(SharedTransactionScope) }; Parsers = new List <IParserEngine <IMerchantTransaction> >() { new RomanBaseParser(SharedTransactionScope), new UnitParser(SharedTransactionScope), new EnquiryParser(SharedTransactionScope) }; Solvers.ToList().ForEach(p => p.OnSolveCompleted += (s, a) => OnTransactionProcessed?.Invoke(s, a)); }