Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    def execute(cls, stack: MichelsonStack, stdout: List[str],
                context: AbstractContext):
        delegate = cast(OptionType, stack.pop1())
        delegate.assert_type_equal(OptionType.create_type(args=[KeyHashType]))

        delegation = OperationType.delegation(
            source=context.get_self_address(),
            delegate=None if delegate.is_none() else str(delegate.get_some()))
        stack.push(delegation)
        stdout.append(format_stdout(cls.prim, [delegate], [delegation]))
        return cls()