Author

Topic: Bitcoin Daemon / Bitcoin-QT -Is it possible to show what block a tx confirmed in (Read 568 times)

legendary
Activity: 2254
Merit: 1140
I guess I would have to do something like $currentblock - $numConfirmations to be sure it was confirmed in time.  

That depends on what information you want.

For example, if you want the block height of the block where the transaction was first confirmed, you could use a combination of getrawtransaction and getblock.

Here's an example using transaction ID 584955e07e3b87bb23446e704c73ce2332ce21adca1798ca1b8590d414a87bd7:

Command:
Code:
getrawtransaction 584955e07e3b87bb23446e704c73ce2332ce21adca1798ca1b8590d414a87bd7 1
Result:
Quote
{
- snip -
"blockhash" : "000000000000000000c38b7591b174ca4915ced5ff5dc8d9b1883df56899139d",
"confirmations" : 11,
- snip -
}

Command:
Code:
getblock 000000000000000000c38b7591b174ca4915ced5ff5dc8d9b1883df56899139d
Result:
Quote
{
- snip -
"confirmations" : 11,
"size" : 737575,
"height" : 401460,
- snip -

As you can see, the transaction was first confirmed in the block at height 401460 in the block with hash 000000000000000000c38b7591b174ca4915ced5ff5dc8d9b1883df56899139d

Therefore, if 401460 is less than your target block height, the transaction had at least one confirmation at the time of the target block.

How do you plan on handling re-orgs (where transactions that were confirmed with only 1 or 2 confirmations may become unconfirmed)?

Does it matter how many confirmations the transaction has, or do you just need ot know that it has at least 1?

Thanks Danny!   This actually seems like the perfect solution.

As far as reorgs, I won't pay out until 4-6 confirmations, however I just need to know that the transaction was confirmed in or before the target block.   It does not need to get calculated at the time of the target block.   It can happen just before payout.   Any opinion as to what a safe time to do that is?   I was thinking 6, but would 4 confirmations be enough to calculate the results?

Having the correct block height and hash for the target is crucial as each team will have a chance of winning proportional to the amount each team has wagered and since it is provably fair, I will be using a blockhash + server secret method.


EDIT: Looks like I need to build a tx index with this method.   Will report back.   Thanks again Danny.
legendary
Activity: 3472
Merit: 4801
I guess I would have to do something like $currentblock - $numConfirmations to be sure it was confirmed in time. 

That depends on what information you want.

For example, if you want the block height of the block where the transaction was first confirmed, you could use a combination of getrawtransaction and getblock.

Here's an example using transaction ID 584955e07e3b87bb23446e704c73ce2332ce21adca1798ca1b8590d414a87bd7:

Command:
Code:
getrawtransaction 584955e07e3b87bb23446e704c73ce2332ce21adca1798ca1b8590d414a87bd7 1
Result:
Quote
{
- snip -
"blockhash" : "000000000000000000c38b7591b174ca4915ced5ff5dc8d9b1883df56899139d",
"confirmations" : 11,
- snip -
}

Command:
Code:
getblock 000000000000000000c38b7591b174ca4915ced5ff5dc8d9b1883df56899139d
Result:
Quote
{
- snip -
"confirmations" : 11,
"size" : 737575,
"height" : 401460,
- snip -

As you can see, the transaction was first confirmed in the block at height 401460 in the block with hash 000000000000000000c38b7591b174ca4915ced5ff5dc8d9b1883df56899139d

Therefore, if 401460 is less than your target block height, the transaction had at least one confirmation at the time of the target block.

How do you plan on handling re-orgs (where transactions that were confirmed with only 1 or 2 confirmations may become unconfirmed)?

Does it matter how many confirmations the transaction has, or do you just need ot know that it has at least 1?
legendary
Activity: 2254
Merit: 1140
You can use  gettransaction or getrawtransaction to get the details of a transaction and see how many confirmations it has.


I guess I would have to do something like $currentblock - $numConfirmations to be sure it was confirmed in time. 
staff
Activity: 3458
Merit: 6793
Just writing some code
You can use  gettransaction or getrawtransaction to get the details of a transaction and see how many confirmations it has.
legendary
Activity: 2254
Merit: 1140
So, I am in development of a Lotto type game.   It is round based, and the rounds end on a certain block number.

I only want to count transactions that have 1 confirmation by the time the target block hits.    However I am not sure how to accomplish this given the current list of Bitcoin RPC commands as shown here: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

It is team based as well, so each team will have a new address for each round.

I know it is possible to do using the blockchain API but I would really like to figure out a way to do it with the daemon so I can expand to other coins in the future.

Any suggestions?
Jump to: