Hello, Andreas!
Thanks for your answer.
> The CancelledKeyException isn't a bad sign. It just happens if some peer
> remotely disconnects.
This code is supposed to connect to a locally running regtest network. If that network disconnects regularly, this is probably an error in the configuration of the test network, isn't it?
# testnet-box functionality
regtest=1
dnsseed=0
upnp=0
# always run a server, even with bitcoin-qt
server=1
txindex=1
addressindex=1
timestampindex=1
spentindex=1
uacomment=bitcore
rpcworkqueue=128
dbcache=16384
rpcuser=test
rpcpassword=test
# listen on different ports than default testnet
[regtest]
rpcbind=0.0.0.0
port=19000
rpcport=19001
> I don't see the code that actually observes the address. Can you show it?
Sure, here it is:
public void init() {
BriefLogFormatter.init();
final LocalTestNetParams netParams = new LocalTestNetParams();
netParams.setPort(CUR_PORT);
try {
final WalletAppKit kit = new WalletAppKit(netParams, new File("."), "_minimalCryptoExchangeBtcWallet");
kit.connectToLocalHost();
kit.setAutoSave(false);
kit.startAsync();
kit.awaitRunning();
System.out.println("Port works");
kit.peerGroup().addPeerDiscovery(new DnsDiscovery(netParams));
kit.wallet().addWatchedAddress(Address.fromString(netParams, "2N23tWAFEtBtTgxNjBNmnwzsiPdLcNek181"));
kit.wallet().addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
@Override
public void onCoinsReceived(final Wallet wallet, final Transaction transaction, final Coin prevBalance, final Coin newBalance) {
System.out.println("Heyo!");
}
});
}
catch (Exception exception) {
exception.printStackTrace();
}
}
The method that is supposed to be called whenever money has been sent to 2N23tWAFEtBtTgxNjBNmnwzsiPdLcNek181 is onCoinsReceived.
Please note that until now I never got past kit.awaitRunning(). I terminated the application after that message. So I haven't tested the code after kit.awaitRunning() yet.
Feedback regarding errors in this code is highly appreciated as I never worked with Bitcoin/BitcoinJ before.
Thanks!
Dmitrii