fun saveWalletAndWalletInfoSimple( perWalletModelData: WalletData, walletFilename: String?, walletInfoFilename: String? ) { val walletFile = File(walletFilename) val walletInfo: WalletInfoData = perWalletModelData.getWalletInfo() var fileOutputStream: FileOutputStream? = null try { if (perWalletModelData.getWallet() != null) { if (walletInfo != null) { val walletDescriptionInInfoFile: String = walletInfo.getProperty(WalletInfoData.DESCRIPTION_PROPERTY) if (walletDescriptionInInfoFile != null) { perWalletModelData.getWallet().setDescription(walletDescriptionInInfoFile) } } log.debug( "Saving wallet file '" + walletFile.getAbsolutePath().toString() + "' ..." ) if (MultiBitWalletVersion.SERIALIZED === walletInfo.getWalletVersion()) { throw WalletSaveException( "Cannot save wallet '" + walletFile.getAbsolutePath() .toString() + "'. Serialized wallets are no longer supported." ) } else { var walletIsActuallyEncrypted = false val wallet: Wallet = perWalletModelData.getWallet() for (key in wallet.getKeychain()) { if (key.isEncrypted()) { walletIsActuallyEncrypted = true break } } if (walletIsActuallyEncrypted) { walletInfo.setWalletVersion(MultiBitWalletVersion.PROTOBUF_ENCRYPTED) } if (MultiBitWalletVersion.PROTOBUF === walletInfo.getWalletVersion()) { perWalletModelData.getWallet().saveToFile(walletFile) } else if (MultiBitWalletVersion.PROTOBUF_ENCRYPTED === walletInfo.getWalletVersion()) { fileOutputStream = FileOutputStream(walletFile) walletProtobufSerializer.writeWallet( perWalletModelData.getWallet(), fileOutputStream ) } else { throw WalletVersionException( "Cannot save wallet '" + perWalletModelData.getWalletFilename() .toString() + "'. Its wallet version is '" + walletInfo.getWalletVersion() .toString() .toString() + "' but this version of MultiBit does not understand that format." ) } } log.debug("... done saving wallet file.") } } catch (ioe: IOException) { throw WalletSaveException( "Cannot save wallet '" + perWalletModelData.getWalletFilename(), ioe ) } finally { if (fileOutputStream != null) { try { fileOutputStream.flush() fileOutputStream.close() } catch (e: IOException) { throw WalletSaveException( "Cannot save wallet '" + perWalletModelData.getWalletFilename(), e ) } } } walletInfo.writeToFile(walletInfoFilename, walletInfo.getWalletVersion()) }
Simply save the wallet and wallet info files . Used for backup writes .