/** * Uses protobuf serialization to save the wallet to the given file. To learn more about this file format, see * {@link WalletProtobufSerializer}. Writes out first to a temporary file in the same directory and then renames * once written. */ public void saveToFile(File f) throws IOException { File directory = f.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); saveToFile(temp, f); }
/** * Uses protobuf serialization to save the wallet to the given file. To learn more about this file format, see * {@link WalletProtobufSerializer}. Writes out first to a temporary file in the same directory and then renames * once written. */ public void saveToFile(File f) throws IOException { File directory = f.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); saveToFile(temp, f); }
/** * Uses protobuf serialization to save the wallet to the given file. To learn more about this file format, see * {@link WalletProtobufSerializer}. Writes out first to a temporary file in the same directory and then renames * once written. */ public void saveToFile(File f) throws IOException { File directory = f.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); saveToFile(temp, f); }
/** * Uses protobuf serialization to save the wallet to the given file. To learn more about this file format, see * {@link WalletProtobufSerializer}. Writes out first to a temporary file in the same directory and then renames * once written. */ public void saveToFile(File f) throws IOException { File directory = f.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); saveToFile(temp, f); }
private static void saveWallet(File walletFile) { try { // This will save the new state of the wallet to a temp file then rename, in case anything goes wrong. wallet.saveToFile(walletFile); } catch (IOException e) { System.err.println("Failed to save wallet! Old wallet should be left untouched."); e.printStackTrace(); System.exit(1); } }
private void saveNowInternal() throws IOException { final Stopwatch watch = Stopwatch.createStarted(); File directory = file.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); final Listener listener = vListener; if (listener != null) listener.onBeforeAutoSave(temp); wallet.saveToFile(temp, file); if (listener != null) listener.onAfterAutoSave(file); watch.stop(); log.info("Save completed in {}", watch); }
private void saveNowInternal() throws IOException { final Stopwatch watch = Stopwatch.createStarted(); File directory = file.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); final Listener listener = vListener; if (listener != null) listener.onBeforeAutoSave(temp); wallet.saveToFile(temp, file); if (listener != null) listener.onAfterAutoSave(file); watch.stop(); log.info("Save completed in {}", watch); }
private void saveNowInternal() throws IOException { final Stopwatch watch = Stopwatch.createStarted(); File directory = file.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); final Listener listener = vListener; if (listener != null) listener.onBeforeAutoSave(temp); wallet.saveToFile(temp, file); if (listener != null) listener.onAfterAutoSave(file); watch.stop(); log.info("Save completed in {}", watch); }
private void saveNowInternal() throws IOException { final Stopwatch watch = Stopwatch.createStarted(); File directory = file.getAbsoluteFile().getParentFile(); File temp = File.createTempFile("wallet", null, directory); final Listener listener = vListener; if (listener != null) listener.onBeforeAutoSave(temp); wallet.saveToFile(temp, file); if (listener != null) listener.onAfterAutoSave(file); watch.stop(); log.info("Save completed in {}", watch); }
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
@Override protected void shutDown() throws Exception { // Runs in a separate thread. try { Context.propagate(context); vPeerGroup.stop(); vWallet.saveToFile(vWalletFile); vStore.close(); vPeerGroup = null; vWallet = null; vStore = null; vChain = null; } catch (BlockStoreException e) { throw new IOException(e); } }
public BitcoinTestPaymentService(BlockChain bitcoinBlockchain, Context bitcoinContext, NetworkParameters bitcoinNetworkParameters, PeerGroup peerGroup, String walletPassword, String walletPath) throws IOException, CipherException, UnreadableWalletException { this.bitcoinBlockchain = bitcoinBlockchain; this.bitcoinContext = bitcoinContext; this.bitcoinNetworkParameters = bitcoinNetworkParameters; this.peerGroup = peerGroup; File walletFile = new File(walletPath); if (walletFile.exists()) { LOG.info("Wallet exists... trying to load from: {}", walletPath); this.bitcoinWallet = Wallet.loadFromFile(new File(walletPath)); } else { LOG.info("Wallet does NOT exist... creating one.", walletPath); this.bitcoinWallet = new Wallet(this.bitcoinContext); this.bitcoinWallet.saveToFile(walletFile); } LOG.info("Wallet loaded: address={}", this.bitcoinWallet.currentReceiveAddress()); this.bitcoinWallet.autosaveToFile(walletFile, 500, TimeUnit.MILLISECONDS, null); this.bitcoinBlockchain.addWallet(this.bitcoinWallet); peerGroup.addWallet(this.bitcoinWallet); }
wallet.saveToFile(walletFile);
public static void main(String[] args) throws Exception { File file = new File(args[0]); Wallet wallet = Wallet.loadFromFile(file); System.out.println(wallet.toString()); // Set up the components and link them together. final NetworkParameters params = TestNet3Params.get(); BlockStore blockStore = new MemoryBlockStore(params); BlockChain chain = new BlockChain(params, wallet, blockStore); final PeerGroup peerGroup = new PeerGroup(params, chain); peerGroup.startAsync(); wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() { @Override public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) { System.out.println("\nReceived tx " + tx.getHashAsString()); System.out.println(tx.toString()); } }); // Now download and process the block chain. peerGroup.downloadBlockChain(); peerGroup.stopAsync(); wallet.saveToFile(file); System.out.println("\nDone!\n"); System.out.println(wallet.toString()); } }
private Wallet createOrLoadWallet(boolean shouldReplayWallet) throws Exception { Wallet wallet; maybeMoveOldWalletOutOfTheWay(); if (vWalletFile.exists()) { wallet = loadWallet(shouldReplayWallet); } else { wallet = createWallet(); wallet.freshReceiveKey(); for (WalletExtension e : provideWalletExtensions()) { wallet.addExtension(e); } // Currently the only way we can be sure that an extension is aware of its containing wallet is by // deserializing the extension (see WalletExtension#deserializeWalletExtension(Wallet, byte[])) // Hence, we first save and then load wallet to ensure any extensions are correctly initialized. wallet.saveToFile(vWalletFile); wallet = loadWallet(false); } if (useAutoSave) { this.setupAutoSave(wallet); } return wallet; }
private Wallet createOrLoadWallet(boolean shouldReplayWallet) throws Exception { Wallet wallet; maybeMoveOldWalletOutOfTheWay(); if (vWalletFile.exists()) { wallet = loadWallet(shouldReplayWallet); } else { wallet = createWallet(); wallet.freshReceiveKey(); for (WalletExtension e : provideWalletExtensions()) { wallet.addExtension(e); } // Currently the only way we can be sure that an extension is aware of its containing wallet is by // deserializing the extension (see WalletExtension#deserializeWalletExtension(Wallet, byte[])) // Hence, we first save and then load wallet to ensure any extensions are correctly initialized. wallet.saveToFile(vWalletFile); wallet = loadWallet(false); } if (useAutoSave) { this.setupAutoSave(wallet); } return wallet; }
private Wallet createOrLoadWallet(boolean shouldReplayWallet) throws Exception { Wallet wallet; maybeMoveOldWalletOutOfTheWay(); if (vWalletFile.exists()) { wallet = loadWallet(shouldReplayWallet); } else { wallet = createWallet(); wallet.freshReceiveKey(); for (WalletExtension e : provideWalletExtensions()) { wallet.addExtension(e); } // Currently the only way we can be sure that an extension is aware of its containing wallet is by // deserializing the extension (see WalletExtension#deserializeWalletExtension(Wallet, byte[])) // Hence, we first save and then load wallet to ensure any extensions are correctly initialized. wallet.saveToFile(vWalletFile); wallet = loadWallet(false); } if (useAutoSave) { this.setupAutoSave(wallet); } return wallet; }
private Wallet createOrLoadWallet(boolean shouldReplayWallet) throws Exception { Wallet wallet; maybeMoveOldWalletOutOfTheWay(); if (vWalletFile.exists()) { wallet = loadWallet(shouldReplayWallet); } else { wallet = createWallet(); wallet.freshReceiveKey(); for (WalletExtension e : provideWalletExtensions()) { wallet.addExtension(e); } // Currently the only way we can be sure that an extension is aware of its containing wallet is by // deserializing the extension (see WalletExtension#deserializeWalletExtension(Wallet, byte[])) // Hence, we first save and then load wallet to ensure any extensions are correctly initialized. wallet.saveToFile(vWalletFile); wallet = loadWallet(false); } if (useAutoSave) { this.setupAutoSave(wallet); } return wallet; }