Bitcoin Forum
April 25, 2024, 03:47:28 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to get tx hash in someone block?  (Read 1858 times)
yky_sh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 6


View Profile
August 15, 2016, 07:39:04 AM
 #1

I want to use "getblock" msg to get someone block information. but the tx information in block only don't contain the tx hash, the hash in tx is the previous transaction hash.
So, how can I get the current hash code of the block?

Then, in blockchain(link:www.blockchain.info), each transaction contain the in and out bitcoin address, can I get these addresses in block? which message can I use to get these?
https://blockchain.info/tx/836bd0af24d9a00d916b8bd2a98df8ac7aac2fedae7de793d6a70f2d750dd7d8

thank you!
1714016848
Hero Member
*
Offline Offline

Posts: 1714016848

View Profile Personal Message (Offline)

Ignore
1714016848
Reply with quote  #2

1714016848
Report to moderator
"In a nutshell, the network works like a distributed timestamp server, stamping the first transaction to spend a coin. It takes advantage of the nature of information being easy to spread but hard to stifle." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
mcb1221
Legendary
*
Offline Offline

Activity: 1162
Merit: 1000



View Profile
August 15, 2016, 07:40:49 AM
 #2

just at the last of transaction url put "?format=hex" without quotes.
example: https://blockchain.info/tx/836bd0af24d9a00d916b8bd2a98df8ac7aac2fedae7de793d6a70f2d750dd7d8?format=hex

             ▄▄▄▄██████████▄▄▄▄
         ▄▄██▀▀▀               ▀▀▄▄
      ▄▄█▀                         ▀▀▄
    ▄█▀                        ▄▄▀▀▀▀▀█
  ▄██                     ▄▄█▀▀     ▄▀
 ██▀                 ▄▄██████▄    ▄▀
███               ▄▄██████████▄  ▀
██             ▄▄█████████████▀
██          ▄▄█████████████▀
██        ▄ ▀██████████████
██▄    ▄██▀▀  ▀▀████████▀
 ██   ██▀        ▀▀████▀
  ██ █▀
   ▀█
  █▄ ▀▄
 ▄▀    ▀▄
 
SatoshiGames.io
██████

█████

████

████

█████

██████
               ▄▀▀▀▀▀▄▄▄▄
           ▄▄▄▄█  ▄█     ▀▀▀▀▄▄▄▄
▄▄▀▀▀▀▀▀▀▀▀   █  ▀ █            ▀▀▀▀▄
█  █▄        ▄▀                    ▄▀
▀▄ █ ▀       █         ▄           █
 █          █        ▄██▄         ▄▀
 █         ▄▀     ▄██████▄       ▄▀
 ▀▄        █    ▄█████████▄      █
  █       █      ██████████▄    ▄▀
  █      ▄▀        ▀████████   ▄▀
  ▀▄     █        ▄████▀▀▀▀    █
   █    █          ▀▀▀█       ▄▀
   █   ▄▀                    ▄▀
   ▀▄  █                     █
    █  ▀▄▄              █ ▄ ▄▀
    █     ▀▀▀▀▄▄▄       █▀ ▄▀
    ▀▄▄▄▄▄▄▄▄▀▀▀▀▀▀▀▀▀▀▄▄▄▄█


▄▄▄▄██████▄▄█▄▄██████▄▄▄▄
███████████████████████████████
▄▀▄           █           ▄▀▄
█   █         ▄█▄         █   █
█     █        ███        █     █
█       █       ███       █       █
█         █     █████     █         █
█           █    █████    █           █
█             █   █████   █             █
█▄▄▄▄▄▄▄▄▄▄▄▄▄█   █████   █▄▄▄▄▄▄▄▄▄▄▄▄▄█
▀███████████▀    █████    ▀███████████▀
▀▀▀▀▀▀▀▀▀       ███       ▀▀▀▀▀▀▀▀▀

▄███▄
▄▄▄█████████████▄▄▄
BTC
██████

█████

████

████

█████

██████
yky_sh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 6


View Profile
August 15, 2016, 08:11:43 AM
 #3

just at the last of transaction url put "?format=hex" without quotes.
example: https://blockchain.info/tx/836bd0af24d9a00d916b8bd2a98df8ac7aac2fedae7de793d6a70f2d750dd7d8?format=hex

Thank you very much.
I mean to get these information by protocal command in developer-reference, such as "getblocks", "getheaders".
DannyHamilton
Legendary
*
Offline Offline

Activity: 3374
Merit: 4606



View Profile
August 15, 2016, 11:52:57 AM
 #4

I want to use "getblock" msg to get someone block information.

That should work fine as long as you know the block hash.

If you only know the block index, then you'll need to run getblockhash first.

but the tx information in block only don't contain the tx hash,

Yes, it does.

getblock returns the block header and a list of all the transaction hashes of all the transactions in the block.

the hash in tx is the previous transaction hash.

I think you are mistaken.  The list of transactions hashes provided by getblock are the hashes of the transactions that are included in that block.

So, how can I get the current hash code of the block?

If you are using getblock, then you already have the hash of the current block.  If you don't have the hash of the block then you'll need to know the index (the height of the block).  Then you can use getblockhash.  If you don't know the index or the hash, then how do you know which block you want to get?

Then, in blockchain(link:www.blockchain.info), each transaction contain the in and out bitcoin address, can I get these addresses in block?

