Hello, I try to send from Wallet.createBasic and importKey, this work good to sync, but when try to send the logs throw this:
java.lang.IllegalStateException: doesn't support deterministic chains
at com.google.common.base.Preconditions.checkState(Preconditions.java:510)
at org.bitcoinj.wallet.KeyChainGroup.getActiveKeyChain(KeyChainGroup.java:426)
at org.bitcoinj.wallet.KeyChainGroup.currentAddress(KeyChainGroup.java:308)
at org.bitcoinj.wallet.Wallet.currentAddress(Wallet.java:607)
at org.bitcoinj.wallet.Wallet.currentChangeAddress(Wallet.java:861)
at org.bitcoinj.wallet.Wallet.calculateFee(Wallet.java:5062)
at org.bitcoinj.wallet.Wallet.completeTx(Wallet.java:4151)
at org.bitcoinj.wallet.Wallet.sendCoinsOffline(Wallet.java:3948)
at org.bitcoinj.wallet.Wallet.sendCoins(Wallet.java:4015)
at org.bitcoinj.wallet.Wallet.sendCoins(Wallet.java:3984)
the dependency its the branch master (0.16-SNAPSHOT)
the Wif
cVYU7EDwyHdzhtz26v5REiLmq3zHpveb83LyWSpSYhf7BoaKY6mp
The unit test
@Test
public void TransferWallet0151() throws Exception {
Context.propagate(new Context(netParams));
File chainFileSeed = new File("seed.spvchain");
File chainFile = new File(System.currentTimeMillis() + ".spvchain");
byte[] allBytes = Files.readAllBytes(chainFileSeed.toPath());
Files.write(chainFile.toPath(), allBytes);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
Date time = calendar.getTime();
ECKey ecKey = DumpedPrivateKey.fromBase58(netParams, privateKeyAsWiF).getKey();
ecKey.setCreationTimeSeconds(time.getTime() / 1000);
Wallet wallet = Wallet.createBasic(netParams);
wallet.importKey(ecKey);
BlockStore blockStore = new SPVBlockStore(netParams, chainFile);
BlockChain chain = new BlockChain(netParams, blockStore);
final PeerGroup peerGroup = new PeerGroup(netParams, chain);
peerGroup.addPeerDiscovery(new DnsDiscovery(netParams));
peerGroup.setFastCatchupTimeSecs(time.getTime());
peerGroup.addWallet(wallet);
chain.addWallet(wallet);
peerGroup.start();
peerGroup.downloadBlockChain();
Address to = LegacyAddress.fromBase58(netParams, "mtGedFZpWkN5JHHMuG2q4JPtUneypAUAd2");
Coin coin = wallet.getBalance();
Wallet.SendResult sendResult = null;
while (true) try {
sendResult = wallet.sendCoins(peerGroup, to, coin);
break;
} catch (InsufficientMoneyException e) {
assert e.missing != null;
coin = coin.minus(e.missing);
} catch (Exception e) {
e.printStackTrace();
break;
}
peerGroup.stop();
chainFile.delete();
System.out.println("-------->");
System.out.println(LegacyAddress.fromKey(netParams, ecKey));
System.out.println("-------->");
System.out.println(sendResult);
System.out.println("-------->");
System.out.println(wallet);
wallet.cleanup();
}