public async Task TrackAsync(Script scriptPubkey) { await _RPCBatch.Do(async batch => { await batch.ImportAddressAsync(scriptPubkey, "", false).ConfigureAwait(false); return(true); }).ConfigureAwait(false); }
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.Do(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); } } }