コード例 #1
0
def create_block(signed_transactions: List["transaction_model.TransactionModel"]) -> l1_block_model.L1BlockModel:
    # Get prior block hash and ID, and create new block with the fixated transactions
    previous_proof = block_dao.get_last_block_proof()
    block = l1_block_model.new_from_full_transactions(signed_transactions, previous_proof.get("block_id") or "", previous_proof.get("proof") or "")
    _log.info(f"[L1] Next block created. Previous block hash: {previous_proof.get('proof')}, previous block ID: {previous_proof.get('block_id')}")

    _log.info("[L1] Signing block")
    sign_block(block)

    return block
コード例 #2
0
def get_next_block_info() -> Tuple[int, str]:
    previous = block_dao.get_last_block_proof()
    _log.info(f"[L4] Got previous block information: {previous}")
    if not previous:
        # Throws an exception if sanity check fails
        shared_functions.sanity_check_empty_chain()
        block_id = 1
        prev_proof = ""
    else:
        block_id = int(previous["block_id"]) + 1
        prev_proof = previous["proof"]
        _log.info(f"[L4] Got previous block id, incremented current block id to {block_id}")

    return block_id, prev_proof
コード例 #3
0
def get_next_block_info() -> Tuple[int, str]:
    _log.info("[L2] Creating L2 block")
    previous_proof_dict = block_dao.get_last_block_proof()
    _log.info(f"[L2] Got previous block proof: {previous_proof_dict}")

    if not previous_proof_dict:
        # Throws an exception if sanity check fails
        shared_functions.sanity_check_empty_chain()
        block_id = 1
        prev_proof = ""
    else:
        block_id = int(previous_proof_dict["block_id"]) + 1
        prev_proof = previous_proof_dict["proof"]
        _log.info(
            f"[L2] Got previous block id, incremented current block id to {block_id}"
        )

    return block_id, prev_proof