Ejemplo n.º 1
0
        public IRpcMethodResult EncryptWallet(string passphrase)
        {
            try
            {
                var result   = false;
                var settting = new SettingComponent().GetSetting();

                if (settting.Encrypt)
                {
                    LogHelper.Error("Error occured in EncrypWallet API");
                    throw new CommonException(ErrorCode.Service.Wallet.CAN_NOT_ENCRYPT_AN_ENCRYPTED_WALLET);
                }

                result = new WalletComponent().EncryptWallet(passphrase);
                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
Ejemplo n.º 2
0
        public IRpcMethodResult WalletPassphraseChange(string currentPassphrase, string newPassphrase)
        {
            try
            {
                var settting = new SettingComponent().GetSetting();

                if (!settting.Encrypt)
                {
                    throw new CommonException(ErrorCode.Service.Wallet.CAN_NOT_CHANGE_PASSWORD_IN_AN_UNENCRYPTED_WALLET);
                }

                WalletComponent wc = new WalletComponent();
                wc.ChangePassword(currentPassphrase, newPassphrase);
                _cache.Remove("WalletPassphrase");
                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
Ejemplo n.º 3
0
        public IRpcMethodResult BackupWallet(string targetAddress)
        {
            try
            {
                WalletComponent  component        = new WalletComponent();
                SettingComponent settingComponent = new SettingComponent();
                Setting          setting          = settingComponent.GetSetting();

                if (setting.Encrypt)
                {
                    if (string.IsNullOrEmpty(_cache.Get <string>("WalletPassphrase")))
                    {
                        throw new CommonException(ErrorCode.Service.Wallet.WALLET_HAS_BEEN_LOCKED);
                    }
                    component.BackupWallet(targetAddress, _cache.Get <string>("WalletPassphrase"));
                }
                else
                {
                    component.BackupWallet(targetAddress, null);
                }
                return(Ok());
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
Ejemplo n.º 4
0
 public IRpcMethodResult BackupWallet(string targetAddress)
 {
     try
     {
         WalletComponent component = new WalletComponent();
         component.BackupWallet(targetAddress, _cache.Get <string>("WalletPassphrase"));
         return(Ok());
     }
     catch (CommonException ce)
     {
         return(Error(ce.ErrorCode, ce.Message, ce));
     }
     catch (Exception ex)
     {
         return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
     }
 }
Ejemplo n.º 5
0
 public IRpcMethodResult RestoreWalletBackup(string backupFilePaths, string passphrase = null)
 {
     try
     {
         var             result    = false;
         WalletComponent component = new WalletComponent();
         result = component.RestoreWalletBackup(backupFilePaths, passphrase);
         return(Ok(result));
     }
     catch (CommonException ce)
     {
         return(Error(ce.ErrorCode, ce.Message, ce));
     }
     catch (Exception ex)
     {
         return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
     }
 }