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 end(self, stack: MichelsonStack, stdout: List[str], output_mode='readable') \ -> Tuple[List[dict], Any, List[dict], PairType]: res = cast(PairType, stack.pop1()) assert len(stack) == 0, f'stack is not empty: {repr(stack)}' res.assert_type_equal(PairType.create_type(args=[ ListType.create_type(args=[OperationType]), self.storage.args[0] ]), message='list of operations + resulting storage') operations = [op.content for op in res.items[0]] lazy_diff = [] storage = res.items[1].aggregate_lazy_diff(lazy_diff).to_micheline_value(mode=output_mode) stdout.append(format_stdout(f'END %{self.entrypoint}', [res], [])) return operations, storage, lazy_diff, res
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): points = cast(ListType, stack.pop1()) points.assert_type_equal( ListType.create_type(args=[ PairType.create_type(args=[BLS12_381_G1Type, BLS12_381_G2Type]) ])) prod = FQ12.one() for pair in points: g1, g2 = tuple( iter(pair)) # type: BLS12_381_G1Type, BLS12_381_G2Type prod = prod * bls12_381.pairing(g2.to_point(), g1.to_point()) res = BoolType.from_value(FQ12.one() == prod) stack.push(res) stdout.append(format_stdout(cls.prim, [points], [res])) return cls()
def end(self, stack: MichelsonStack, stdout: List[str], output_mode='readable' ) -> Tuple[List[dict], Any, List[dict], PairType]: """Finish contract execution""" res = cast(PairType, stack.pop1()) if len(stack): raise Exception(f'Stack is not empty: {repr(stack)}') res.assert_type_equal( PairType.create_type(args=[ ListType.create_type(args=[OperationType]), self.storage.args[0] ], ), message='list of operations + resulting storage', ) operations = [op.content for op in res.items[0]] # type: ignore lazy_diff = [] # type: ignore storage = res.items[1].aggregate_lazy_diff( lazy_diff).to_micheline_value(mode=output_mode) stdout.append(format_stdout(f'END %{self.entrypoint}', [res], [])) return operations, storage, lazy_diff, res
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): # FIXME: MichelsonProgram copypaste debug, context.debug = context.debug, False # type: ignore res = cast(PairType, stack.pop1()) if len(stack): raise Exception(f'Stack is not empty: {stack}') res.assert_type_equal( PairType.create_type( args=[ ListType.create_type(args=[OperationType]), StorageSection.match(context.get_storage_expr()).args[0] ], ), message='list of operations + resulting storage', ) operations = ListType(items=[op for op in res.items[0]]) # type: ignore lazy_diff = [] # type: ignore storage = res.items[1].aggregate_lazy_diff(lazy_diff) stdout.append(format_stdout(f'END %default', [res], [])) result = PairType.from_comb([operations, storage]) context.debug = debug # type: ignore return cls(lazy_diff=lazy_diff, result=result)