def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): pair = cast(PairType, stack.pop1()) pair.assert_type_in(PairType) left, right = tuple(pair) assert isinstance( left, TicketType), f'expected ticket on the left, got {left.prim}' assert isinstance( right, TicketType), f'expected ticket on the right, got {right.prim}' res = TicketType.join(left, right) if res is None: res = OptionType.none(type(left)) # type: ignore else: res = OptionType.from_some(res) # type: ignore stack.push(res) # type: ignore stdout.append(format_stdout(cls.prim, [pair], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): key, val, src = cast( Tuple[MichelsonType, Union[OptionType, BoolType], Union[MapType, BigMapType, SetType]], stack.pop3()) val.assert_type_in(OptionType, BoolType) if isinstance(val, BoolType): src.assert_type_in(SetType) dst = src.add(key) if bool(val) else src.remove( key) # type: ignore else: src.assert_type_in(MapType, BigMapType) _, dst = src.update( key, None if val.is_none() else val.get_some()) # type: ignore stack.push(dst) stdout.append(format_stdout(cls.prim, [key, val, src], [dst])) # type: ignore return cls(stack_items_added=1)
def push(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): res_type: MichelsonType literal: Type[MichelineLiteral] res_type, literal = cls.args # type: ignore if res_type.prim == 'big_map': if isinstance(literal.literal, int): res = context.tzt_big_maps[literal.literal] # type: ignore else: res = res_type.from_literal(literal) res.attach_context(context) elif res_type.is_pushable(): res = res_type.from_literal(literal) else: raise Exception( f'`{res_type.prim}` is neither pushable nor big_map') stack.push(res) stdout.append(format_stdout(cls.prim, [], [res])) # type: ignore
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): ticket, amounts = cast(Tuple[TicketType, PairType], stack.pop2()) ticket.assert_type_in(TicketType) amounts.assert_type_in(PairType) a, b = tuple(amounts) # type: NatType, NatType # type: ignore a.assert_type_equal(NatType) b.assert_type_equal(NatType) res = ticket.split(int(a), int(b)) if res is None: res = OptionType.none( PairType.create_type( args=[type(ticket), type(ticket)])) # type: ignore else: res = OptionType.from_some(PairType.from_comb( list(res))) # type: ignore stack.push(res) # type: ignore stdout.append(format_stdout(cls.prim, [ticket, amounts], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast(Tuple[Union[BoolType, NatType, IntType], ...], stack.pop2()) res_type, convert = dispatch_types(type(a), type(b), mapping={ (BoolType, BoolType): (BoolType, bool), (NatType, NatType): (NatType, int), (NatType, IntType): (NatType, int), (IntType, NatType): (NatType, int), }) res = res_type.from_value(convert(a) & convert(b)) stack.push(res) stdout.append(format_stdout(cls.prim, [a, b], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): entrypoint = next(iter(cls.field_names), 'default') address = cast(AddressType, stack.pop1()) address.assert_type_in(AddressType) entrypoint_type = get_entrypoint_type(context, entrypoint, address=str(address)) contract_type = ContractType.create_type(args=cls.args) try: if entrypoint_type is None: stdout.append( f'{cls.prim}: skip type checking for {str(address)}') else: entrypoint_type.assert_type_equal(cls.args[0]) res = OptionType.from_some( contract_type.from_value(f'{str(address)}%{entrypoint}')) except AssertionError: res = OptionType.none(contract_type) stack.push(res) stdout.append(format_stdout(cls.prim, [address], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast( Tuple[Union[IntType, NatType, MutezType, TimestampType], ...], stack.pop2()) res_type, = dispatch_types( type(a), type(b), mapping={ # type: ignore (NatType, NatType): (IntType, ), (NatType, IntType): (IntType, ), (IntType, NatType): (IntType, ), (IntType, IntType): (IntType, ), (TimestampType, IntType): (TimestampType, ), (TimestampType, TimestampType): (IntType, ), (MutezType, MutezType): (MutezType, ) } ) # type: Union[Type[IntType], Type[NatType], Type[TimestampType], Type[MutezType]] res = res_type.from_value(int(a) - int(b)) stack.push(res) stdout.append(format_stdout(cls.prim, [a, b], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): # FIXME: MichelsonProgram copypaste parameter_literal, storage_literal = cls.args # type: ignore parameter_type_expr = context.get_parameter_expr() storage_type_expr = context.get_storage_expr() if parameter_type_expr is None: raise Exception('parameter type is not initialized') if storage_type_expr is None: raise Exception('storage type is not initialized') parameter_type = ParameterSection.match(parameter_type_expr) storage_type = StorageSection.match(storage_type_expr) parameter = parameter_type.from_micheline_value(parameter_literal.as_micheline_expr()) storage = storage_type.from_micheline_value(storage_literal.as_micheline_expr()) parameter.attach_context(context) storage.attach_context(context) res = PairType.from_comb([parameter.item, storage.item]) stack.items = [] stack.push(res) stdout.append(format_stdout(f'BEGIN %default', [], [res])) return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast( Union[IntType, NatType, BLS12_381_FrType, BLS12_381_G1Type, BLS12_381_G2Type], stack.pop1()) res_type, = dispatch_types(type(a), mapping={ (IntType, ): (IntType, ), (NatType, ): (IntType, ), (BLS12_381_FrType, ): (BLS12_381_FrType, ), (BLS12_381_G1Type, ): (BLS12_381_G1Type, ), (BLS12_381_G2Type, ): (BLS12_381_G2Type, ) }) if issubclass(res_type, IntType): res = IntType.from_value(-int(a)) else: res = res_type.from_point(bls12_381.neg(a.to_point())) stack.push(res) stdout.append(format_stdout(cls.prim, [a], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast( Tuple[Union[IntType, NatType, MutezType, BLS12_381_FrType, BLS12_381_G1Type, BLS12_381_G2Type], ...], stack.pop2()) res_type, = dispatch_types( type(a), type(b), mapping={ (NatType, NatType): (NatType, ), (NatType, IntType): (IntType, ), (IntType, NatType): (IntType, ), (IntType, IntType): (IntType, ), (MutezType, NatType): (MutezType, ), (NatType, MutezType): (MutezType, ), (NatType, BLS12_381_FrType): (BLS12_381_FrType, ), (IntType, BLS12_381_FrType): (BLS12_381_FrType, ), (BLS12_381_FrType, NatType): (BLS12_381_FrType, ), (BLS12_381_FrType, IntType): (BLS12_381_FrType, ), (BLS12_381_FrType, BLS12_381_FrType): (BLS12_381_FrType, ), (BLS12_381_G1Type, BLS12_381_FrType): (BLS12_381_G1Type, ), (BLS12_381_G2Type, BLS12_381_FrType): (BLS12_381_G2Type, ), }) res_type = cast( Union[Type[IntType], Type[NatType], Type[TimestampType], Type[MutezType], Type[BLS12_381_FrType], Type[BLS12_381_G1Type], Type[BLS12_381_G2Type]], res_type) if issubclass(res_type, IntType): res = res_type.from_value(int(a) * int(b)) # type: ignore else: res = res_type.from_point(bls12_381.multiply( a.to_point(), int(b))) # type: ignore stack.push(res) stdout.append(format_stdout(cls.prim, [a, b], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): res = UnitType() stack.push(res) stdout.append(format_stdout(cls.prim, [], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = stack.pop2() stack.push(a) stack.push(b) stdout.append(format_stdout(cls.prim, [a, b], [b, a])) # type: ignore return cls(stack_items_added=2)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): res = SetType.empty(item_type=cls.args[0]) # type: ignore stack.push(res) stdout.append(format_stdout(cls.prim, [], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): some = stack.pop1() res = OptionType.from_some(some) stack.push(res) stdout.append(format_stdout(cls.prim, [some], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): left, right = stack.pop2() res = PairType.from_comb([left, right]) stack.push(res) stdout.append(format_stdout(cls.prim, [left, right], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): res = stack.peek().duplicate() stack.push(res) stdout.append(format_stdout(cls.prim, [res], [res, res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): res = MapType.empty(key_type=cls.args[0], val_type=cls.args[1]) stack.push(res) stdout.append(format_stdout(cls.prim, [], [res])) return cls()
def execute_cxr(prim: str, stack: MichelsonStack, stdout: List[str], idx: int): pair = cast(PairType, stack.pop1()) pair.assert_type_in(PairType) res = pair.items[idx] stack.push(res) stdout.append(format_stdout(prim, [pair], [res]))
def begin(self, stack: MichelsonStack, stdout: List[str], context: AbstractContext): self.parameter_value.attach_context(context) self.storage_value.attach_context(context) res = PairType.from_comb([self.parameter_value.item, self.storage_value.item]) stack.push(res) stdout.append(format_stdout(f'BEGIN %{self.entrypoint}', [], [res]))
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): lambda_type = LambdaType.create_type(args=cls.args[:2]) res = lambda_type(cls.args[2]) # type: ignore stack.push(res) stdout.append(format_stdout(cls.prim, [], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): right = stack.pop1() res = OrType.from_right(right, cls.args[0]) stack.push(res) stdout.append(format_stdout(cls.prim, [right], [res])) return cls()