ListTransactionsOfBlock RPC method #2579

pull shufps wants to merge 1 commits into bitcoin:master from shufps:master changing 3 files +31 −0
  1. shufps commented at 7:53 PM on April 26, 2013: none

    The method 'listtransactionsofblock' lists all transactions (from the wallet) which are in block with blockhash <hash>

    It can be used this way: (pseudo-code)

    ScanTransactions() {
      Database.TransactionBegin()
    
      long lastBlock = BitcoinRPC.getLastBlockNr()
      long lastScannedBlock = Database.getLastScannedBlock()
    
      while (lastBlock - lastScannedBlock > targetConfirms)  {
        lastScannedBlock++;
        string hash = BitcoinRPC.getHashOfBlock(lastScannedBlock)
        list<Transaction> list = BitcoinRPC.getTransactionsOfBlock(hash)
        for (Transaction t : list)
        {
          // do something
          // at this point, you can absolutely be sure to see only transactions 
          // with <targetconfirms> confirms.
          // and you only have to scan each block exactly once
        }
      }
      Database.saveLastScannedBlock()
      Database.TransactionCommit()
    }
    

    This is an easy example how payments can reliably be received.

    Explained here: #2565

  2. listtransactionsofblock added b17a24ca70
  3. BitcoinPullTester commented at 11:05 PM on April 26, 2013: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/b17a24ca7084f386330f4ceb7f5d314acddb87d2 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  4. jgarzik commented at 3:22 PM on June 10, 2013: contributor

    Technical comment: is it better to iterate through one block, checking IsMine(), than all transactions in wallet?

    Non-technical: is there a compelling use case? Ignored the solvable code objection, I'm tempted to close until a compelling need for this arises.

  5. shufps commented at 4:08 PM on June 10, 2013: none

    technical:

    Iterating through the block would only give me txids of all transactions within a block. With IsMine() I could check if this transaction belongs to my addresses. Then, I would have to to query the wallet to give me all transaction details for every transaction which is mine in the block I currently processed.

    I'm not sure if this would be more efficient because I thought json-rpc-calls are more expensive. So I thought, one single RPC-call would be better than lots of them ...

    non-technical:

    I tried to find a method for reliably receive confirmations about sent and received payments. I wanted to process every block exactly once and I'm working with a database which supports transactions, so everything happens within a single sql-transaction.

    My solution is absolutely bullet-proof and repeatable in case an Exception in my java code occures. So I don't lose/oversee anything and I can easily debug my errors.

    I invested almost a week and tried almost everything until I implemented it this way.

    There is another method which is called 'listtransationssinceblock' but it mostly gives unconfirmed transactions over and over again (with each call) back to my java-class. I was not interested in unconfirmed transactions but the method couldn't be restricted to only give back confirmed txs.

    I also tried what you suggested but there was the issue with lots and lots of rpc queries ...

  6. jgarzik commented at 2:50 PM on June 24, 2013: contributor

    That's not a compelling use case. If you are having problems with lots of RPC queries, then send a batch of them together as a JSON-RPC 2.0 batch.

    The problem with this method is that it causes over-reliance on a broken assumption that block == totally confirmed transactions. This is not true. You might have a chain reorganization at any time, which would invalidate any queries based on a specific block height/hash, and move transactions from one block to another.

  7. jgarzik closed this on Jun 24, 2013

  8. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-29 03:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me