내 목표는 입니다.은 공개 비트 코인 주소를보고 그 주소로 돈을 보낼 때마다 콘솔에 출력합니다. 그게 다야. Bitcoin Core에서 이전에 생성 된 주소를 사용하고 있습니다.Bitcoinj (java)에서 주소의 거래를 보는 방법?
나는 다음과 같은 일을 해요 : 내가 제대로 AbstractWalletEventListener를 처리하고 있지 않다 느낌이
NetworkParameters params = MainNetParams.get();
Wallet wallet = Wallet.loadFromFile(file);
BlockStore blockStore = new MemoryBlockStore(params);
BlockChain chain = new BlockChain(params, wallet, blockStore);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addPeerDiscovery(new DnsDiscovery(params));
peerGroup.setUseLocalhostPeerWhenPossible(true);
peerGroup.startAsync();
Address add = new Address(params, "1NpxxxxxxxxxxxxxxxaSC4");
wallet.addWatchedAddress(add);
wallet.addEventListener(new AbstractWalletEventListener() {
@Override
public synchronized void onCoinsReceived(Wallet w, Transaction tx, Coin prevBalance, Coin newBalance) {
System.out.println("[main]: COINS RECIEVED!");
System.out.println("\nReceived tx " + tx.getHashAsString());
System.out.println(tx.toString());
}
});
System.out.println("\nDone!\n");
System.out.println(wallet.toString());
. 주소로 돈을 보내면 콘솔에 표시되는 텍스트가 표시되지 않습니다. 대신, 나는 peerGroup.startAsync() 메소드의 [NioClientManager]에서 "peer announce New Transaction"의 연속적인 스트림을 볼 수있다.
내가 뭘 잘못하고 있으며 어떻게 해결할 수 있습니까? 나는 그런 간단한 일이어야하는 것처럼 보이는 무언가에 있어야하는 것보다 길을 더 많이 보냈다.
추신. "loadFromFile"을 호출하는 파일은 bitcoinj에 의해 생성 된 빈 지갑의 기본 지갑 파일입니다. 특별한 것은 없습니다.
편집 : 또한 지갑의 총 잔액을보고 싶지 않습니다. 나는 새로운 거래가 언제 올지 알고 싶을 뿐이다. 오래된 것들은 내 프로그램과는 무관하다.