public IActionResult ListMethods() { try { var listMethods = new List <Models.RpcCommandModel>(); foreach (var descriptor in this.GetActionDescriptors().Values.Where(desc => desc.ActionName == desc.ActionName.ToLower())) { var attr = descriptor.MethodInfo.CustomAttributes.Where(x => x.AttributeType == typeof(ActionDescription)).FirstOrDefault(); var description = attr?.ConstructorArguments.FirstOrDefault().Value as string ?? ""; var parameters = new List <string>(); foreach (var param in descriptor.Parameters.OfType <ControllerParameterDescriptor>()) { if (!param.ParameterInfo.IsRetval) { string value = $"<{param.ParameterInfo.Name.ToLower()}>"; if (param.ParameterInfo.HasDefaultValue) { value = $"[{value}]"; } parameters.Add(value); } } string method = $"{descriptor.ActionName} {string.Join(" ", parameters.ToArray())}"; listMethods.Add(new Models.RpcCommandModel { Command = method.Trim(), Description = description }); } return(this.Json(listMethods)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult BuildTransaction([FromBody] BuildMultisigTransactionRequest request) { Guard.NotNull(request, nameof(request)); if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } try { var recipients = request .Recipients .Select(recipientModel => new Wallet.Recipient { ScriptPubKey = BitcoinAddress.Create(recipientModel.DestinationAddress, this.network).ScriptPubKey, Amount = recipientModel.Amount }) .ToList(); Key[] privateKeys = request .Secrets .Select(secret => new Mnemonic(secret.Mnemonic).DeriveExtKey(secret.Passphrase).PrivateKey) .ToArray(); Transaction transactionResult = this.fedMultiSigManualWithdrawalTransactionBuilder.BuildTransaction(recipients, privateKeys); var model = new WalletBuildTransactionModel { Hex = transactionResult.ToHex(), TransactionId = transactionResult.GetHash() }; return(this.Json(model)); } catch (Exception e) { LoggerExtensions.LogError(this.logger, "Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public async Task <IActionResult> GetRawTransactionAsync([FromQuery] string trxid, bool verbose = false) { try { Guard.NotEmpty(trxid, nameof(trxid)); uint256 txid; if (!uint256.TryParse(trxid, out txid)) { throw new ArgumentException(nameof(trxid)); } // First tries to find a pooledTransaction. If can't, will retrieve it from the blockstore if it exists. Transaction trx = this.pooledTransaction != null ? await this.pooledTransaction.GetTransaction(txid).ConfigureAwait(false) : null; if (trx == null) { trx = this.blockStore?.GetTransactionById(txid); } if (trx == null) { return(this.Json(null)); } if (verbose) { ChainedHeader block = this.GetTransactionBlock(txid, this.fullNode, this.chainIndexer); return(this.Json(new TransactionVerboseModel(trx, this.network, block, this.chainState?.ConsensusTip))); } else { return(this.Json(new TransactionBriefModel(trx))); } } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult Recover([FromBody] WalletRecoveryRequest request) { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { // get the wallet folder DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath); Wallet wallet = this.walletManager.RecoverWallet(request.Password, walletFolder.FullName, request.Name, request.Network, request.Mnemonic, null, request.CreationDate); // start syncing the wallet from the creation date this.tracker.SyncFrom(request.CreationDate); return(this.Json(new WalletModel { Network = wallet.Network.Name, // Addresses = wallet.GetFirstNAddresses(10).Select(a => a.ToWif()), FileName = wallet.WalletFilePath })); } catch (InvalidOperationException e) { // indicates that this wallet already exists return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, "This wallet already exists.", e.ToString())); } catch (FileNotFoundException e) { // indicates that this wallet does not exist return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, "Wallet not found.", e.ToString())); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
private IActionResult VoteAddKickFedMember(CollateralFederationMemberModel request, bool addMember) { Guard.NotNull(request, nameof(request)); if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } if (!this.fedManager.IsFederationMember) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Only federation members can vote", string.Empty)); } try { var key = new PubKey(request.PubKeyHex); if (this.fedManager.IsMultisigMember(key)) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Multisig members can't be voted on", string.Empty)); } IFederationMember federationMember = new CollateralFederationMember(key, false, new Money(request.CollateralAmountSatoshis), request.CollateralMainchainAddress); byte[] fedMemberBytes = (this.network.Consensus.ConsensusFactory as PoAConsensusFactory).SerializeFederationMember(federationMember); this.votingManager.ScheduleVote(new VotingData() { Key = addMember ? VoteKey.AddFederationMember : VoteKey.KickFederationMember, Data = fedMemberBytes }); return(this.Ok()); } catch (Exception e) { this.logger.Error("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "There was a problem executing a command.", e.ToString())); } }
public async Task <IActionResult> GetTransactionsAsync() { if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } var pageSize = 10; // Should we allow page size to be set in query? //this.logger.LogTrace("(Hash:'{1}')", hash); try { ChainedHeader chainHeader = this.chain.Tip; var transactions = new List <TransactionVerboseModel>(); while (chainHeader != null && transactions.Count < pageSize) { Block block = await this.blockStoreCache.GetBlockAsync(chainHeader.HashBlock).ConfigureAwait(false); var blockModel = new PosBlockModel(block, this.chain); foreach (Transaction trx in block.Transactions) { // Since we got Chainheader and Tip available, we'll supply those in this query. That means this query will // return more metadata than specific query using transaction ID. transactions.Add(new TransactionVerboseModel(trx, this.network, chainHeader, this.chainState.BlockStoreTip)); } chainHeader = chainHeader.Previous; } return(Json(transactions)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult BuildTransaction([FromBody] BuildTransactionRequest request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } var destination = BitcoinAddress.Create(request.DestinationAddress, this.network).ScriptPubKey; try { var context = new TransactionBuildContext( new WalletAccountReference(request.WalletName, request.AccountName), new[] { new Recipient { Amount = request.Amount, ScriptPubKey = destination } }.ToList(), request.Password) { FeeType = FeeParser.Parse(request.FeeType), MinConfirmations = request.AllowUnconfirmed ? 0 : 1 }; var transactionResult = this.walletTransactionHandler.BuildTransaction(context); var model = new WalletBuildTransactionModel { Hex = transactionResult.ToHex(), Fee = context.TransactionFee, TransactionId = transactionResult.GetHash() }; return(this.Json(model)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult Recover([FromBody] WalletRecoveryRequest request) { Guard.NotNull(request, nameof(request)); this.logger.LogTrace("({0}.{1}:'{2}')", nameof(request), nameof(request.Name), request.Name); // checks the request is valid if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } try { Wallet wallet = this.walletManager.RecoverWallet(request.Password, request.Name, request.Mnemonic, request.CreationDate, passphrase: request.Passphrase); this.SyncFromBestHeightForRecoveredWallets(request.CreationDate); return(this.Ok()); } catch (WalletException e) { // indicates that this wallet already exists this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, e.Message, e.ToString())); } catch (FileNotFoundException e) { // indicates that this wallet does not exist this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, "Wallet not found.", e.ToString())); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } finally { this.logger.LogTrace("(-)"); } }
public IActionResult GetAddressesBalances(string addresses, int minConfirmations) { try { string[] addressesArray = addresses.Split(','); var balances = new Dictionary <string, Money>(addresses.Length); foreach (string address in addressesArray) { balances[address] = this.addressIndexer.GetAddressBalance(address, minConfirmations); } return(this.Json(balances)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetMaturedBlockDeposits([FromBody] MaturedBlockRequestModel blockRequest) { Guard.NotNull(blockRequest, nameof(blockRequest)); if (!this.ModelState.IsValid) { IEnumerable <string> errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { SerializableResult <List <MaturedBlockDepositsModel> > depositsResult = this.maturedBlocksProvider.GetMaturedDeposits(blockRequest.BlockHeight, blockRequest.MaxBlocksToSend); return(this.Json(depositsResult)); } catch (Exception e) { this.logger.LogDebug("Exception thrown calling /api/FederationGateway/{0}: {1}.", FederationGatewayRouteEndPoint.GetMaturedBlockDeposits, e.Message); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, $"Could not re-sync matured block deposits: {e.Message}", e.ToString())); } }
public async Task <IActionResult> ConfirmTransactionAsync(DestinationChain destinationChain, int transactionId, int gasPrice) { try { if (!this.ethCompatibleClientProvider.IsChainSupportedAndEnabled(destinationChain)) { return(this.Json($"{destinationChain} not enabled or supported!")); } IETHClient client = this.ethCompatibleClientProvider.GetClientForChain(destinationChain); // TODO: Maybe for convenience the gas price could come from the external API poller return(this.Json(await client.ConfirmTransactionAsync(transactionId, gasPrice).ConfigureAwait(false))); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult RemoveAddress([FromQuery]string label) { Guard.NotEmpty(label, nameof(label)); try { AddressBookEntry removedEntry = this.addressBookManager.RemoveAddress(label); if (removedEntry == null) { return ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, $"No item with label '{label}' was found in the address book.", string.Empty); } return this.Json(new AddressBookEntryModel { Label = removedEntry.Label, Address = removedEntry.Address }); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "There was a problem removing an address from the address book.", e.ToString()); } }
public IActionResult DeploymentFlags() { try { var ruleEngine = this.ConsensusManager.ConsensusRules as ConsensusRuleEngine; // Ensure threshold conditions cached. var thresholdStates = ruleEngine.NodeDeployments.BIP9.GetStates(this.ChainState.ConsensusTip.Previous); var metrics = ruleEngine.NodeDeployments.BIP9.GetThresholdStateMetrics(this.ChainState.ConsensusTip.Previous, thresholdStates); return(Json(metrics)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetRegistrations() { try { List <IServiceNode> serviceNodes = this.serviceNodeManager.GetServiceNodes(); IEnumerable <RegistrationModel> models = serviceNodes.Select(m => new RegistrationModel { ServerId = m.RegistrationRecord.Token.ServerId, BlockReceived = m.RegistrationRecord.BlockReceived, RecordTimestamp = m.RegistrationRecord.RecordTimestamp, RecordTxHex = m.RegistrationRecord.RecordTxHex, RecordTxId = m.RegistrationRecord.RecordTxId }); return(this.Json(models)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult Rescan([FromQuery] DateTimeOffset fromTime) { try { RescanState rescanState = this.watchOnlyWalletManager.Rescan(fromTime); RescanStateModel model = new RescanStateModel() { IsInProgress = rescanState.IsInProgress, FromTime = rescanState.FromTime, UntilTime = rescanState.UntilTime, ProgressPercentage = rescanState.ProgressPercentage }; return(this.Json(model)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, e.Message, e.ToString())); } }
public IActionResult GetExtPubKey([FromQuery] GetExtPubKeyModel request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { return(BuildErrorResponse(this.ModelState)); } try { string result = this.walletManager.GetExtPubKey(new WalletAccountReference(request.WalletName, request.AccountName)); return(this.Json(result)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult ListAccounts([FromQuery] ListAccountsModel request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { return(BuildErrorResponse(this.ModelState)); } try { IEnumerable <HdAccount> result = this.walletManager.GetAccounts(request.WalletName); return(this.Json(result.Select(a => a.Name))); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult CreateNewAccount([FromBody] GetUnusedAccountModel request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { return(BuildErrorResponse(this.ModelState)); } try { var result = this.walletManager.GetUnusedAccount(request.WalletName, request.Password); return(this.Json(result.Name)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public async Task <IActionResult> GetTumblingStateAsync() { try { var parameterDictionary = new Dictionary <string, string>() { ["tumbler"] = this.tumbleBitManager.TumblerAddress, ["state"] = this.tumbleBitManager.State.ToString(), ["originWallet"] = this.tumbleBitManager.tumblingState.OriginWalletName, ["destinationWallet"] = this.tumbleBitManager.tumblingState.DestinationWalletName, ["registrations"] = this.tumbleBitManager.RegistrationCount().ToString(), ["minRegistrations"] = "1" }; return(this.Json(parameterDictionary)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "An error occured during tumbling-state request.", e.ToString())); } }
public IActionResult GetUnusedAddress([FromQuery] GetUnusedAddressModel request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { var result = this.walletManager.GetUnusedAddress(new WalletAccountReference(request.WalletName, request.AccountName)); return(this.Json(result.Address)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult ImportMemberKey([FromBody] ImportMemberKeyRequest request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { return(BuildErrorResponse(this.ModelState)); } try { this.walletManager.ImportMemberKey(request.Password, request.Mnemonic, request.Passphrase); return(this.Ok()); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetFederationAtHeight([FromQuery(Name = "blockHeight")] int blockHeight) { try { ChainedHeader chainedHeader = this.chainIndexer.GetHeader(blockHeight); List <IFederationMember> federationMembers = this.federationHistory.GetFederationForBlock(chainedHeader); List <PubKey> federationPubKeys = new List <PubKey>(); foreach (IFederationMember federationMember in federationMembers) { federationPubKeys.Add(federationMember.PubKey); } return(Json(federationPubKeys)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult Deserialize([FromBody] DeserializeTransactionRequest request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } try { Transaction transaction = this.network.CreateTransaction(request.Hex); return(Content(transaction.ToString(this.network))); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetStakingInfo() { try { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } GetStakingInfoModel model = this.posMinting != null?this.posMinting.GetGetStakingInfoModel() : new GetStakingInfoModel(); return(this.Json(model)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetHistoryFilter([FromQuery] WalletHistoryFilterRequest request) { Guard.NotNull(request, nameof(request)); if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } try { WalletHistoryFilterModel model = HistoryModelBuilder.GetHistoryFilter(this.chain, this.walletManager, this.blockRepository, this.txMempool, this.network, request); return(this.Json(model)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetBalance([FromQuery] WalletBalanceRequest request) { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { WalletBalanceModel model = new WalletBalanceModel { AccountsBalances = new List <AccountBalance>() }; var accounts = this.walletManager.GetAccountsByCoinType(request.WalletName, this.coinType).ToList(); foreach (var account in accounts) { var allTransactions = account.ExternalAddresses.SelectMany(a => a.Transactions) .Concat(account.InternalAddresses.SelectMany(i => i.Transactions)).ToList(); AccountBalance balance = new AccountBalance { CoinType = this.coinType, Name = account.Name, HdPath = account.HdPath, AmountConfirmed = allTransactions.Sum(t => t.SpendableAmount(true)), AmountUnconfirmed = allTransactions.Sum(t => t.SpendableAmount(false)), }; model.AccountsBalances.Add(balance); } return(this.Json(model)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetBalance([FromQuery] WalletBalanceRequest request) { Guard.NotNull(request, nameof(request)); // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { WalletBalanceModel model = new WalletBalanceModel(); var accounts = this.walletManager.GetAccounts(request.WalletName).ToList(); foreach (var account in accounts) { var result = account.GetSpendableAmount(); AccountBalance balance = new AccountBalance { CoinType = this.coinType, Name = account.Name, HdPath = account.HdPath, AmountConfirmed = result.ConfirmedAmount, AmountUnconfirmed = result.UnConfirmedAmount, }; model.AccountsBalances.Add(balance); } return(this.Json(model)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult ValidateAddress([FromQuery] string address) { try { Guard.NotEmpty(address, nameof(address)); var res = new ValidatedAddress(); res.IsValid = false; // P2WPKH if (BitcoinWitPubKeyAddress.IsValid(address, this.network, out Exception _)) { res.IsValid = true; } // P2WSH else if (BitcoinWitScriptAddress.IsValid(address, this.network, out Exception _)) { res.IsValid = true; } // P2PKH else if (BitcoinPubKeyAddress.IsValid(address, this.network)) { res.IsValid = true; } // P2SH else if (BitcoinScriptAddress.IsValid(address, this.network)) { res.IsValid = true; } return(this.Json(res)); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public async Task <IActionResult> GetTxOutAsync([FromQuery] string trxid, uint vout = 0, bool includeMemPool = true) { try { Guard.NotEmpty(trxid, nameof(trxid)); uint256 txid; if (!uint256.TryParse(trxid, out txid)) { throw new ArgumentException(nameof(trxid)); } UnspentOutputs unspentOutputs = null; if (includeMemPool) { unspentOutputs = this.pooledGetUnspentTransaction != null ? await this.pooledGetUnspentTransaction.GetUnspentTransactionAsync(txid).ConfigureAwait(false) : null; } else { unspentOutputs = this.getUnspentTransaction != null ? await this.getUnspentTransaction.GetUnspentTransactionAsync(txid).ConfigureAwait(false) : null; } if (unspentOutputs == null) { return(Json(null)); } return(Json(new GetTxOutModel(unspentOutputs, vout, this.network, this.chainIndexer.Tip))); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }
public IActionResult GetHistory([FromQuery] WalletHistoryRequest request) { // checks the request is valid if (!this.ModelState.IsValid) { var errors = this.ModelState.Values.SelectMany(e => e.Errors.Select(m => m.ErrorMessage)); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Formatting error", string.Join(Environment.NewLine, errors))); } try { WalletHistoryModel model = new WalletHistoryModel { Transactions = new List <TransactionItem>() }; // get transactions contained in the wallet var addresses = this.walletManager.GetHistoryByCoinType(request.WalletName, request.CoinType); foreach (var address in addresses) { foreach (var transaction in address.Transactions) { model.Transactions.Add(new TransactionItem { Amount = transaction.Amount, Confirmed = transaction.Confirmed, Timestamp = transaction.CreationTime, TransactionId = transaction.Id, Address = address.Address }); } } model.Transactions = model.Transactions.OrderByDescending(t => t.Timestamp).ToList(); return(this.Json(model)); } catch (Exception e) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString())); } }