def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): parameter, amount, destination = cast( Tuple[MichelsonType, MutezType, ContractType], stack.pop3()) amount.assert_type_equal(MutezType) assert isinstance( destination, ContractType), f'expected contract, got {destination.prim}' parameter.assert_type_equal(destination.args[0]) ep_type = get_entrypoint_type(context, destination.get_entrypoint(), address=destination.get_address()) if ep_type: parameter.assert_type_equal( ep_type, message='destination contract parameter') transaction = OperationType.transaction( source=context.get_self_address(), destination=destination.get_address(), amount=int(amount), entrypoint=destination.get_entrypoint(), parameter=parameter) stack.push(transaction) stdout.append( format_stdout(cls.prim, [parameter, amount, destination], [transaction])) # type: ignore return cls(stack_items_added=1)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): sequence = cast(MichelineSequence, cls.args[0]) assert len(sequence.args ) == 3, f'expected 3 sections, got {len(sequence.args)}' assert {arg.prim for arg in sequence.args} == {'parameter', 'storage', 'code'}, f'unexpected sections' storage_type = cast( Type[MichelsonType], next(arg.args[0] for arg in sequence.args if arg.prim == 'storage')) delegate, amount, initial_storage = cast( Tuple[OptionType, MutezType, MichelsonType], stack.pop3()) delegate.assert_type_equal(OptionType.create_type(args=[KeyHashType])) amount.assert_type_equal(MutezType) initial_storage.assert_type_equal(storage_type) originated_address = AddressType.from_value( context.get_originated_address()) context.spend_balance(int(amount)) origination = OperationType.origination( source=context.get_self_address(), script=cls.args[0], # type: ignore storage=initial_storage, balance=int(amount), delegate=None if delegate.is_none() else str(delegate.get_some())) stack.push(originated_address) stack.push(origination) stdout.append( format_stdout(cls.prim, [delegate, amount, initial_storage], [origination, originated_address])) # type: ignore return cls(stack_items_added=2)
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) else: src.assert_type_in(MapType, BigMapType) _, dst = src.update(key, None if val.is_none() else val.get_some()) stack.push(dst) stdout.append(format_stdout(cls.prim, [key, val, src], [dst])) 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): 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])) # type: ignore return cls(stack_items_added=2)
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): pk, sig, msg = cast(Tuple[KeyType, SignatureType, BytesType], stack.pop3()) pk.assert_type_equal(KeyType) sig.assert_type_equal(SignatureType) msg.assert_type_equal(BytesType) key = Key.from_encoded_key(str(pk)) try: key.verify(signature=str(sig), message=bytes(msg)) except ValueError: res = BoolType(False) else: res = BoolType(True) stack.push(res) stdout.append(format_stdout(cls.prim, [pk, sig, msg], [res])) return cls()