public IActionResult GetWatchOnlyWallet() { try { // Map a watch-only wallet to a model object for display in the front end. var watchOnlyWallet = this.watchOnlyWalletManager.GetWatchOnlyWallet(); WatchOnlyWalletModel model = new WatchOnlyWalletModel { CoinType = watchOnlyWallet.CoinType, Network = watchOnlyWallet.Network, CreationTime = watchOnlyWallet.CreationTime }; foreach (var watchAddress in watchOnlyWallet.WatchedAddresses) { WatchedAddressModel watchedAddressModel = new WatchedAddressModel { Address = watchAddress.Value.Address, Transactions = new List <TransactionModel>() }; foreach (var transactionData in watchAddress.Value.Transactions) { Transaction transaction = watchOnlyWallet.Network.CreateTransaction(transactionData.Value.Hex); watchedAddressModel.Transactions.Add(new TransactionBriefModel(transaction, watchOnlyWallet.Network)); } model.WatchedAddresses.Add(watchedAddressModel); } foreach (var transactionData in watchOnlyWallet.WatchedTransactions) { Transaction transaction = watchOnlyWallet.Network.CreateTransaction(transactionData.Value.Hex); WatchedTransactionModel watchedTransactionModel = new WatchedTransactionModel { Transaction = new TransactionBriefModel(transaction, watchOnlyWallet.Network) }; model.WatchedTransactions.Add(watchedTransactionModel); } return(this.Json(model)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult ListTransactions([FromQuery] string address) { // Checks the request is valid. if (string.IsNullOrEmpty(address)) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", "Address to watch is missing.")); } try { var watchOnlyWallet = this.watchOnlyWalletManager.GetWatchOnlyWallet(); if (!watchOnlyWallet.WatchedAddresses.Any(adr => adr.Value.Address == address)) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Data error", "Address is not in he watchlist. Please add it first with the 'watch' API and use the 'rescan' API if necessary.")); } var watchedAddress = watchOnlyWallet.WatchedAddresses.First(adr => adr.Value.Address == address).Value; WatchedAddressModel watchedAddressModel = new WatchedAddressModel { Address = watchedAddress.Address, Transactions = new List <TransactionModel>() }; foreach (KeyValuePair <string, TransactionData> transactionData in watchOnlyWallet.WatchedTransactions) { Transaction transaction = watchOnlyWallet.Network.CreateTransaction(transactionData.Value.Hex); watchedAddressModel.Transactions.Add(new TransactionVerboseModel(transaction, watchOnlyWallet.Network)); } return(this.Json(watchedAddressModel)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, e.Message, e.ToString())); } }