public IRpcMethodResult SetDefaultAccount(string address) { try { var accountComponent = new AccountComponent(); var account = accountComponent.GetAccountById(address); if (account != null) { var component = new UserSettingComponent(); component.SetDefaultAccount(account.Id); } else { throw new CommonException(ErrorCode.Service.Account.ACCOUNT_NOT_FOUND); } return(Ok()); } catch (CommonException ce) { return(Error(ce.ErrorCode, ce.Message, ce)); } catch (Exception ex) { return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex)); } }
public IRpcMethodResult SetAutoAddress(bool isEnable) { try { UserSettingComponent userSettingComponent = new UserSettingComponent(); userSettingComponent.SetEnableAutoAccount(isEnable); return(Ok()); } catch (Exception ex) { return(Error(ex.HResult, 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)); } }
public static void Initialize() { var notify = new NotifyComponent(); BlockchainComponent blockChainComponent = new BlockchainComponent(); AccountComponent accountComponent = new AccountComponent(); BlockchainJob.Current = new BlockchainJob(); BlockDac.Default.GetAccountByLockScript = BlockchainJob.Current.GetAccountByLockScript; //从配置文件中读取 ConfigurationTool tool = new ConfigurationTool(); config = tool.GetAppSettings <NodeConfig>("NodeConfig"); if (config == null) { GlobalParameters.IsPool = false; config = new NodeConfig(); } else { notify.SetCallbackApp(config.WalletNotify); BlockchainJob.Current.P2PJob.LocalIP = config.LocalIP; GlobalParameters.IsPool = config.IsPool; } ConfigCenter.ConfigNode = config; //TODO 待验证删除 //if (config != null) //{ // notify.SetCallbackApp(config.WalletNotify); // BlockchainJob.Current.P2PJob.IPAddress = config.Ip; // GlobalParameters.IsPool = config.IsPool; //} //else //{ // GlobalParameters.IsPool = false; //} if (GlobalActions.TransactionNotifyAction == null) { GlobalActions.TransactionNotifyAction = NewTransactionNotify; } blockChainComponent.Initialize(); var accounts = AccountDac.Default.GetAccountBook(); if (accounts.Count == 0) { var account = accountComponent.GenerateNewAccount(false); accountComponent.SetDefaultAccount(account.Id); } var defaultAccount = AppDac.Default.GetDefaultAccount(); if (string.IsNullOrEmpty(defaultAccount)) { var first = AccountDac.Default.GetAccountBook().FirstOrDefault(); UserSettingComponent component = new UserSettingComponent(); component.SetDefaultAccount(first); } TransactionPool.Instance.Load(); }