I suggest you closely examine bitcoinj's log output. Especially around
the first appearance of the transaction ID of your missing incoming
transaction, what does it tell? Usually relevant pending transactions
should be added to the wallet's pending pool, except if the transaction
is considered risky.


On 05/11/2018 06:08 AM, Ian Pierce wrote:
> 
> I'm trying to get the pending transactions from my localhost node
> (NetworkParameters params = RegTestParams.get();) using my SPV wallet.
> So when I create a transaction sending funds from my localhost node to
> my SPV wallet I immediately see the transaction instead of waiting for
> it to be confirmed. 
> 
> I see the pending 0 conf transaction on my node when I execute:
> 
> ./bitcoin-cli -regtest listtransactions
> |
> {
>     "account": "",
>     "address": "n4BMZgwrL8xoduXDh1tgrfRXV8r8YhYxLS",
>     "category": "send",
>     "amount": -10.00000000,
>     "vout": 0,
>     "fee": -0.00003360,
>     "confirmations": 0,
>     "trusted": true,
>     "txid":
> "725ad4dcfee6378e699745534bad95a52baae4496ad0ca6a735dfcaa2b8ba77d",
>     "walletconflicts": [
>     ],
>     "time": 1525835288,
>     "timereceived": 1525835288,
>     "bip125-replaceable": "no",
>     "abandoned": false
> }
> |
> 
> I see that my wallet is listening for the correct address:
> 
> addr:n4BMZgwrL8xoduXDh1tgrfRXV8r8YhYxLS is listed along with the other
> two public addresses which already received transactions. The other two
> transactions were confirmed on my localhost blockchain and the wallet
> finds those no problem.
> 
> wallet.toString()
> |
> Wallet containing 20.00 BTC (spendable: 20.00 BTC) in:
>   0 pending transactions
>   2 unspent transactions
>   0 spent transactions
>   0 dead transactions
> Last seen best block: 102 (2018-05-09T02:41:50Z):
> 403e15efadaa0723a34525c8a99d3b48dcb686970b7fb4e3cce46ef39ea097b1
> 
> Keys:
> Earliest creation time: 2018-05-08T05:11:55Z
> Seed birthday: 1525756315  [2018-05-08T05:11:55Z]
> Key to watch: 
> tpubD8oxvS8LoVzaMfThLGMpapwiX4DpSGyxE2EME6WyG5ZnEBvBkGkMUgsBKpuDYKv6se5P3vpEgVXT46eANE7cuyBkVwJMQcnRagQTwspf5GV
>   addr:mpwXH58im3MBLszzZhhui9tboT4re13ToE 
> hash160:675ea5e47418ba7b4bdae54dc3a905726d38aa80  (M/0H/0/0)
>   addr:mhYeYHdmbVAhkwnsn9QrAYUdiCV31zGuin 
> hash160:16424340810fabe6d5c7285199809b4257553bae  (M/0H/0/1)
>   addr:n4BMZgwrL8xoduXDh1tgrfRXV8r8YhYxLS 
> hash160:f895ff8dbc68d497c83f49dc4d3e69db03e11635  (M/0H/0/2)
> 
> 
>>>> UNSPENT:
> 10.00 BTC total value (sends 0.00 BTC and receives 10.00 BTC)
>   confidence: Appeared in best chain at height 104, depth 103. Source:
> NETWORK
>   88e4fb901b77bf2639c75fa7ceacc35a4a3c69848f4f1b338c6443419b918261
>   updated: 2018-05-09T03:06:09Z
>   version 2
>   time locked until block 71
>      in   PUSHDATA(22)[00141a0baa176e8b351f24a5bd53489f931af9d19a62]
> 39.999962 BTC
>          
> outpoint:480d793055e871a89a4575b30fa12bfb896a8ddac963cc814c7342e4303750a1:1
> hash160:f6ef780f621daa3c47dffb2f12fb2343e0f96d8a
>           sequence:fffffffe
>      out  HASH160 PUSHDATA(20)[fc9b41dcd99fd7249cea58498db7bed0c8437100]
> EQUAL 29.9999284 BTC
>      out  DUP HASH160
> PUSHDATA(20)[16424340810fabe6d5c7285199809b4257553bae] EQUALVERIFY
> CHECKSIG 10.00 BTC
>      fee  0.00024 BTC/kB, 0.0000336 BTC for 140 bytes
>      prps UNKNOWN
> 10.00 BTC total value (sends 0.00 BTC and receives 10.00 BTC)
>   confidence: Appeared in best chain at height 103, depth 715. Source:
> NETWORK
>   480d793055e871a89a4575b30fa12bfb896a8ddac963cc814c7342e4303750a1
>   updated: 2018-05-09T02:58:24Z
>   version 2
>   time locked until block 102
>      in 
>  
> PUSHDATA(72)[3045022100ccafa7d27952e3e0290457944900d0d3840858f264978d255130d8d833960dd3022074f4d29f3f4759e0a14e280e9801aa7d709a725773fb3e257b89328c42cdab4d01]
>          
> outpoint:efa1370d76908a548792b290ebbb88d2f034d96cf4b7a2cc59329f01411615fa:0
>           sequence:fffffffe
>      out  DUP HASH160
> PUSHDATA(20)[675ea5e47418ba7b4bdae54dc3a905726d38aa80] EQUALVERIFY
> CHECKSIG 10.00 BTC
>      out  HASH160 PUSHDATA(20)[f6ef780f621daa3c47dffb2f12fb2343e0f96d8a]
> EQUAL 39.999962 BTC Spent by
> 88e4fb901b77bf2639c75fa7ceacc35a4a3c69848f4f1b338c6443419b918261
>      prps UNKNOWN
> |
> 
> My main file. 
> 
> public class PaymentsReceived {
>     public static void main(String[] args) {
>         try {
>             WalletBundle bundle = new WalletBundle(args[0]);
>             Wallet wallet = bundle.getWallet();
>             PeerGroup peerGroup = bundle.getPeerGroup();
> 
>             Coin availableCoin = 
> wallet.getBalance(Wallet.BalanceType.AVAILABLE);
>             Coin availableSpendableCoin = 
> wallet.getBalance(Wallet.BalanceType.AVAILABLE_SPENDABLE);
>             Coin estimatedCoin = 
> wallet.getBalance(Wallet.BalanceType.ESTIMATED);
>             Coin estimatedSpendableCoin = 
> wallet.getBalance(Wallet.BalanceType.ESTIMATED_SPENDABLE);
> 
>             System.out.println("Balance: " + 
> bundle.getWallet().getBalance().toFriendlyString());
>             System.out.println("Available Balance: " + 
> availableCoin.toFriendlyString());
>             System.out.println("Estimated Balance: " + 
> estimatedCoin.toFriendlyString());
>             System.out.println("Available Spendable Balance: " + 
> availableSpendableCoin.toFriendlyString());
>             System.out.println("Estimated Spendable Balance: " + 
> estimatedSpendableCoin.toFriendlyString());
> 
>             List<TransactionOutput> watchedOutputs = 
> wallet.getWatchedOutputs(true);
> 
>             for (final TransactionOutput output : watchedOutputs) {
>                 System.out.println("watched output: " + output.toString());
>             }
> 
>             Collection<Transaction> pendingTransactions = 
> wallet.getPendingTransactions();
> 
>             for (final Transaction transaction : pendingTransactions) {
>                 System.out.println("pending tx: " + transaction.toString());
>             }
> 
>             List<TransactionOutput> spendCandidates = 
> wallet.calculateAllSpendCandidates(false, false);
> 
>             for (final TransactionOutput output : spendCandidates) {
>                 System.out.println("spend candidate output: " + 
> output.toString());
>             }
> 
> 
>         } catch (UnreadableWalletException e) {
>             e.printStackTrace();
>         } catch (IOException e) {
>             e.printStackTrace();
>         } catch (BlockStoreException e) {
>             e.printStackTrace();
>         } catch (InterruptedException e) {
>             e.printStackTrace();
>         }
>     }
> }
> 
> 
> I use RegTestParams.get() and peerGroup.connectToLocalHost()to connect
> to my localhost node. I would expect peerGroup.addWallet(wallet) to
> associate my wallet with the public keys it's watching. But I'm not sure
> how to sync relevant transactions from my localhost node's mempool with
> my SPV wallet.
> 
> public class WalletBundle {
> 
>     private final Wallet wallet;
>     private final BlockStore blockStore;
>     private final BlockChain blockChain;
>     private final PeerGroup peerGroup;
> 
>     public WalletBundle(String fileName) throws UnreadableWalletException, 
> BlockStoreException, IOException, InterruptedException {
>         File walletFile = new File(fileName);
> 
>         wallet = Wallet.loadFromFile(walletFile, null);
> 
>         final NetworkParameters params = RegTestParams.get();
> 
>         File chainFile = new File("restore-from-seed.spvchain");
> 
>         boolean downloadBlockchain = true;
> 
> //        if (chainFile.exists()) {
> //            chainFile.delete();
> //            downloadBlockchain = false;
> //        }
> 
>         blockStore = new SPVBlockStore(params, chainFile);
>         blockChain = new BlockChain(params, wallet, blockStore);
>         peerGroup = new PeerGroup(params, blockChain);
> 
>         blockChain.addWallet(wallet);
>         peerGroup.addWallet(wallet);
> 
>         System.out.println("Starting PeerGroup");
>         peerGroup.start();
>         peerGroup.connectToLocalHost();
> 
>         DownloadProgressTracker bListener = new DownloadProgressTracker() {
>             @Override
>             public void doneDownload() {
>                 System.out.println("blockchain downloaded");
>             }
> 
>             @Override
>             protected void startDownload(int blocks) {
>                 super.startDownload(blocks);
>                 System.out.println("number of blocks to DL: " + blocks);
>             }
>         };
> 
>         if (downloadBlockchain) {
>             System.out.println("Starting Blockchain download");
>             peerGroup.startBlockChainDownload(bListener);
> 
>             System.out.println("Waiting...");
>             bListener.await();
>         }
> 
>         System.out.println("Allow unconfirmed transactions");
>         wallet.allowSpendingUnconfirmedTransactions();
> 
>         wallet.saveToFile(walletFile);
>         System.out.println("Saved wallet to file");
> 
>         System.out.println(wallet.toString());
>     }
> 
>     public Wallet getWallet() {
>         return wallet;
>     }
> 
>     public BlockStore getBlockStore() {
>         return blockStore;
>     }
> 
>     public BlockChain getBlockChain() {
>         return blockChain;
>     }
> 
>     public PeerGroup getPeerGroup() {
>         return peerGroup;
>     }
> }
> 
> 
> The stdout from executing my Main method:
> 
> |
> Starting PeerGroup
> Starting Blockchain download
> Waiting...
> number of blocks to DL: 2
> blockchain downloaded
> Allow unconfirmed transactions
> Saved wallet to file
> Wallet containing 20.00 BTC (spendable: 20.00 BTC) in:
>   0 pending transactions
>   2 unspent transactions
>   0 spent transactions
>   0 dead transactions
> Last seen best block: 102 (2018-05-09T02:41:50Z):
> 403e15efadaa0723a34525c8a99d3b48dcb686970b7fb4e3cce46ef39ea097b1
> 
> Keys:
> Earliest creation time: 2018-05-08T05:11:55Z
> Seed birthday: 1525756315  [2018-05-08T05:11:55Z]
> Key to watch: 
> tpubD8oxvS8LoVzaMfThLGMpapwiX4DpSGyxE2EME6WyG5ZnEBvBkGkMUgsBKpuDYKv6se5P3vpEgVXT46eANE7cuyBkVwJMQcnRagQTwspf5GV
>   addr:mpwXH58im3MBLszzZhhui9tboT4re13ToE 
> hash160:675ea5e47418ba7b4bdae54dc3a905726d38aa80  (M/0H/0/0)
>   addr:mhYeYHdmbVAhkwnsn9QrAYUdiCV31zGuin 
> hash160:16424340810fabe6d5c7285199809b4257553bae  (M/0H/0/1)
>   addr:n4BMZgwrL8xoduXDh1tgrfRXV8r8YhYxLS 
> hash160:f895ff8dbc68d497c83f49dc4d3e69db03e11635  (M/0H/0/2)
> 
> 
>>>> UNSPENT:
> 10.00 BTC total value (sends 0.00 BTC and receives 10.00 BTC)
>   confidence: Appeared in best chain at height 104, depth 103. Source:
> NETWORK
>   88e4fb901b77bf2639c75fa7ceacc35a4a3c69848f4f1b338c6443419b918261
>   updated: 2018-05-09T03:06:09Z
>   version 2
>   time locked until block 71
>      in   PUSHDATA(22)[00141a0baa176e8b351f24a5bd53489f931af9d19a62]
> 39.999962 BTC
>          
> outpoint:480d793055e871a89a4575b30fa12bfb896a8ddac963cc814c7342e4303750a1:1
> hash160:f6ef780f621daa3c47dffb2f12fb2343e0f96d8a
>           sequence:fffffffe
>      out  HASH160 PUSHDATA(20)[fc9b41dcd99fd7249cea58498db7bed0c8437100]
> EQUAL 29.9999284 BTC
>      out  DUP HASH160
> PUSHDATA(20)[16424340810fabe6d5c7285199809b4257553bae] EQUALVERIFY
> CHECKSIG 10.00 BTC
>      fee  0.00024 BTC/kB, 0.0000336 BTC for 140 bytes
>      prps UNKNOWN
> 10.00 BTC total value (sends 0.00 BTC and receives 10.00 BTC)
>   confidence: Appeared in best chain at height 103, depth 715. Source:
> NETWORK
>   480d793055e871a89a4575b30fa12bfb896a8ddac963cc814c7342e4303750a1
>   updated: 2018-05-09T02:58:24Z
>   version 2
>   time locked until block 102
>      in 
>  
> PUSHDATA(72)[3045022100ccafa7d27952e3e0290457944900d0d3840858f264978d255130d8d833960dd3022074f4d29f3f4759e0a14e280e9801aa7d709a725773fb3e257b89328c42cdab4d01]
>          
> outpoint:efa1370d76908a548792b290ebbb88d2f034d96cf4b7a2cc59329f01411615fa:0
>           sequence:fffffffe
>      out  DUP HASH160
> PUSHDATA(20)[675ea5e47418ba7b4bdae54dc3a905726d38aa80] EQUALVERIFY
> CHECKSIG 10.00 BTC
>      out  HASH160 PUSHDATA(20)[f6ef780f621daa3c47dffb2f12fb2343e0f96d8a]
> EQUAL 39.999962 BTC Spent by
> 88e4fb901b77bf2639c75fa7ceacc35a4a3c69848f4f1b338c6443419b918261
>      prps UNKNOWN
> 
> Balance: 20.00 BTC
> Available Balance: 20.00 BTC
> Estimated Balance: 20.00 BTC
> Available Spendable Balance: 20.00 BTC
> Estimated Spendable Balance: 20.00 BTC
> spend candidate output: TxOut of 10.00 BTC to
> mpwXH58im3MBLszzZhhui9tboT4re13ToE script:DUP HASH160
> PUSHDATA(20)[675ea5e47418ba7b4bdae54dc3a905726d38aa80] EQUALVERIFY CHECKSIG
> spend candidate output: TxOut of 10.00 BTC to
> mhYeYHdmbVAhkwnsn9QrAYUdiCV31zGuin script:DUP HASH160
> PUSHDATA(20)[16424340810fabe6d5c7285199809b4257553bae] EQUALVERIFY CHECKSIG
> |
> 
> 
> How can I watch my node's mempool so I can get relevant transactions
> whose outputs satisfy the addresses that my node is watching? I would
> like to be able to be instantly notified when a relevant transaction
> enters the mempool.
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bitcoinj+unsubscr...@googlegroups.com
> <mailto:bitcoinj+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bitcoinj+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to