private bool TryIncludeNewTransaction(NodeIndex nodeIndex, OngoingBlock ongoingBlock, Transaction newTransaction, out OngoingBlock newOngoingBlock) { NewTransactionIncludeResult includeResult; try { includeResult = _newTransactionValidator.Validate(nodeIndex, ongoingBlock, newTransaction); } catch (TransactionDeclinedException ex) { Trace.TraceWarning("Transaction message {0} will be declined: {1}", newTransaction.Signature, ex.Message); newOngoingBlock = default(OngoingBlock); return(false); } catch (Exception ex) { Trace.TraceWarning("Transaction message {0} will be ignored because of unexpected error: {1}", newTransaction.Signature, ex); newOngoingBlock = default(OngoingBlock); return(false); } if (includeResult.IsNone) { Trace.TraceWarning("Transaction message {0} will be declined: try to set a better fee", newTransaction.Signature); newOngoingBlock = default(OngoingBlock); return(false); } newOngoingBlock = ongoingBlock.Aggregate(newTransaction, includeResult.ToRemoveTransactions); return(true); }
public NodeState Add(Block nextBlock) { var newNodeIndex = NodeIndex.Add(nextBlock); var includedTransactions = nextBlock.Transactions.Select(t => t.Signature).ToHashSet(); var notIncludedTransactios = OngoingBlock.Transactions.Where(t => !includedTransactions.Contains(t.Signature)).ToArray(); var newOngoingBlock = new OngoingBlock(nextBlock.Index + 1, OngoingBlock.Node, nextBlock.Signature, notIncludedTransactios); return(new NodeState(newNodeIndex, newOngoingBlock)); }
private bool TryFindNextBlock(OngoingBlock ongoingBlock, out Block nextBlock) { var rnd = Guid.NewGuid().ToString("D"); nextBlock = _blockFactory.Create(ongoingBlock.Index, ongoingBlock.Node, rnd, ongoingBlock.PreviousHash, ongoingBlock.Transactions); Trace.TraceInformation("[node]\t\tCreated next block candidate {0}", nextBlock); return(_hashFilter.IsSatisfy(nextBlock.Signature, _nodeSettings.NextHashFactor)); }
public NodeState UpdateOngoingBlock(OngoingBlock newOngoingBlock) { return(new NodeState(NodeIndex, newOngoingBlock)); }
internal NodeState(NodeIndex nodeIndex, OngoingBlock ongoingBlock) { NodeIndex = nodeIndex ?? throw new NullReferenceException("nodeIndex"); OngoingBlock = ongoingBlock ?? throw new NullReferenceException("ongoingBlock"); }
public NodeState(INode node) { NodeIndex = NodeIndex.Empty; OngoingBlock = new OngoingBlock(1, node, HashValue.Empty, Array.Empty <Transaction>()); }