@ -4,6 +4,7 @@ import com.google.common.base.Charsets;
import com.google.common.eventbus.Subscribe ;
import com.google.common.eventbus.Subscribe ;
import com.google.common.io.ByteSource ;
import com.google.common.io.ByteSource ;
import com.sparrowwallet.drongo.BitcoinUnit ;
import com.sparrowwallet.drongo.BitcoinUnit ;
import com.sparrowwallet.drongo.Network ;
import com.sparrowwallet.drongo.SecureString ;
import com.sparrowwallet.drongo.SecureString ;
import com.sparrowwallet.drongo.Utils ;
import com.sparrowwallet.drongo.Utils ;
import com.sparrowwallet.drongo.crypto.InvalidPasswordException ;
import com.sparrowwallet.drongo.crypto.InvalidPasswordException ;
@ -770,6 +771,7 @@ public class AppController implements Initializable {
FileType fileType = IOUtils . getFileType ( file ) ;
FileType fileType = IOUtils . getFileType ( file ) ;
if ( FileType . JSON . equals ( fileType ) ) {
if ( FileType . JSON . equals ( fileType ) ) {
Wallet wallet = storage . loadWallet ( ) ;
Wallet wallet = storage . loadWallet ( ) ;
checkWalletNetwork ( wallet ) ;
restorePublicKeysFromSeed ( wallet , null ) ;
restorePublicKeysFromSeed ( wallet , null ) ;
Tab tab = addWalletTab ( storage , wallet ) ;
Tab tab = addWalletTab ( storage , wallet ) ;
tabs . getSelectionModel ( ) . select ( tab ) ;
tabs . getSelectionModel ( ) . select ( tab ) ;
@ -786,10 +788,11 @@ public class AppController implements Initializable {
EventManager . get ( ) . post ( new StorageEvent ( storage . getWalletFile ( ) , TimedEvent . Action . END , "Done" ) ) ;
EventManager . get ( ) . post ( new StorageEvent ( storage . getWalletFile ( ) , TimedEvent . Action . END , "Done" ) ) ;
Storage . WalletAndKey walletAndKey = loadWalletService . getValue ( ) ;
Storage . WalletAndKey walletAndKey = loadWalletService . getValue ( ) ;
try {
try {
checkWalletNetwork ( walletAndKey . wallet ) ;
restorePublicKeysFromSeed ( walletAndKey . wallet , walletAndKey . key ) ;
restorePublicKeysFromSeed ( walletAndKey . wallet , walletAndKey . key ) ;
Tab tab = addWalletTab ( storage , walletAndKey . wallet ) ;
Tab tab = addWalletTab ( storage , walletAndKey . wallet ) ;
tabs . getSelectionModel ( ) . select ( tab ) ;
tabs . getSelectionModel ( ) . select ( tab ) ;
} catch ( Mnemonic Exception e ) {
} catch ( Exception e ) {
showErrorDialog ( "Error Opening Wallet" , e . getMessage ( ) ) ;
showErrorDialog ( "Error Opening Wallet" , e . getMessage ( ) ) ;
} finally {
} finally {
walletAndKey . key . clear ( ) ;
walletAndKey . key . clear ( ) ;
@ -816,6 +819,12 @@ public class AppController implements Initializable {
}
}
}
}
private void checkWalletNetwork ( Wallet wallet ) {
if ( wallet . getNetwork ( ) ! = null & & wallet . getNetwork ( ) ! = Network . get ( ) ) {
throw new IllegalStateException ( "Provided " + wallet . getNetwork ( ) + " wallet is invalid on a " + Network . get ( ) + " network. Use a " + wallet . getNetwork ( ) + " configuration to load this wallet." ) ;
}
}
private void restorePublicKeysFromSeed ( Wallet wallet , Key key ) throws MnemonicException {
private void restorePublicKeysFromSeed ( Wallet wallet , Key key ) throws MnemonicException {
if ( wallet . containsSeeds ( ) ) {
if ( wallet . containsSeeds ( ) ) {
//Derive xpub and master fingerprint from seed, potentially with passphrase
//Derive xpub and master fingerprint from seed, potentially with passphrase
@ -1382,7 +1391,7 @@ public class AppController implements Initializable {
@Subscribe
@Subscribe
public void openWallets ( OpenWalletsEvent event ) {
public void openWallets ( OpenWalletsEvent event ) {
List < File > walletFiles = event . getWalletsMap ( ) . values ( ) . stream ( ) . map ( storage - > storage . getWalletFile ( ) ) . collect ( Collectors . toList ( ) ) ;
List < File > walletFiles = event . getWalletsMap ( ) . values ( ) . stream ( ) . map ( Storage : : getWalletFile ) . collect ( Collectors . toList ( ) ) ;
Config . get ( ) . setRecentWalletFiles ( walletFiles ) ;
Config . get ( ) . setRecentWalletFiles ( walletFiles ) ;
boolean usbWallet = false ;
boolean usbWallet = false ;