public Account ImportPublicKeyAndAddress(string filePath, string salt) { Account result = null; string extensionName = Path.GetExtension(filePath).ToLower(); if (extensionName != encryptExtensionName && extensionName != noEncryptExtensionName) { throw new CommonException(ErrorCode.Engine.Wallet.IO.EXTENSION_NAME_NOT_SUPPORT); } WatchAccountBackup backup = null; try { if (extensionName == noEncryptExtensionName) { backup = LoadFile <WatchAccountBackup>(filePath, null); } else { backup = LoadFile <WatchAccountBackup>(filePath, salt); } if (backup != null) { AccountDac dac = AccountDac.Default; dac.Insert(new Account { Balance = 0, Id = backup.Address, IsDefault = false, PrivateKey = null, PublicKey = backup.PublicKey, Tag = "", Timestamp = Time.EpochTime, WatchedOnly = true }); result = dac.SelectById(backup.Address); } } catch (Exception ex) { throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex); } return(result); }
public void ExportPublicKeyAndAddress(string address, string filePath, string salt) { string extensionName = Path.GetExtension(filePath).ToLower(); if (string.IsNullOrWhiteSpace(salt)) { filePath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + noEncryptExtensionName); } else { filePath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + encryptExtensionName); } try { Account account = AccountDac.Default.SelectById(address); WatchAccountBackup backup = new WatchAccountBackup() { Address = account.Id, PublicKey = account.PublicKey }; if (backup != null) { if (extensionName == noEncryptExtensionName) { SaveFile(backup, filePath, null); } else { SaveFile(backup, filePath, salt); } } } catch (Exception ex) { throw new CommonException(ErrorCode.Engine.Wallet.DATA_SAVE_TO_FILE_ERROR, ex); } }