Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListTransactionsOfBlock RPC method #2579

Closed
wants to merge 1 commit into from
Closed

ListTransactionsOfBlock RPC method #2579

wants to merge 1 commit into from

Conversation

shufps
Copy link

@shufps shufps commented Apr 26, 2013

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

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

@BitcoinPullTester
Copy link

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.

@jgarzik
Copy link
Contributor

jgarzik commented Jun 10, 2013

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.

@shufps
Copy link
Author

shufps commented Jun 10, 2013

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 ...

@jgarzik
Copy link
Contributor

jgarzik commented Jun 24, 2013

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.

@jgarzik jgarzik closed this Jun 24, 2013
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants