public IEnumerable <String> GetTransactionSenderAddresses(String txId) { List <String> senderAddresses = new List <String>(); String rawTransaction = GetRawTransaction(txId, 0); DecodeRawTransactionResponse decodedRawTransaction = DecodeRawTransaction(rawTransaction); List <Vin> transactionInputs = decodedRawTransaction.Vin; Console.WriteLine("Found {0} inputs", transactionInputs.Count); for (Int32 i = 0; i < transactionInputs.Count; i++) { Console.WriteLine("\nInput {0}: txId = {1}", i + 1, transactionInputs[i].TxId); String rawTransactionHex = GetRawTransaction(transactionInputs[i].TxId, 0); DecodeRawTransactionResponse inputDecodedRawTransaction = DecodeRawTransaction(rawTransactionHex); List <Vout> vouts = inputDecodedRawTransaction.Vout; foreach (String sendersAddress in vouts.Select(vout => vout.ScriptPubKey.Addresses[0])) { Console.Write("Sender's address: {0}...", sendersAddress); if (!senderAddresses.Contains(sendersAddress)) { senderAddresses.Add(sendersAddress); Console.WriteLine("Added"); } else { Console.WriteLine("Already exists"); } } } return(senderAddresses); }
// Note: Be careful when using GetTransactionSenderAddress() as it just gives you an address owned by someone who previously controlled the transaction's outputs // which might not actually be the sender (e.g. for e-wallets) and who may not intend to receive anything there in the first place. public String GetTransactionSenderAddress(String txId) { String rawTransaction = GetRawTransaction(txId, 0); DecodeRawTransactionResponse decodedRawTransaction = DecodeRawTransaction(rawTransaction); List <Vin> transactionInputs = decodedRawTransaction.Vin; String rawTransactionHex = GetRawTransaction(transactionInputs[0].TxId, 0); DecodeRawTransactionResponse inputDecodedRawTransaction = DecodeRawTransaction(rawTransactionHex); List <Vout> vouts = inputDecodedRawTransaction.Vout; return(vouts[0].ScriptPubKey.Addresses[0]); }
public JsonResult GetInformationAboutTransaction(String txId) { DecodeRawTransactionResponse transaction = _bitcoinService.GetPublicTransaction(txId); return(Json(transaction, JsonRequestBehavior.AllowGet)); }