public async Task <QueryTransactionStatusResponse> QueryTransaction(string id) { var currentMinerId = await minerId.GetCurrentMinerIdAsync(); var(result, allTheSame, exception) = await rpcMultiClient.GetRawTransactionAsync(id); if (exception != null && result == null) // only report errors none of the nodes return result or if we got RpcExcpetion (such as as transaction not found) { return(new QueryTransactionStatusResponse { Timestamp = clock.UtcNow(), Txid = id, ReturnResult = "failure", ResultDescription = GetSafeExceptionDescription(exception), MinerID = currentMinerId, }); } // report mixed errors if we got mixed result or if we got some successful results and some RpcException. // Ordinary exception might indicate connectivity problems, so we skip them if (!allTheSame || (exception as AggregateException)?.GetBaseException() is RpcException) { return(new QueryTransactionStatusResponse { Timestamp = clock.UtcNow(), Txid = id, ReturnResult = "failure", ResultDescription = "Mixed results", MinerID = currentMinerId, }); } return(new QueryTransactionStatusResponse { Timestamp = clock.UtcNow(), Txid = id, ReturnResult = "success", ResultDescription = null, BlockHash = result.Blockhash, BlockHeight = result.Blockheight, Confirmations = result.Confirmations, MinerID = currentMinerId //TxSecondMempoolExpiry }); }
private async Task <string> SignIfRequiredAsync <T>(T response) { string payload = HelperTools.JSONSerialize(response, false); if (minerId == null) { // Do not sign if we do not have miner id return(payload); } lastMinerId ??= await minerId.GetCurrentMinerIdAsync(); async Task <JsonEnvelope> TryToSign() { async Task <(string signature, string publicKey)> signWithMinerId(string sigHashHex) { var signature = await minerId.SignWithMinerIdAsync(lastMinerId, sigHashHex); return(signature, lastMinerId); } var envelope = await JsonEnvelopeSignature.CreateJSonSignatureAsync(payload, signWithMinerId); // Verify a signature - some implementation might have incorrect race conditions when rotating the keys if (!JsonEnvelopeSignature.VerifySignature(envelope)) { return(null); } return(envelope); } var jsonEnvelope = await TryToSign(); if (jsonEnvelope == null) { throw new Exception("Error while validating signature. Possible reason: incorrect configuration or key rotation"); } return(HelperTools.JSONSerialize(new SignedPayloadViewModel(jsonEnvelope), true)); }
private async Task <ActionResult> FillFeeQuoteViewModelWithInfo <T>(T feeQuoteViewModelGet) where T : FeeQuoteViewModelGet { feeQuoteViewModelGet.ExpiryTime = feeQuoteViewModelGet.Timestamp.Add(TimeSpan.FromMinutes(quoteExpiryMinutes)); var info = await blockChainInfo.GetInfoAsync(); feeQuoteViewModelGet.MinerId = await minerId.GetCurrentMinerIdAsync(); feeQuoteViewModelGet.CurrentHighestBlockHash = info.BestBlockHash; feeQuoteViewModelGet.CurrentHighestBlockHeight = info.BestBlockHeight; logger.LogInformation($"Returning {nameof(feeQuoteViewModelGet)} with ExpiryTime: {feeQuoteViewModelGet.ExpiryTime}."); return(await SignIfRequiredAsync(feeQuoteViewModelGet, feeQuoteViewModelGet.MinerId)); }
private async Task TestMinerId() { try { logger.LogInformation($"Checking MinerId"); var currentMinerId = await minerId.GetCurrentMinerIdAsync(); await minerId.SignWithMinerIdAsync(currentMinerId, "5bdc7d2ca32915a311f91a6b4b8dcefd746b1a73d355a65cbdee425e4134d682"); logger.LogInformation($"MinerId check completed successfully"); } catch (Exception e) { logger.LogError($"Can not access MinerID. {e.Message}"); throw; } }
public async Task <ActionResult <FeeQuoteViewModelGet> > GetFeeQuote() { if (!IdentityProviderStore.GetUserAndIssuer(User, Request.Headers, out var identity)) { return(Unauthorized("Incorrectly formatted token")); } logger.LogInformation($"Get FeeQuote for user { ((identity == null) ? "/" : identity.ToString() )} ..."); FeeQuote feeQuote = feeQuoteRepository.GetCurrentFeeQuoteByIdentity(identity); if (feeQuote == null) { logger.LogInformation($"There are no active feeQuotes."); return(NotFound()); } var feeQuoteViewModelGet = new FeeQuoteViewModelGet(feeQuote) { Timestamp = clock.UtcNow(), }; feeQuoteViewModelGet.ExpiryTime = feeQuoteViewModelGet.Timestamp.Add(TimeSpan.FromMinutes(quoteExpiryMinutes)); var info = blockChainInfo.GetInfo(); feeQuoteViewModelGet.MinerId = await minerId.GetCurrentMinerIdAsync(); feeQuoteViewModelGet.CurrentHighestBlockHash = info.BestBlockHash; feeQuoteViewModelGet.CurrentHighestBlockHeight = info.BestBlockHeight; logger.LogInformation($"Returning feeQuote with ExpiryTime: {feeQuoteViewModelGet.ExpiryTime}."); return(await SignIfRequiredAsync(feeQuoteViewModelGet, feeQuoteViewModelGet.MinerId)); }