private async Task <bool> TryBroadcastCoreAsync(Record tx, int currentHeight) { bool remove = false; try { remove = currentHeight >= tx.Expiration; //Happens when the caller does not know the previous input yet if (tx.Transaction.Inputs.Count == 0 || tx.Transaction.Inputs[0].PrevOut.Hash == uint256.Zero) { return(false); } bool isFinal = tx.Transaction.IsFinal(DateTimeOffset.UtcNow, currentHeight + 1); if (!isFinal || IsDoubleSpend(tx.Transaction)) { return(false); } try { await _RPCBatch.WaitTransactionAsync(async batch => { await batch.SendRawTransactionAsync(tx.Transaction).ConfigureAwait(false); return(true); }).ConfigureAwait(false); _Cache.ImportTransaction(tx.Transaction, 0); Logs.Broadcasters.LogInformation($"Broadcasted {tx.Transaction.GetHash()}"); return(true); } catch (RPCException ex) { if (ex.RPCResult == null || ex.RPCResult.Error == null) { return(false); } var error = ex.RPCResult.Error.Message; if (ex.RPCResult.Error.Code != RPCErrorCode.RPC_TRANSACTION_ALREADY_IN_CHAIN && !error.EndsWith("bad-txns-inputs-spent", StringComparison.OrdinalIgnoreCase) && !error.EndsWith("txn-mempool-conflict", StringComparison.OrdinalIgnoreCase) && !error.EndsWith("Missing inputs", StringComparison.OrdinalIgnoreCase)) { remove = false; } } return(false); } finally { if (remove) { RemoveRecord(tx); } } }
public bool TrackPrunedTransaction(Transaction transaction, MerkleBlock merkleProof) { var result = RPCClient.SendCommandNoThrows("importprunedfunds", transaction.ToHex(), Encoders.Hex.EncodeData(merkleProof.ToBytes())); var success = result != null && result.Error == null; if (success) { _Cache.ImportTransaction(transaction, GetBlockConfirmations(merkleProof.Header.GetHash())); } return(success); }
public async Task <bool> TrackPrunedTransactionAsync(Transaction transaction, MerkleBlock merkleProof) { return(await _RPCBatch.Do(async batch => { var result = await batch.SendCommandNoThrowsAsync("importprunedfunds", transaction.ToHex(), Encoders.Hex.EncodeData(merkleProof.ToBytes())).ConfigureAwait(false); var success = result != null && result.Error == null; if (success) { _Cache.ImportTransaction(transaction, GetBlockConfirmations(merkleProof.Header.GetHash())); } return success; }).ConfigureAwait(false)); }