Esempio n. 1
0
        public bool RestoreWalletBackup(string filePath, string salt)
        {
            bool result = false;

            string extensionName = Path.GetExtension(filePath).ToLower();

            if (extensionName != encryptExtensionName && extensionName != noEncryptExtensionName)
            {
                throw new CommonException(ErrorCode.Engine.Wallet.IO.EXTENSION_NAME_NOT_SUPPORT);
            }

            //Load backup file data.
            WalletBackup backup = null;

            if (extensionName == noEncryptExtensionName)
            {
                backup = LoadFile <WalletBackup>(filePath);
            }
            else
            {
                backup = LoadFile <WalletBackup>(filePath, salt);
            }


            //Create SQL Query Script and run
            try
            {
                if (backup != null)
                {
                    WalletBackupDac dac   = new WalletBackupDac();
                    int             count = -1;
                    count = dac.Restore(backup);
                    if (count > -1)
                    {
                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex);
            }

            return(result);
        }
Esempio n. 2
0
        public bool RestoreWalletBackup(string filePath, string salt)
        {
            bool result = false;

            string extensionName = Path.GetExtension(filePath).ToLower();

            var setting = new SettingComponent().GetSetting();

            if (setting.Encrypt && string.IsNullOrEmpty(salt))
            {
                throw new CommonException(ErrorCode.Engine.Wallet.CHECK_PASSWORD_ERROR);
            }

            if (setting.Encrypt && (extensionName != encryptExtensionName))
            {
                throw new CommonException(ErrorCode.Engine.Wallet.IO.EXTENSION_NAME_NOT_SUPPORT);
            }
            else if (!setting.Encrypt && extensionName != noEncryptExtensionName)
            {
                throw new CommonException(ErrorCode.Engine.Wallet.IO.EXTENSION_NAME_NOT_SUPPORT);
            }

            //Load backup file data.
            WalletBackup backup = null;

            if (extensionName == noEncryptExtensionName)
            {
                try
                {
                    backup = LoadFile <WalletBackup>(filePath);
                }
                catch
                {
                    var backup1 = LoadFile <WalletBackup1>(filePath);
                    backup = backup1.ToBackup();
                }
            }
            else
            {
                try
                {
                    backup = LoadFile <WalletBackup>(filePath, salt);
                }
                catch
                {
                    var backup1 = LoadFile <WalletBackup1>(filePath, salt);
                    backup = backup1.ToBackup();
                }
                backup.AccountList.RemoveAll(x => string.IsNullOrEmpty(x.PrivateKey));
            }


            //Create SQL Query Script and run
            try
            {
                if (backup != null)
                {
                    WalletBackupDac dac = WalletBackupDac.Default;
                    dac.Restore(backup);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex);
            }
            return(result);
        }