public void GetAncestors(MemoryPoolRecord memPoolRecord, List <MemoryPoolRecord> records) { if (memPoolRecord == null) { throw new ArgumentNullException(nameof(memPoolRecord)); } if (memPoolRecord.ParentMemoryPool != null) { records.Add(memPoolRecord.ParentMemoryPool); GetAncestors(memPoolRecord.ParentMemoryPool, records); } }
public int CountAncestors(MemoryPoolRecord memPoolRecord) { if (memPoolRecord == null) { throw new ArgumentNullException(nameof(memPoolRecord)); } var ancestors = new List <MemoryPoolRecord>(); GetAncestors(memPoolRecord, ancestors); if (ancestors == null) { return(1); } return(ancestors.Count() + 1); }
public int CountDescendants(MemoryPoolRecord memPoolRecord) { if (memPoolRecord == null) { throw new ArgumentNullException(nameof(memPoolRecord)); } if (memPoolRecord.Transaction == null) { throw new ArgumentNullException(nameof(memPoolRecord.Transaction)); } var descendants = new List <MemoryPoolRecord>(); GetDescendants(memPoolRecord, descendants); if (descendants == null) { return(1); } return(descendants.Count() + 1); }
public void AddTransaction(BaseTransaction transaction, int blockHeight) { if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } var record = new MemoryPoolRecord(transaction, DateTime.UtcNow, blockHeight); var noneCoinBaseTx = transaction as NoneCoinbaseTransaction; if (noneCoinBaseTx != null) { var txIn = noneCoinBaseTx.TransactionIn.First() as TransactionInNoneCoinbase; var parent = GetUnspentMemoryRecord(txIn.Outpoint.Hash, txIn.Outpoint.Index); if (parent != null) { record.ParentMemoryPool = parent; } } _transactions.Add(record); }
public void GetDescendants(MemoryPoolRecord memPoolRecord, List <MemoryPoolRecord> records) { if (memPoolRecord == null) { throw new ArgumentNullException(nameof(memPoolRecord)); } if (memPoolRecord.Transaction == null) { throw new ArgumentNullException(nameof(memPoolRecord.Transaction)); } var transaction = memPoolRecord.Transaction as BcBaseTransaction; if (transaction != null && transaction.TransactionOut != null && transaction.TransactionOut.Any()) { var txs = _transactions.Where(t => { var noneCbTx = t.Transaction as NoneCoinbaseTransaction; if (noneCbTx == null) { return(false); } var txIn = noneCbTx.TransactionIn.First() as TransactionInNoneCoinbase; return(txIn.Outpoint.Hash.SequenceEqual(transaction.GetTxId())); }); if (txs == null || !txs.Any()) { return; } records.AddRange(txs); foreach (var m in txs) { GetDescendants(m, records); } } }