def new_work(cls, header: str, block_num: int, boundary: str, pub_key="", signature="", timeout=120): start_time = datetime.utcnow() expire_time = start_time + timedelta(seconds=timeout) seed = ethash.block_num_to_seed(block_num) seed = crypto.bytes_to_hex_str_0x(seed) return cls(header=header, seed=seed, boundary=boundary, pub_key=pub_key, signature=signature, block_num=block_num, start_time=start_time, expire_time=expire_time)
def add_new_work(block_num, difficulty, timeout, node=0): print(f"Generate a work for block {block_num}, difficulty {difficulty}") header = crypto.rand_hex_str_0x(64) seed = crypto.bytes_to_hex_str_0x(ethash.block_num_to_seed(block_num)) boundary = crypto.bytes_to_hex_str_0x(ethash.difficulty_to_boundary_divided(difficulty)) print(f" header : {header}") print(f" seed : {seed}") print(f" boundary : {boundary}") pub_key = debug_data.nodes[node][0] print(f"save work, timeout = {timeout}, pub_key = {pub_key}") work = pow.PowWork.new_work(header, seed, boundary, pub_key=pub_key, signature="", timeout=timeout) work = work.save() if work: print(f"success, {work}") else: print(f"failed")