当前位置: 首页>>代码示例>>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;未经允许,请勿转载。