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])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a, b = cast( Tuple[Union[IntType, NatType, MutezType, TimestampType], ...], stack.pop2()) q_type, r_type = dispatch_types( type(a), type(b), mapping={ # type: ignore (NatType, NatType): (NatType, NatType), (NatType, IntType): (IntType, NatType), (IntType, NatType): (IntType, NatType), (IntType, IntType): (IntType, NatType), (MutezType, NatType): (MutezType, MutezType), (MutezType, MutezType): (NatType, MutezType) } ) # type: Union[Type[IntType], Type[NatType], Type[TimestampType], Type[MutezType]] if int(b) == 0: res = OptionType.none(PairType.create_type(args=[q_type, r_type])) else: q, r = divmod(int(a), int(b)) if r < 0: r += abs(int(b)) q += 1 items = [q_type.from_value(q), r_type.from_value(r)] res = OptionType.from_some(PairType.from_comb(items)) 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): key, val, src = cast(Tuple[MichelsonType, OptionType, Union[MapType, BigMapType]], stack.pop3()) src.assert_type_in(MapType, BigMapType) prev_val, dst = src.update(key, None if val.is_none() else val.get_some()) res = OptionType.none(src.args[1]) if prev_val is None else OptionType.from_some(prev_val) stack.push(dst) stack.push(res) stdout.append(format_stdout(cls.prim, [key, val, src], [res, dst])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast(IntType, stack.pop1()) a.assert_type_equal(IntType) if int(a) >= 0: res = OptionType.from_some(NatType.from_value(int(a))) else: res = OptionType.none(NatType) stack.push(res) stdout.append(format_stdout(cls.prim, [a], [res])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): key, src = cast(Tuple[MichelsonType, Union[MapType, BigMapType]], stack.pop2()) src.assert_type_in(MapType, BigMapType) val = src.get(key, dup=True) if val is None: res = OptionType.none(src.args[0]) else: res = OptionType.from_some(val) stack.push(res) stdout.append(format_stdout(cls.prim, [key, src], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): a = cast(BytesType, stack.pop1()) a.assert_type_equal(BytesType) try: some = cls.args[0].unpack(bytes(a)) res = OptionType.from_some(some) except Exception as e: stdout.append(f'{cls.prim}: {e}') res = OptionType.none(cls.args[0]) stack.push(res) stdout.append(format_stdout(cls.prim, [a], [res])) return cls()
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)) else: res = OptionType.from_some(res) stack.push(res) stdout.append(format_stdout(cls.prim, [pair], [res])) return cls()
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 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)])) else: res = OptionType.from_some(PairType.from_comb(list(res))) stack.push(res) stdout.append(format_stdout(cls.prim, [ticket, amounts], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): offset, length, s = cast( Tuple[NatType, NatType, Union[StringType, BytesType]], stack.pop3()) offset.assert_type_equal(NatType) length.assert_type_equal(NatType) s.assert_type_in(StringType, BytesType) start, stop = int(offset), int(offset) + int(length) if 0 <= start <= stop <= len(s): res = OptionType.from_some(s[start:stop]) else: res = OptionType.none(type(s)) stack.push(res) stdout.append(format_stdout(cls.prim, [offset, length, s], [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()