コード例 #1
0
def _tree_hash(node: SExp, precalculated: Set[bytes32]) -> bytes32:
    """
    Hash values in `precalculated` are presumed to have been hashed already.
    """
    if node.listp():
        left = _tree_hash(node.first(), precalculated)
        right = _tree_hash(node.rest(), precalculated)
        s = b"\2" + left + right
    else:
        atom = node.as_atom()
        if atom in precalculated:
            return bytes32(atom)
        s = b"\1" + atom
    return bytes32(std_hash(s))
コード例 #2
0
ファイル: utils.py プロジェクト: Chia-Network/clvm_tools
def ir_as_symbol(ir_sexp: SExp) -> typing.Optional[str]:
    if ir_sexp.listp() and ir_type(ir_sexp) == Type.SYMBOL:
        return bytes(ir_as_sexp(ir_sexp).as_atom()).decode("utf8")
    return None