Java Code Examples for org.bitcoinj.wallet.Wallet#saveToFile()

The following examples show how to use org.bitcoinj.wallet.Wallet#saveToFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WalletConfig.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
private Wallet createOrLoadWallet(File walletFile, boolean shouldReplayWallet,
                                  BisqKeyChainGroup keyChainGroup, boolean isBsqWallet, DeterministicSeed restoreFromSeed)
        throws Exception {

    if (restoreFromSeed != null)
        maybeMoveOldWalletOutOfTheWay(walletFile);

    Wallet wallet;
    if (walletFile.exists()) {
        wallet = loadWallet(walletFile, shouldReplayWallet, keyChainGroup.isUseBitcoinDeterministicKeyChain());
    } else {
        wallet = createWallet(keyChainGroup, isBsqWallet);
        wallet.freshReceiveKey();
        wallet.saveToFile(walletFile);
    }

    if (useAutoSave) wallet.autosaveToFile(walletFile, 5, TimeUnit.SECONDS, null);

    return wallet;
}
 
Example 2
Source File: WalletConfig.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private Wallet createOrLoadWallet(File walletFile, boolean shouldReplayWallet,
                                  BisqKeyChainGroup keyChainGroup, boolean isBsqWallet, DeterministicSeed restoreFromSeed)
        throws Exception {

    if (restoreFromSeed != null)
        maybeMoveOldWalletOutOfTheWay(walletFile);

    Wallet wallet;
    if (walletFile.exists()) {
        wallet = loadWallet(walletFile, shouldReplayWallet, keyChainGroup.isUseBitcoinDeterministicKeyChain());
    } else {
        wallet = createWallet(keyChainGroup, isBsqWallet);
        wallet.freshReceiveKey();
        wallet.saveToFile(walletFile);
    }

    if (useAutoSave) wallet.autosaveToFile(walletFile, 5, TimeUnit.SECONDS, null);

    return wallet;
}
 
Example 3
Source File: RefreshWallet.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
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());
}
 
Example 4
Source File: RefreshWallet.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
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());
}