Here is the output of wallet.toString()
Wallet containing 6.30 BTC in:
1 unspent transactions
0 spent transactions
0 pending transactions
0 dead transactions
Last seen best block: (112773) 00000000761cc5b4eb871e745ae1512143e1fea5f2b26d639a8baf07c8bb35e1
Encryption: Scrypt/AES
Keys:
addr:n3LRVzswykPCUASzD9tgwFUNAyZqFrTXva pub:0285084a41af1d5e16bc704399892d47f552a6d677f4ac0ca095bbde6fa8ee0cfc encrypted
addr:n41AVgo7xj1LtFeKqH3iKNfPbfJBGcm6s1 pub:02ab19d8c48d52f52e549aab88f1f178984c2a5955b43f063b4db8187937b8ddc2 timestamp:1381115208
>>> UNSPENT:
Sends 0.00 and receives 6.30, total value 6.30.
ff0dd34050e4b62be5a46d513debc8ac6489346428441f9a8d0e964be95a7d73: Seen by 1 peer. Appeared in best chain at height 112773, depth 1, work done 4295032833.
in [3046022100e1d8132ca9fa32f6880d43dae9cb8be4dd1e9a05e41db001702a5c1892785f14022100ca1578a92da58becf550fd36589350be4f10808f1814d69d683ab1c33a2b1f3f01] [0313e5d56288e6775255cae5ddf0ef8a7f72244c3f6ec53189e061b077d5c983ed] / 3bb2ccd413fc24f0eba81f8e516cbf0e0ff26d7071d0715c27eb580db550a7c7:0
out DUP HASH160 [f6a8994404b8f34ce00f018c04ed6991f09f25fc] EQUALVERIFY CHECKSIG 6.30 BTC
out DUP HASH160 [61a9491d44c98ac08bd0fb043a6ec927f3f6b064] EQUALVERIFY CHECKSIG 159.10 BTC
And here is the parts where I set u bitcoinj.
public class BitcoinJWallet{
public static NetworkParameters params;
public static Wallet wallet;
public static PeerGroup peerGroup;
private AbstractBlockChain chain;
private File walletFile;
private ECKey key;
public BitcoinJWallet(){
params = TestNet3Params.get();
setupWallet();
wallet.addEventListener(new WalletConfirmations());
setupBlockchain();
setupPeerGroup();
}
public void setupWallet(){
final File walletFile = new File("site.wallet");
try {
wallet = Wallet.loadFromFile(walletFile);
} catch (UnreadableWalletException e) {
wallet = new Wallet(params);
wallet.addKey(new ECKey());
try {
wallet.saveToFile(walletFile);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(!wallet.isEncrypted()){
wallet.encrypt(config.WALLET_PASSWORD);
}
wallet.autosaveToFile(walletFile, 500, TimeUnit.MILLISECONDS, null);
}
key = wallet.getKeys().get(0);
}
public void setupBlockchain(){
try{
File file = new File("site.spvchain");
boolean chainExistedAlready = file.exists();
SPVBlockStore blockStore = new SPVBlockStore(params, file);
if (!chainExistedAlready) {
File checkpointsFile = new File("checkpoints");
if (checkpointsFile.exists()) {
FileInputStream stream = new FileInputStream(checkpointsFile);
CheckpointManager.checkpoint(params, stream, blockStore, key.getCreationTimeSeconds());
}
}
chain = new BlockChain(params, wallet, blockStore);
}catch(Exception e){
e.printStackTrace();
}
}
public void setupPeerGroup(){
peerGroup = new PeerGroup(params, chain);
try {
peerGroup.addAddress(new PeerAddress(InetAddress.getByName("127.0.0.1"), 18333));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
peerGroup.addWallet(wallet);
peerGroup.startAndWait();
peerGroup.downloadBlockChain();
}