xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡介

Python學(xué)習(xí)區(qū)塊鏈入門代碼。區(qū)塊中數(shù)據(jù)使用MerkleTree結(jié)構(gòu),包含挖礦模擬等內(nèi)容。代碼易讀,適合初步入門學(xué)習(xí)。

資源截圖

代碼片段和文件信息

#?-*-?coding:utf-8?-*-

import?hashlib
import?uuid
import?random
import?time
from?merkletree?import?*

class?Block(object):
????def?__init__(self?data=None?previous_hash=None):
????????self.identifier?=?uuid.uuid4().hex??#?產(chǎn)生唯一標(biāo)示
????????self.nonce?=?None??#?nonce值(難度值)
????????self.data?=?data??#?區(qū)塊內(nèi)容
????????self.timestamp?=?str(time.time())??#?區(qū)塊標(biāo)識時(shí)間戳
????????self.ver?=?“1.0“??#?區(qū)塊鏈版本號
????????self.random_num?=?random.randint(10002000)??#?區(qū)塊頭隨機(jī)數(shù)
????????self.previous_hash?=?previous_hash??#?父節(jié)點(diǎn)哈希值
????????if?isinstance(data?list):
????????????self.mt?=?merkletree(data)
????????????self.merkle_root?=??str(self.mt.merkle_root)?#?區(qū)塊MT樹TopHash值
????????else:
????????????self.mt?=?list()
????????????self.merkle_root?=?“None“??#?區(qū)塊MT樹TopHash值

????def?hash(self?nonce=None):
????????‘‘‘
????????????計(jì)算區(qū)塊的哈希值?拼接區(qū)塊
????????‘‘‘
????????message?=?hashlib.sha256()
????????message.update(str(self.previous_hash).encode(‘utf-8‘))
????????message.update(self.ver.encode(‘utf-8‘))
????????message.update(self.timestamp.encode(‘utf-8‘))
????????message.update(self.identifier.encode(‘utf-8‘))
????????message.update(str(nonce).encode(‘utf-8‘))
????????message.update(str(self.random_num).encode(‘utf-8‘))
????????message.update(str(self.merkle_root).encode(‘utf-8‘))
????????return?message.hexdigest()

????def?hash_is_valid(self?the_hash):
????????return?the_hash.startswith(‘0000‘)

????def?__str__(self):
????????return?‘Block‘.format(self.hash(self.nonce)?self.nonce)

????def?__repr__(self):
????????return?‘Block‘.format(self.hash(self.nonce)?self.nonce)

????def?mine(self):
????????#?初始化nonce為0
????????cur_nonce?=?self.nonce?or?0
????????#?循環(huán)直到生成一個(gè)有效的哈希值
????????while?True:
????????????the_hash?=?self.hash(nonce=cur_nonce)
????????????if?self.hash_is_valid(the_hash):??#?如果生成的哈希值有效
????????????????self.nonce?=?cur_nonce??#?保持當(dāng)前nonce值
????????????????break??#?并退出
????????????else:
????????????????cur_nonce?+=?1??#?若當(dāng)前哈希值無效,更新nonce值,進(jìn)行加1操作

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件???????2282??2018-03-16?01:39??blockchain_2_代碼\block.py

?????文件???????1086??2018-02-28?13:44??blockchain_2_代碼\blockchain.py

?????文件???????2707??2018-03-16?13:17??blockchain_2_代碼\main.py

?????文件????????472??2018-03-15?23:38??blockchain_2_代碼\.idea\blockchain_1.iml

?????文件????????276??2018-02-28?12:51??blockchain_2_代碼\.idea\modules.xml

?????文件??????23220??2018-03-16?18:58??blockchain_2_代碼\.idea\workspace.xml

?????文件????????226??2018-03-15?23:38??blockchain_2_代碼\.idea\misc.xml

?????文件???????1210??2018-03-16?00:36??blockchain_2_代碼\__pycache__\blockchain.cpython-36.pyc

?????文件???????1727??2018-03-16?01:34??blockchain_2_代碼\__pycache__\merkletree.cpython-36.pyc

?????文件???????2011??2018-03-16?01:39??blockchain_2_代碼\__pycache__\block.cpython-36.pyc

?????文件???????2081??2018-03-16?01:34??blockchain_2_代碼\merkletree.py

?????目錄??????????0??2018-02-28?12:52??blockchain_2_代碼\.idea\inspectionProfiles

?????目錄??????????0??2018-02-28?15:21??blockchain_2_代碼\.idea

?????目錄??????????0??2018-02-28?13:46??blockchain_2_代碼\__pycache__

?????目錄??????????0??2018-02-28?14:01??blockchain_2_代碼

-----------?---------??----------?-----??----

????????????????37298????????????????????15


評論

共有 條評論