コード例 #1
0
def parse_aggsig(args: SExp) -> List[bytes]:
    pubkey = args.first().atom
    args = args.rest()
    message = args.first().atom
    if len(pubkey) != 48:
        raise ValidationError(Err.INVALID_CONDITION)
    if len(message) > 1024:
        raise ValidationError(Err.INVALID_CONDITION)
    return [pubkey, message]
コード例 #2
0
def parse_create_coin(args: SExp, safe_mode: bool) -> List[bytes]:
    puzzle_hash = args.first().atom
    args = args.rest()
    if len(puzzle_hash) != 32:
        raise ValidationError(Err.INVALID_CONDITION)
    amount_int = sanitize_int(args.first(), safe_mode)
    if amount_int >= 2**64:
        raise ValidationError(Err.COIN_AMOUNT_EXCEEDS_MAXIMUM)
    if amount_int < 0:
        raise ValidationError(Err.COIN_AMOUNT_NEGATIVE)
    # note that this may change the representation of amount. If the original
    # buffer had redundant leading zeroes, they will be stripped
    return [puzzle_hash, int_to_bytes(amount_int)]
コード例 #3
0
def parse_aggsig(args: SExp) -> List[bytes]:
    pubkey = args.first().atom
    args = args.rest()
    message = args.first().atom
    if len(pubkey) != 48:
        raise ValidationError(Err.INVALID_CONDITION)
    if len(message) > 1024:
        raise ValidationError(Err.INVALID_CONDITION)
    # agg sig conditions only take 2 parameters
    args = args.rest()
    # the list is terminated by having a right-element that's not another pair,
    # just like as_atom_list() (see chia/types/blockchain_format/program.py)
    if args.pair is not None:
        raise ValidationError(Err.INVALID_CONDITION)
    return [pubkey, message]
コード例 #4
0
def parse_fee(args: SExp, safe_mode: bool) -> List[bytes]:
    fee_int = sanitize_int(args.first(), safe_mode)
    if fee_int >= 2**64 or fee_int < 0:
        raise ValidationError(Err.RESERVE_FEE_CONDITION_FAILED)
    # note that this may change the representation of the fee. If the original
    # buffer had redundant leading zeroes, they will be stripped
    return [int_to_bytes(fee_int)]
コード例 #5
0
ファイル: utils.py プロジェクト: Chia-Network/clvm_tools
def ir_offset(ir_sexp: SExp) -> int:
    the_offset = ir_sexp.first()
    if the_offset.listp():
        the_offset = the_offset.rest().as_atom()
    else:
        the_offset = b"\xff"
    return casts.int_from_bytes(the_offset)
コード例 #6
0
def parse_amount(args: SExp, safe_mode: bool) -> List[bytes]:
    amount_int = sanitize_int(args.first(), safe_mode)
    if amount_int < 0:
        raise ValidationError(Err.ASSERT_MY_AMOUNT_FAILED)
    if amount_int >= 2**64:
        raise ValidationError(Err.ASSERT_MY_AMOUNT_FAILED)
    # note that this may change the representation of amount. If the original
    # buffer had redundant leading zeroes, they will be stripped
    return [int_to_bytes(amount_int)]
コード例 #7
0
def parse_height(args: SExp, safe_mode: bool, error_code: Err) -> Optional[List[bytes]]:
    height_int = sanitize_int(args.first(), safe_mode)
    # this condition is inherently satisified, there is no need to keep it
    if height_int < 0:
        return None
    if height_int >= 2 ** 32:
        raise ValidationError(error_code)
    # note that this may change the representation of the height. If the original
    # buffer had redundant leading zeroes, they will be stripped
    return [int_to_bytes(height_int)]
コード例 #8
0
def parse_condition(cond: SExp, safe_mode: bool) -> Tuple[int, Optional[ConditionWithArgs]]:
    condition = cond.first().as_atom()
    if condition in CONDITION_OPCODES:
        opcode: ConditionOpcode = ConditionOpcode(condition)
        cost, args = parse_condition_args(cond.rest(), opcode, safe_mode)
        cvl = ConditionWithArgs(opcode, args) if args is not None else None
    elif not safe_mode:
        opcode = ConditionOpcode.UNKNOWN
        cvl = ConditionWithArgs(opcode, cond.rest().as_atom_list())
        cost = 0
    else:
        raise ValidationError(Err.INVALID_CONDITION)
    return cost, cvl
コード例 #9
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))
コード例 #10
0
def parse_condition(
        cond: SExp,
        safe_mode: bool) -> Tuple[int, Optional[ConditionWithArgs]]:
    condition = cond.first().as_atom()
    if condition in CONDITION_OPCODES:
        opcode: ConditionOpcode = ConditionOpcode(condition)
        cost, args = parse_condition_args(cond.rest(), opcode, safe_mode)
        cvl = ConditionWithArgs(opcode, args) if args is not None else None
    elif not safe_mode:
        # we don't need to save unknown conditions. We can't do anything with them anyway
        # safe_mode just tells us whether we can tolerate them or not
        return 0, None
    else:
        raise ValidationError(Err.INVALID_CONDITION)
    return cost, cvl
コード例 #11
0
def parse_announcement(args: SExp) -> List[bytes]:
    msg = args.first().atom
    if len(msg) > 1024:
        raise ValidationError(Err.INVALID_CONDITION)
    return [msg]
コード例 #12
0
def parse_hash(args: SExp, error_code: Err) -> List[bytes]:
    h = args.first().atom
    if len(h) != 32:
        raise ValidationError(error_code)
    return [h]
コード例 #13
0
ファイル: utils.py プロジェクト: Chia-Network/clvm_tools
def ir_type(ir_sexp: SExp) -> int:
    the_type = ir_sexp.first()
    if the_type.listp():
        the_type = the_type.first()

    return casts.int_from_bytes(the_type.as_atom())