/// <summary> /// Gets a raw transaction that is present on this full node. /// This method first searches the transaction pool and then tries the block store. /// </summary> /// <param name="txid">The transaction ID (a hash of the trancaction).</param> /// <param name="verbose">A flag that specifies whether to return verbose information about the transaction.</param> /// <returns>Json formatted <see cref="RawTransactionResponse"/> or <see cref="RawTransactionResponse"/>. <c>null</c> if transaction not found. Returns a formatted error if otherwise fails.</returns> public async Task <RawTransactionResponse> GetRawTransaction(string txid, bool verbose) { RawTransactionResponse rawTransactionResult = await restClient.GetRawTransaction(txid, verbose); Guard.Null(rawTransactionResult, nameof(rawTransactionResult), $"An Error Occured When Trying To Get The Raw Transaction for '{txid}' with verbose '{verbose}'"); return(rawTransactionResult); }
/// <summary> /// Gets a JSON representation for a given transaction in hex format. /// </summary> /// <param name="rawHex">A string containing the necessary parameters for a block search request.</param> /// <returns>The raw transaction result of the transaction.</returns> public async Task <RawTransactionResponse> DecodeRawTransaction(string rawHex) { RawTransactionResponse rawTransactionResult = await restClient.DecodeRawTransaction(rawHex); Guard.Null(rawTransactionResult, nameof(rawTransactionResult), $"An Error Occured When Trying To decode the Transaction for '{rawHex}'"); return(rawTransactionResult); }
public ActionResult RenderTransaction(string id) { RawTransactionResponse vtr = _transaction.Get(id); TransactionDetail td = new TransactionDetail(); List <TransactionDetail> list = td.Get(vtr); return(View("Parts/txDetails", list)); }
/// <summary> /// Get transaction details for a given transaction hash /// </summary> /// <param name="id">Transaction Hash</param> /// <returns></returns> public ActionResult Tx(string id) { RawTransactionResponse vtr = _transaction.Get(id); if (vtr == null) { ExplorerError error = new ExplorerError(); error.Errors.Add("Transaction not found. Try again or contact us for assistance"); TempData["Errors"] = error; return(RedirectToAction("Index")); } return(View(vtr)); }
/// <summary> /// Gets a raw transaction that is present on this full node. /// This method first searches the transaction pool and then tries the block store. /// </summary> /// <param name="txid">The transaction ID (a hash of the trancaction).</param> /// <param name="verbose">A flag that specifies whether to return verbose information about the transaction.</param> /// <returns>Json formatted <see cref="RawTransactionResponse"/> or <see cref="RawTransactionResponse"/>. <c>null</c> if transaction not found. Returns a formatted error if otherwise fails.</returns> public async Task <RawTransactionResponse> GetRawTransaction(string txid, bool verbose) { try { Guard.Null(txid, nameof(txid), "Unable to get raw tx, Provided transaction id Is NULL/Empty!"); StringBuilder queryURL = new StringBuilder($"api/Node/getrawtransaction?trxid={txid}&verbose={verbose}"); RawTransactionResponse response = await base.SendGet <RawTransactionResponse>(queryURL.ToString()); Guard.Null(response, nameof(response), "'api/Node/getrawtransaction' API Response Was Null!"); return(response); } catch (Exception ex) { logger.LogCritical($"An Error '{ex.Message}' Occured When Getting raw transaction For '{txid}'!", ex); throw; } }
/// <summary> /// Gets a JSON representation for a given transaction in hex format. /// </summary> /// <param name="rawHex">A string containing the necessary parameters for a block search request.</param> /// <returns>The raw transaction result of the transaction.</returns> public async Task <RawTransactionResponse> DecodeRawTransaction(string rawHex) { try { Guard.Null(rawHex, nameof(rawHex), "Unable to decode raw tx, Provided raw hex Is NULL/Empty!"); DecodeRawTransactionRequest decodeTxRequest = new DecodeRawTransactionRequest { RawHex = rawHex }; RawTransactionResponse response = await base.SendPostJSON <RawTransactionResponse>("api/Node/decoderawtransaction", decodeTxRequest); Guard.Null(response, nameof(response), "'api/Node/decoderawtransaction' API Response Was Null!"); return(response); } catch (Exception ex) { logger.LogCritical($"An Error '{ex.Message}' Occured When Getting raw transaction For '{rawHex}'!", ex); throw; } }
public async Task <bool> IsPayeeSignatureValid(RawTransactionResponse rawTransaction, string pricelockId, string signature) { foreach (var tx in rawTransaction.VIn) { var inputTransaction = await network.GetRawTransaction(tx.TxId, true); foreach (var transactionOutputs in inputTransaction.VOut) { if (transactionOutputs != null && transactionOutputs.ScriptPubKey != null && transactionOutputs.ScriptPubKey.Addresses != null) { foreach (string address in transactionOutputs.ScriptPubKey.Addresses) { bool foundValidAddress = await network.VerifySenderPriceLockSignature(address, pricelockId, signature); if (foundValidAddress) { return(true); } } } } } return(false); }
public List <TransactionDetail> Get(RawTransactionResponse model) { List <TransactionDetail> list = new List <TransactionDetail>(); TransactionDetail td = new TransactionDetail(); List <string> addresses = new List <string>(); bool isExchange = false; foreach (var item in model.Vout) { td.BlockTime = BlockChainHelper.UnixTimeStampToDateTime(model.Time); td.TxId = model.TxId; td.Confirmations = model.Confirmations + " Confirmations"; if (item.Assets != null) { if (item.Assets.Count == 1) { isExchange = true; AssetBalanceResponse asset = item.Assets.First(); // if asset transfer if (asset.Type == "transfer") { td.EventType = "success fa fa-2x fa-arrow-right"; } else // if issue of asset { td.EventType = "fa fa-arrow-right"; td.EventTypeLabel = "Asset Issued"; td.Action = item.Assets.First().Name; } if (item.ScriptPubKey.Addresses.Count > 0) { td.To = item.ScriptPubKey.Addresses.First(); } } else { if (item.ScriptPubKey.Addresses.Count > 0) { if (isExchange) { if (string.IsNullOrEmpty(td.From)) { td.From = item.ScriptPubKey.Addresses.First(); } } else { addresses.Add(item.ScriptPubKey.Addresses.First()); } } // if stream if (item.Items.Count > 0) { td.From = item.Items.First().Publishers.First(); td.Action = item.Items.First().Key; td.To = item.Items.First().StreamRef; if (!string.IsNullOrEmpty(item.Items.First().DataAsAscii)) { if (BlockChainHelper.IsJsonObject(item.Items.First().DataAsAscii)) { StreamData data = JsonConvert.DeserializeObject <StreamData>(item.Items.First().DataAsAscii); if (data != null) { td.To = data.Address; td.HashTo = data.Hash; td.EventType = "fa fa-arrow-right"; } } } ResolveStreamKey(td); } // if permission change if (item.Permissions.Count > 0) { td.From = ExplorerSettings.Connection.RootNodeAddress; td.To = item.ScriptPubKey.Addresses.First(); td.Action = "Permissions Changed"; } } } if (addresses.Count == 1) { td.To = addresses.First(); } else if (addresses.Count > 1) { td.To = addresses.First(); td.From = addresses.Last(); } // is miner if (string.IsNullOrEmpty(td.From) && string.IsNullOrEmpty(td.To)) { td.Confirmations = model.Confirmations + " Confirmations"; Blocks blocks = new Blocks(); td.From = blocks.GetMiner(model.BlockHash) + "<br/>"; td.EventTypeLabel = "Coinbase Miner Transaction"; } if (string.IsNullOrEmpty(td.To)) { td.To = td.From; td.From = ExplorerSettings.Connection.RootNodeAddress; } } if (string.IsNullOrEmpty(td.Action)) { // to be implemented } td.To = ResolveAddress(td.To, td); td.From = ResolveAddress(td.From, td); if (CanAdd(td)) { list.Add(td); } return(list); }