1
2
3
4
5
6
7
8
9
10
|
# block 734206 header
block_header={
'ver': '0x2000e004', # 4 bytes
'prev_block':'0000000000000000000914331e5d52001a51ce23b4d176b4adbbdba9aac57663', # 32 bytes
'mrkl_root':'c6c565adffee226711d676ffee5fca583f5e5c4a5b93e6f03804386643f024bc', # 32 bytes
'time' : '2022-04-30 15:42:07', # 4 bytes
'bits' : '0x17097275', # 4 bytes
'nonce' : '0x3e1cb67c' # 4 bytes
} # total 80 bytes
|
cs |
[INPUT]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
##########################
# format convert to hex
##########################
from datetime import datetime
import time
import binascii
# reverse hex
block_header['ver'] = binascii.unhexlify(block_header['ver'][2:])[::-1].hex()
block_header['prev_block'] = binascii.unhexlify(block_header['prev_block'])[::-1].hex()
block_header['mrkl_root'] = binascii.unhexlify(block_header['mrkl_root'])[::-1].hex()
block_header['bits'] = binascii.unhexlify(block_header['bits'][2:])[::-1].hex()
block_header['nonce'] = binascii.unhexlify(block_header['nonce'][2:])[::-1].hex()
# time -> unix epoch -> hex
# and reverse hex
block_header['time'] = binascii.unhexlify(hex(int(time.mktime(\
datetime.strptime(block_header['time'], '%Y-%m-%d %H:%M:%S').timetuple())))[2:])[::-1].hex()
from pprint import pprint
pprint(block_header)
|
cs |
[OUTPUT]
1
2
3
4
5
6
|
{'bits': '75720917',
'mrkl_root': 'bc24f04366380438f0e6935b4a5c5e3f58ca5feeff76d6116722eeffad65c5c6',
'nonce': '7cb61c3e',
'prev_block': '6376c5aaa9dbbbadb476d1b423ce511a00525d1e331409000000000000000000',
'time': '3fda6c62',
'ver': '04e00020'}
|
cs |
[INPUT]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
##########################################################################
# serialized(80 bytes) -> double hashing(32 bytes) -> reverse -> get ID
##########################################################################
# serialized(80 bytes)
header = block_header['ver']+block_header['prev_block']+\
block_header['mrkl_root']+str(block_header['time'])+block_header['bits']+block_header['nonce']
print(header)
print('size = ',len(header)*4,'bits')
header_bin = binascii.a2b_hex(header)
# double hashing(32 bytes)
import hashlib
import codecs
hash256 = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
id_block_header_hash = codecs.encode(hash256[::-1],'hex').decode('utf-8')
print(id_block_header_hash)
|
cs |
[OUTPUT]
1
2
3
|
04e000206376c5aaa9dbbbadb476d1b423ce511a00525d1e331409000000000000000000bc24f04366380438f0e6935b4a5c5e3f58ca5feeff76d6116722eeffad65c5c63fda6c62757209177cb61c3e
size = 640 bits
00000000000000000008cd76babc05dc40cf177f790cbec0f79a54459657c2ae
|
cs |
4. 3-3에서 나온 id_block_header_hash와 734206높이의 block header 비교
비트코인 지갑이란? 그리고 니모닉(mnemonic) (0) | 2022.06.15 |
---|---|
암호학의 종류 간단하게 알아보기 (0) | 2022.06.13 |
비트코인 펀더멘탈 (0) | 2021.06.14 |
비트코인 가치 (0) | 2021.06.14 |
비트코인 이해 (0) | 2021.06.14 |