/// <summary> /// Adds the transaction. /// </summary> /// <returns>The transaction.</returns> /// <param name="identifier">Identifier.</param> /// <param name="password">Password.</param> /// <param name="transaction">Transaction.</param> public async Task <bool> AddTransaction(SecureString identifier, SecureString password, TransactionDto transaction) { Guard.Argument(identifier, nameof(identifier)).NotNull(); Guard.Argument(password, nameof(password)).NotNull(); Guard.Argument(transaction, nameof(transaction)).NotNull(); bool added = false; using (var insecureIdentifier = identifier.Insecure()) { try { var found = false; var data = await vaultServiceClient.GetDataAsync(identifier, password, $"wallets/{insecureIdentifier.Value}/wallet"); if (data.Data.TryGetValue("transactions", out object txs)) { foreach (JObject item in ((JArray)txs).Children().ToList()) { var hash = item.GetValue("Hash"); found = hash.Value <string>().Equals(transaction.Hash); } if (!found) { ((JArray)txs).Add(JObject.FromObject(transaction)); } } else { data.Data.Add("transactions", new List <TransactionDto> { transaction }); } await vaultServiceClient.SaveDataAsync(identifier, password, $"wallets/{insecureIdentifier.Value}/wallet", data.Data); added = true; } catch (Exception ex) { logger.LogError(ex.Message); } } return(added); }
/// <summary> /// Adds the transaction. /// </summary> /// <returns>The transaction.</returns> /// <param name="identifier">Identifier.</param> /// <param name="password">Password.</param> /// <param name="transaction">Transaction.</param> public async Task AddTransaction(SecureString identifier, SecureString password, TransactionDto transaction) { if (identifier == null) { throw new ArgumentNullException(nameof(identifier)); } if (password == null) { throw new ArgumentNullException(nameof(password)); } if (transaction == null) { throw new ArgumentNullException(nameof(transaction)); } using (var insecureIdentifier = identifier.Insecure()) { var found = false; var data = await vaultService.GetDataAsync(identifier, password, $"wallets/{insecureIdentifier.Value}/wallet"); if (data.Data.TryGetValue("transactions", out object txs)) { foreach (JObject item in ((JArray)txs).Children().ToList()) { var hash = item.GetValue("Hash"); found = hash.Value <string>().Equals(transaction.Hash); } if (!found) { ((JArray)txs).Add(JObject.FromObject(transaction)); } } else { data.Data.Add("transactions", new List <TransactionDto> { transaction }); } await vaultService.SaveDataAsync(identifier, password, $"wallets/{insecureIdentifier.Value}/wallet", data.Data); } }