Example #1
0
 def wait_for_nodeid(self):
     pubkey, x, y = get_nodeid(self)
     self.key = eth_utils.encode_hex(pubkey)
     addr_tmp = bytearray(sha3(encode_int32(x) + encode_int32(y))[12:])
     addr_tmp[0] &= 0x0f
     addr_tmp[0] |= 0x10
     self.addr = addr_tmp
     self.log.debug("Get node {} nodeid {}".format(self.index, self.key))
Example #2
0
def create_block(parent_hash=default_config["GENESIS_PREVHASH"], height=0, timestamp=0, difficulty=TEST_DIFFICULTY, transactions=[],
                 gas_limit=3000000000, referee_hashes=[], author=default_config["GENESIS_COINBASE"], deferred_state_root=default_config["GENESIS_STATE_ROOT"], deferred_receipts_root=default_config["GENESIS_RECEIPTS_ROOT"]):
    tx_root = utils.sha3(rlp.encode(Transactions(transactions)))
    nonce = 0
    while True:
        header = BlockHeader(parent_hash=parent_hash, height=height, difficulty=difficulty, timestamp=timestamp,
                             author=author, transactions_root=tx_root, gas_limit=gas_limit,
                             referee_hashes=referee_hashes, nonce=nonce, deferred_state_root=deferred_state_root, deferred_receipts_root=deferred_receipts_root)
        if header.pow_decimal() * difficulty < HASH_MAX:
            break
        nonce += 1
    block = Block(block_header=header, transactions=transactions)
    return block
Example #3
0
 def __init__(self,
              parent_hash=default_config['GENESIS_PREVHASH'],
              height=0,
              timestamp=0,
              author=default_config['GENESIS_COINBASE'],
              transactions_root=trie.BLANK_ROOT,
              deferred_state_root=sha3(rlp.encode(trie.state_root())),
              deferred_receipts_root=trie.BLANK_ROOT,
              deferred_logs_bloom_hash=default_config['GENESIS_LOGS_BLOOM_HASH'],
              blame=0,
              difficulty=default_config['GENESIS_DIFFICULTY'],
              gas_limit=0,
              referee_hashes=[],
              adaptive=0,
              nonce=0):
     # at the beginning of a method, locals() is a dict of all arguments
     fields = {k: v for k, v in locals().items() if
               k not in ['self', '__class__']}
     self.block = None
     super(BlockHeader, self).__init__(**fields)
def create_block(
        parent_hash=default_config["GENESIS_PREVHASH"],
        height=0,
        timestamp=None,
        difficulty=TEST_DIFFICULTY,
        transactions=[],
        gas_limit=default_config["GENESIS_GAS_LIMIT"],
        referee_hashes=[],
        author=default_config["GENESIS_COINBASE"],
        deferred_state_root=default_config["GENESIS_STATE_ROOT"],
        deferred_receipts_root=default_config["GENESIS_RECEIPTS_ROOT"],
        deferred_logs_bloom_hash=default_config["GENESIS_LOGS_BLOOM_HASH"],
        adaptive=0):
    if timestamp is None:
        timestamp = int(time.time())
    tx_root = utils.sha3(rlp.encode(Transactions(transactions)))
    nonce = 0
    while True:
        header = BlockHeader(parent_hash=parent_hash,
                             height=height,
                             difficulty=difficulty,
                             timestamp=timestamp,
                             author=author,
                             transactions_root=tx_root,
                             gas_limit=gas_limit,
                             referee_hashes=referee_hashes,
                             nonce=nonce,
                             deferred_state_root=deferred_state_root,
                             deferred_receipts_root=deferred_receipts_root,
                             deferred_logs_bloom_hash=deferred_logs_bloom_hash,
                             adaptive=adaptive)
        if header.pow_decimal() * difficulty < HASH_MAX:
            break
        nonce += 1
    block = Block(block_header=header, transactions=transactions)
    return block
Example #5
0
 def wait_for_nodeid(self):
     pubkey, x, y = get_nodeid(self)
     self.key = eth_utils.encode_hex(pubkey)
     self.addr = sha3(encode_int32(x) + encode_int32(y))[12:]
     self.log.debug("Get node {} nodeid {}".format(self.index, self.key))
Example #6
0
 def pow_decimal(self):
     return bytes_to_int(sha3(rlp.encode([self.problem_hash(),
                                          self.nonce])))
Example #7
0
 def problem_hash(self):
     return sha3(rlp.encode(self.without_nonce()))
Example #8
0
 def hash(self):
     return sha3(rlp.encode(self.rlp_part()))
Example #9
0
 def pow_decimal(self):
     tmp = sha3(rlp.encode([self.problem_hash(), self.nonce]))
     buf = []
     for i in range(0, 32):
         buf.append(tmp[i] ^ self.problem_hash()[i])
     return bytes_to_int(sha3(bytes(buf)))
Example #10
0
 def hash(self):
     return sha3(rlp.encode(self))