public IRpcMethodResult GetAddressesByTag(string tag) { try { var accountComponent = new AccountComponent(); var accounts = accountComponent.GetAccountsByTag(tag); var result = new List <AccountOM>(); foreach (var account in accounts) { var item = new AccountOM(); item.Address = account.Id; item.PublicKey = account.PublicKey; item.Balance = account.Balance; item.IsDefault = account.IsDefault; item.WatchOnly = account.WatchedOnly; item.Tag = account.Tag; result.Add(item); } return(Ok(result.ToArray())); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult GetAccountByAddress(string address) { try { var utxoComponent = new UtxoComponent(); var account = new AccountComponent().GetAccountById(address); if (account != null) { var result = new AccountOM(); result.Address = account.Id; result.PublicKey = account.PublicKey; result.Balance = utxoComponent.GetConfirmedBlanace(account.Id); result.IsDefault = account.IsDefault; result.WatchOnly = account.WatchedOnly; result.Tag = account.Tag; return(Ok(result)); } else { throw new CommonException(ErrorCode.Service.Account.ACCOUNT_NOT_FOUND); } } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult GetNewAddress(string tag) { try { var accountComponent = new AccountComponent(); Account account = null; var setting = new SettingComponent().GetSetting(); AccountOM result = null; if (setting.Encrypt) { if (!string.IsNullOrWhiteSpace(_cache.Get <string>("WalletPassphrase"))) { account = accountComponent.GenerateNewAccount(); account.IsDefault = true; account.PrivateKey = AES128.Encrypt(account.PrivateKey, _cache.Get <string>("WalletPassphrase")); accountComponent.UpdatePrivateKeyAr(account); } else { throw new CommonException(ErrorCode.Service.Wallet.WALLET_HAS_BEEN_LOCKED); } } else { account = accountComponent.GenerateNewAccount(); account.IsDefault = true; } if (account != null) { account.Tag = tag; accountComponent.UpdateTag(account.Id, tag); result = new AccountOM(); result.Address = account.Id; result.PublicKey = account.PublicKey; result.Balance = account.Balance; result.IsDefault = account.IsDefault; result.WatchOnly = account.WatchedOnly; result.Tag = account.Tag; } return(Ok(result)); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult GetDefaultAccount() { try { var component = new UserSettingComponent(); var id = component.GetDefaultAccount(); var accountComponent = new AccountComponent(); Account account = null; if (string.IsNullOrEmpty(id)) { account = accountComponent.GetAccountById(id); } else { account = accountComponent.GetDefaultAccount(); } if (account != null) { var result = new AccountOM(); result.Address = account.Id; result.PublicKey = account.PublicKey; result.Balance = account.Balance; result.IsDefault = account.IsDefault; result.WatchOnly = account.WatchedOnly; result.Tag = account.Tag; return(Ok(result)); } else { throw new CommonException(ErrorCode.Service.Account.ACCOUNT_NOT_FOUND); } } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }