mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 14:52:16 +00:00
Wallet.loadFromFile takes WalletExtensions
This commit is contained in:
parent
96a82800fd
commit
a2ac847ee9
@ -1340,14 +1340,18 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a wallet deserialized from the given file.
|
||||
* <p>Returns a wallet deserialized from the given file. Extensions previously saved with the wallet can be
|
||||
* deserialized by calling @{@link WalletExtension#deserializeWalletExtension(Wallet, byte[])}}</p>
|
||||
*
|
||||
* @param file the wallet file to read
|
||||
* @param walletExtensions extensions possibly added to the wallet.
|
||||
*/
|
||||
public static Wallet loadFromFile(File f) throws UnreadableWalletException {
|
||||
public static Wallet loadFromFile(File file, @Nullable WalletExtension... walletExtensions) throws UnreadableWalletException {
|
||||
try {
|
||||
FileInputStream stream = null;
|
||||
try {
|
||||
stream = new FileInputStream(f);
|
||||
return loadFromFileStream(stream);
|
||||
stream = new FileInputStream(file);
|
||||
return loadFromFileStream(stream, walletExtensions);
|
||||
} finally {
|
||||
if (stream != null) stream.close();
|
||||
}
|
||||
@ -1407,11 +1411,9 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a wallet deserialized from the given input stream.
|
||||
*/
|
||||
public static Wallet loadFromFileStream(InputStream stream) throws UnreadableWalletException {
|
||||
Wallet wallet = new WalletProtobufSerializer().readWallet(stream);
|
||||
/** Returns a wallet deserialized from the given input stream and wallet extensions. */
|
||||
public static Wallet loadFromFileStream(InputStream stream, @Nullable WalletExtension... walletExtensions) throws UnreadableWalletException {
|
||||
Wallet wallet = new WalletProtobufSerializer().readWallet(stream, walletExtensions);
|
||||
if (!wallet.isConsistent()) {
|
||||
log.error("Loaded an inconsistent wallet");
|
||||
}
|
||||
|
@ -367,9 +367,9 @@ public class WalletProtobufSerializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Parses a wallet from the given stream, using the provided Wallet instance to load data into. This is primarily
|
||||
* used when you want to register extensions. Data in the proto will be added into the wallet where applicable and
|
||||
* overwrite where not.</p>
|
||||
* <p>Loads wallet data from the given protocol buffer and inserts it into the given Wallet object. This is primarily
|
||||
* useful when you wish to pre-register extension objects. Note that if loading fails the provided Wallet object
|
||||
* may be in an indeterminate state and should be thrown away.</p>
|
||||
*
|
||||
* <p>A wallet can be unreadable for various reasons, such as inability to open the file, corrupt data, internally
|
||||
* inconsistent data, a wallet extension marked as mandatory that cannot be handled and so on. You should always
|
||||
@ -377,14 +377,14 @@ public class WalletProtobufSerializer {
|
||||
*
|
||||
* @throws UnreadableWalletException thrown in various error conditions (see description).
|
||||
*/
|
||||
public Wallet readWallet(InputStream input) throws UnreadableWalletException {
|
||||
public Wallet readWallet(InputStream input, @Nullable WalletExtension... walletExtensions) throws UnreadableWalletException {
|
||||
try {
|
||||
Protos.Wallet walletProto = parseToProto(input);
|
||||
final String paramsID = walletProto.getNetworkIdentifier();
|
||||
NetworkParameters params = NetworkParameters.fromID(paramsID);
|
||||
if (params == null)
|
||||
throw new UnreadableWalletException("Unknown network parameters ID " + paramsID);
|
||||
return readWallet(params, null, walletProto);
|
||||
return readWallet(params, walletExtensions, walletProto);
|
||||
} catch (IOException e) {
|
||||
throw new UnreadableWalletException("Could not parse input stream to protobuf", e);
|
||||
} catch (IllegalStateException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user