Bitcoin Forum
June 26, 2024, 09:22:02 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin Daemon / Bitcoin-QT -Is it possible to show what block a tx confirmed in  (Read 555 times)
Rmcdermott927 (OP)
Legendary
*
Offline Offline

Activity: 2254
Merit: 1140


View Profile
March 17, 2016, 03:44:31 PM
 #1

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?

achow101
Moderator
Legendary
*
Offline Offline

Activity: 3430
Merit: 6720


Just writing some code


View Profile WWW
March 17, 2016, 03:48:17 PM
 #2

You can use  gettransaction or getrawtransaction to get the details of a transaction and see how many confirmations it has.

Rmcdermott927 (OP)
Legendary
*
Offline Offline

Activity: 2254
Merit: 1140


View Profile
March 17, 2016, 03:53:26 PM
 #3

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. 

DannyHamilton
Legendary
*
Offline Offline

Activity: 3430
Merit: 4680



View Profile
March 17, 2016, 04:37:36 PM
 #4

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?
Rmcdermott927 (OP)
Legendary
*
Offline Offline

Activity: 2254
Merit: 1140


View Profile
March 17, 2016, 04:48:44 PM
Last edit: March 17, 2016, 08:53:46 PM by Rmcdermott927
 #5

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.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!