public async Task <ICollection <TransactionInformation> > GetTransactionsAsync(Script scriptPubKey, bool withProof) { if (scriptPubKey == null) { throw new ArgumentNullException(nameof(scriptPubKey)); } var results = _Cache .GetEntriesFromScript(scriptPubKey) .Select(entry => new TransactionInformation() { Confirmations = entry.Confirmations, Transaction = entry.Transaction }).ToList(); if (withProof) { foreach (var tx in results.ToList()) { var completion = new TaskCompletionSource <MerkleBlock>(); bool isRequester = true; var txid = tx.Transaction.GetHash(); _GettingProof.AddOrUpdate(txid, completion, (k, o) => { isRequester = false; completion = o; return(o); }); if (isRequester) { try { MerkleBlock proof = null; var result = await RPCClient.SendCommandNoThrowsAsync("gettxoutproof", new JArray(tx.Transaction.GetHash().ToString())).ConfigureAwait(false); if (result == null || result.Error != null) { completion.TrySetResult(null); continue; } proof = new MerkleBlock(); proof.ReadWrite(Encoders.Hex.DecodeData(result.ResultString)); tx.MerkleProof = proof; completion.TrySetResult(proof); } catch (Exception ex) { completion.TrySetException(ex); } finally { _GettingProof.TryRemove(txid, out completion); } } var merkleBlock = await completion.Task.ConfigureAwait(false); if (merkleBlock == null) { results.Remove(tx); } } } return(results); }
public ICollection <TransactionInformation> GetTransactions(Script scriptPubKey, bool withProof) { if (scriptPubKey == null) { throw new ArgumentNullException(nameof(scriptPubKey)); } var results = _Cache .GetEntriesFromScript(scriptPubKey) .Select(entry => new TransactionInformation() { Confirmations = entry.Confirmations, Transaction = entry.Transaction }).ToList(); if (withProof) { foreach (var tx in results.ToList()) { MerkleBlock proof = null; var result = RPCClient.SendCommandNoThrows("gettxoutproof", new JArray(tx.Transaction.GetHash().ToString())); if (result == null || result.Error != null) { results.Remove(tx); continue; } proof = new MerkleBlock(); proof.ReadWrite(Encoders.Hex.DecodeData(result.ResultString)); tx.MerkleProof = proof; } } return(results); }