當前位置: 首頁>>代碼示例>>Python>>正文


Python Uint256.from_bytestr方法代碼示例

本文整理匯總了Python中coinpy.model.protocol.structures.uint256.Uint256.from_bytestr方法的典型用法代碼示例。如果您正苦於以下問題:Python Uint256.from_bytestr方法的具體用法?Python Uint256.from_bytestr怎麽用?Python Uint256.from_bytestr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在coinpy.model.protocol.structures.uint256.Uint256的用法示例。


在下文中一共展示了Uint256.from_bytestr方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: hash_tx

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
def hash_tx(tx):
    if tx.hash:
        return tx.hash
    if not tx.rawdata:
        tx.rawdata = TX_SERIALIZE.serialize(tx)
    tx.hash = Uint256.from_bytestr(doublesha256(tx.rawdata))
    return tx.hash
開發者ID:sirk390,項目名稱:coinpy,代碼行數:9,代碼來源:hash_tx.py

示例2: hash_blockheader

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
def hash_blockheader(blockheader):
    if blockheader.hash:
        return blockheader.hash
    if not blockheader.rawdata:
        blockheader.rawdata = BLOCK_SERIALIZE.serialize(blockheader)
    blockheader.hash = Uint256.from_bytestr(doublesha256(blockheader.rawdata))
    return blockheader.hash
開發者ID:sirk390,項目名稱:coinpy,代碼行數:9,代碼來源:hash_block.py

示例3: check_merkle_branch

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
def check_merkle_branch(txhash, merkle_branch, index_tx):
    """Return True if the merkle branch is valid for txhash and index_tx.
       
       Attributes:
           txhash(Uint256): Hash of a Transaction
           merkle_branch(list of Uint256): Merkle Branch
           index_tx(int): Index of the transaction in the block.
        
    """
    hash = txhash.get_bytestr()
    index = index_tx
    otherside_branch, merkle_root = merkle_branch[:-1], merkle_branch[-1]
    for otherside in otherside_branch:
        if index & 1:
            hash = double_sha256_2_input(otherside.get_bytestr(), hash)
        else:
            hash = double_sha256_2_input(hash, otherside.get_bytestr())
        index = index >> 1
        print "u", Uint256.from_bytestr(hash)           
    return (Uint256.from_bytestr(hash) == merkle_root)
開發者ID:sirk390,項目名稱:coinpy,代碼行數:22,代碼來源:merkle_tree.py

示例4: get_merkle_branch

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
def get_merkle_branch(block, index_tx):
    """Get the merkle branch of a transaction.
    
    block:    block that contains the transaction
    index_tx: index of the transaction in the block
    
    Return value: [list of Uint256] 
    The first element is a hash of a transaction at the bottom of the merkle tree.  
    The last element is the merkle root.
    
    The algorithm uses XOR 1, to select the opposite element at each level.
    """
    merkle_branch = []
    merkle_tree = get_merkle_tree(block)
    for level in merkle_tree:
        merkle_branch.append(Uint256.from_bytestr(level[min(index_tx^1, len(level)-1)]))
        index_tx = index_tx >> 1
    return (merkle_branch)
開發者ID:sirk390,項目名稱:coinpy,代碼行數:20,代碼來源:merkle_tree.py

示例5: mine_block

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
 def mine_block(hash_prev,
                block_height,
                time_source,
                difficulty_bits,
                transactions, 
                coinbase_txout_list,
                coinbase_flags=["/P2SH/"],
                nonce_changer=default_nonce_changer):
     template = BlockheaderTemplate(hash_prev, 
                                    block_height,
                                    coinbase_txout_list, 
                                    transactions, 
                                    time_source.get_time(), 
                                    difficulty_bits,
                                    coinbase_flags=coinbase_flags)
     difficulty_target = uint256_difficulty(difficulty_bits)
     hash_found = False
     while not hash_found:
         hash = Uint256.from_bytestr(doublesha256(template.get_serialized()))
         if (hash <= difficulty_target):
             hash_found = True
         else:
             nonce_changer(template)
     return (template.get_block(), template)
開發者ID:sirk390,項目名稱:coinpy,代碼行數:26,代碼來源:mining.py

示例6: get_hashbestchain

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
 def get_hashbestchain(self):
     return Uint256.from_bytestr(self.db.get("\x0dhashBestChain", txn=self.dbtxn))
開發者ID:sirk390,項目名稱:coinpy,代碼行數:4,代碼來源:indexdb.py

示例7: deserialize

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
 def deserialize(self, data, cursor=0):
     if (len(data) - cursor) < 32:
         raise MissingDataException("%s: Not enought data for uint256" % (self.desc))
     bytestr, = struct.unpack_from("32s", data, cursor)
     return (Uint256.from_bytestr(bytestr), cursor + 32)
開發者ID:sirk390,項目名稱:coinpy,代碼行數:7,代碼來源:s11n_uint256.py

示例8: compute_merkle_root

# 需要導入模塊: from coinpy.model.protocol.structures.uint256 import Uint256 [as 別名]
# 或者: from coinpy.model.protocol.structures.uint256.Uint256 import from_bytestr [as 別名]
def compute_merkle_root(transactions):
    hashes = [hash_tx(tx).get_bytestr() for tx in transactions]
    while (len(hashes) != 1):
        hashes = next_merkle_level(hashes)
    return (Uint256.from_bytestr(hashes[0]))
開發者ID:sirk390,項目名稱:coinpy,代碼行數:7,代碼來源:merkle_tree.py


注:本文中的coinpy.model.protocol.structures.uint256.Uint256.from_bytestr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。