Once you have the transaction hash, you can get the details of the transaction with getrawtransaction (if you have txindex=1 in your bitcoin.conf)

The transaction outputs will have the address (if any) as well as the scriptPubKey so you can handle transaction outputs that do not have addresses.

The transaction inputs will have the index of the output and the transaction hash that identifies the output that is being spent.  You can use getrawtransaction on that transaction hash and look at the indicated output to find the address (if any) as well as the scriptPubKey so you can handle transaction outputs that do not have addresses.
yky_sh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 6


View Profile
August 16, 2016, 11:57:41 AM
 #5

I want to use "getblock" msg to get someone block information.

That should work fine as long as you know the block hash.

If you only know the block index, then you'll need to run getblockhash first.

but the tx information in block only don't contain the tx hash,

Yes, it does.

getblock returns the block header and a list of all the transaction hashes of all the transactions in the block.

the hash in tx is the previous transaction hash.

I think you are mistaken.  The list of transactions hashes provided by getblock are the hashes of the transactions that are included in that block.

So, how can I get the current hash code of the block?

If you are using getblock, then you already have the hash of the current block.  If you don't have the hash of the block then you'll need to know the index (the height of the block).  Then you can use getblockhash.  If you don't know the index or the hash, then how do you know which block you want to get?

Then, in blockchain(link:www.blockchain.info), each transaction contain the in and out bitcoin address, can I get these addresses in block?

Once you have the transaction hash, you can get the details of the transaction with getrawtransaction (if you have txindex=1 in your bitcoin.conf)

The transaction outputs will have the address (if any) as well as the scriptPubKey so you can handle transaction outputs that do not have addresses.

The transaction inputs will have the index of the output and the transaction hash that identifies the output that is being spent.  You can use getrawtransaction on that transaction hash and look at the indicated output to find the address (if any) as well as the scriptPubKey so you can handle transaction outputs that do not have addresses.


Thank your answer, according your answer, i get what i want.
i have other question,
memkleblock: i know , when i send "getdata" message to node, and node maybe reply the "memkleblock". but , i don't know how to set inv data struct in "getdata" message,
1, type, I set 2 or 3?  2 means MSG_BLOCK, 3 means MSG_FILTERED_BLOCK;
2, hash, I set block hash or memkle hash?

the whole stage of "memkleblock" as follow:
"?" -> "inv"-> "getdata"->"memkleblock".
when start, what message should I send to node?

Thank you !



achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6535


Just writing some code


View Profile WWW
August 16, 2016, 12:50:41 PM
 #6

Thank your answer, according your answer, i get what i want.
i have other question,
memkleblock: i know , when i send "getdata" message to node, and node maybe reply the "memkleblock". but , i don't know how to set inv data struct in "getdata" message,
1, type, I set 2 or 3?  2 means MSG_BLOCK, 3 means MSG_FILTERED_BLOCK;
You need to set inv type 3, MSG_FILTERED_BLOCK. But in order to do so, you first must set a bloom filter using filterload.

2, hash, I set block hash or memkle hash?
Block Hash.

the whole stage of "memkleblock" as follow:
"?" -> "inv"-> "getdata"->"memkleblock".
when start, what message should I send to node?
You first do the handshake with the version messages. Then you have to set a bloom filter using filterload. Then you send a getblocks message and the node returns you an inv. Then you can send a getdata and you will get a merkleblock in response.

BTW, it's merkleblock and merkle root, not memkle.

yky_sh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 6


View Profile
August 17, 2016, 03:16:18 AM
 #7

Thank your answer, according your answer, i get what i want.
i have other question,
memkleblock: i know , when i send "getdata" message to node, and node maybe reply the "memkleblock". but , i don't know how to set inv data struct in "getdata" message,
1, type, I set 2 or 3?  2 means MSG_BLOCK, 3 means MSG_FILTERED_BLOCK;
You need to set inv type 3, MSG_FILTERED_BLOCK. But in order to do so, you first must set a bloom filter using filterload.

2, hash, I set block hash or memkle hash?
Block Hash.

the whole stage of "memkleblock" as follow:
"?" -> "inv"-> "getdata"->"memkleblock".
when start, what message should I send to node?
You first do the handshake with the version messages. Then you have to set a bloom filter using filterload. Then you send a getblocks message and the node returns you an inv. Then you can send a getdata and you will get a merkleblock in response.

BTW, it's merkleblock and merkle root, not memkle.

Thank you very much. it's very explicit。
The last question:
how to get the block heigth number?
Thank you.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6535


Just writing some code


View Profile WWW
August 17, 2016, 03:24:03 AM
 #8

Thank you very much. it's very explicit。
The last question:
how to get the block heigth number?
Thank you.
You don't. There actually is no way to request a block by height over p2p in Bitcoin. In order to do so, you need to somehow get the hash. Really the only way is to start from the genesis block and start requesting every block and keeping count of what height you are at.

yky_sh (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 6


View Profile
August 17, 2016, 03:45:10 AM
 #9

Thank you very much. it's very explicit。
The last question:
how to get the block heigth number?
Thank you.
You don't. There actually is no way to request a block by height over p2p in Bitcoin. In order to do so, you need to somehow get the hash. Really the only way is to start from the genesis block and start requesting every block and keeping count of what height you are at.

Understand.
Thank you very much.
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!