コード例 #1
0
    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)
コード例 #2
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)
コード例 #3
0
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     context.shell = None  # type: ignore
     context.network = None  # type: ignore
     context.chain_id = None  # type: ignore
     context.big_maps = {}  # type: ignore
     stack.items = []
     return cls()
コード例 #4
0
ファイル: program.py プロジェクト: kengkiat/pytezos
 def load(context: AbstractContext, with_code=False):
     parameter = ParameterSection.match(context.get_parameter_expr())
     storage = StorageSection.match(context.get_storage_expr())
     code = CodeSection.match(context.get_code_expr() if with_code else [])
     cls = type(MichelsonProgram.__name__, (MichelsonProgram,), dict(parameter=parameter,
                                                                     storage=storage,
                                                                     code=code))
     return cast(Type['MichelsonProgram'], cls)
コード例 #5
0
ファイル: big_map.py プロジェクト: multisme/pytezos
 def attach_context(self, context: AbstractContext, big_map_copy=False):
     assert self.context is None, f'context already attached'
     self.context = context
     if self.ptr is None:
         self.ptr = context.get_tmp_big_map_id()
     else:
         self.ptr = context.register_big_map(self.ptr, copy=big_map_copy)
     if context.tzt:  # type: ignore
         context.tzt_big_maps[self.ptr] = self  # type: ignore
コード例 #6
0
    def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext):
        literal: Type[MichelineLiteral]
        literal = cls.args[0]  # type: ignore

        network = literal.get_string()
        if network not in nodes:
            raise Exception(f'Expected one of {nodes}, got {network}')

        context.network = network  # type: ignore
        context.chain_id = context.shell.chains.main.chain_id()  # type: ignore
        context.big_maps = {}  # type: ignore
        stack.items = []
        return cls()
コード例 #7
0
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     source = context.get_source()
     res = AddressType.from_value(source)
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [], [res]))  # type: ignore
     return cls(stack_items_added=1)
コード例 #8
0
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     chain_id = context.get_chain_id()
     res = ChainIdType.from_value(chain_id)
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [], [res]))  # type: ignore
     return cls(stack_items_added=1)
コード例 #9
0
    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)
コード例 #10
0
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     amount = context.get_amount()
     res = MutezType.from_value(amount)
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [], [res]))  # type: ignore
     return cls(stack_items_added=1)
コード例 #11
0
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     now = context.get_now()
     res = TimestampType.from_value(now)
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [], [res]))  # type: ignore
     return cls(stack_items_added=1)
コード例 #12
0
ファイル: tezos.py プロジェクト: kengkiat/pytezos
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     sender = context.get_sender()
     res = AddressType.from_value(sender)
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [], [res]))
     return cls()
コード例 #13
0
ファイル: tezos.py プロジェクト: kengkiat/pytezos
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     balance = context.get_balance()
     res = MutezType.from_value(balance)
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [], [res]))
     return cls()
コード例 #14
0
ファイル: tezos.py プロジェクト: kengkiat/pytezos
 def execute(cls, stack: 'MichelsonStack', stdout: List[str],
             context: AbstractContext):
     address = cast(KeyHashType, stack.pop1())
     address.assert_type_equal(KeyHashType)
     res = NatType.from_value(context.get_voting_power(str(address)))
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [address], [res]))
     return cls()
コード例 #15
0
 def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext):
     item, amount = cast(Tuple[MichelsonType, NatType], stack.pop2())
     amount.assert_type_equal(NatType)
     address = context.get_self_address()
     res = TicketType.create(address, item, int(amount))
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [item, amount], [res]))
     return cls()
コード例 #16
0
    def execute(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 == 'AMOUNT':
            context.amount = literal.get_int()  # type: ignore
        elif res_type.prim == 'BALANCE':
            context.balance = literal.get_int()  # type: ignore
        elif res_type.prim == 'CHAIN_ID':
            context.chain_id = literal.get_string()  # type: ignore
        elif res_type.prim == 'SENDER':
            context.sender = literal.get_string()  # type: ignore
        elif res_type.prim == 'SOURCE':
            context.source = literal.get_string()  # type: ignore
        elif res_type.prim == 'NOW':
            try:
                context.now = literal.get_int()  # type: ignore
            # FIXME: Why does TypeError appear to be wrapped?
            except (TypeError, MichelsonRuntimeError):
                context.now = int(
                    strict_rfc3339.rfc3339_to_timestamp(
                        literal.get_string()))  # type: ignore
        else:
            raise ValueError(
                f'Expected one of {cls.allowed_primitives}, got {res_type.prim}'
            )
        return cls()
コード例 #17
0
def get_entrypoint_type(context: AbstractContext,
                        name: str,
                        address=None) -> Optional[Type[MichelsonType]]:
    expr = context.get_parameter_expr(address)
    if expr is None:
        return None
    parameter = ParameterSection.match(expr)
    entrypoints = parameter.list_entrypoints()
    assert name in entrypoints, f'unknown entrypoint {name}'
    return entrypoints[name]
コード例 #18
0
    def execute(cls, stack: MichelsonStack, stdout: List[str],
                context: AbstractContext):
        literal = cls.args[0]
        if issubclass(literal, (TrueLiteral, FalseLiteral)):
            debug = literal.literal
        else:
            debug = bool(literal.get_int())  # type: ignore

        context.debug = debug  # type: ignore
        return cls()
コード例 #19
0
ファイル: tezos.py プロジェクト: kengkiat/pytezos
 def execute(cls, stack: MichelsonStack, stdout: List[str],
             context: AbstractContext):
     entrypoint = next(iter(cls.field_names), 'default')
     self_type = get_entrypoint_type(context, entrypoint)
     assert self_type, f'parameter type is not defined'
     self_address = context.get_self_address()
     res_type = ContractType.create_type(args=[self_type])
     res = res_type.from_value(f'{self_address}%{entrypoint}')
     stack.push(res)
     stdout.append(format_stdout(cls.prim, [], [res]))
     return cls()
コード例 #20
0
ファイル: tezos.py プロジェクト: kengkiat/pytezos
    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()
コード例 #21
0
    def execute(cls, stack: MichelsonStack, stdout: List[str],
                context: AbstractContext):
        literal: Type[MichelineLiteral]
        literal = cls.args[0]  # type: ignore

        shell = literal.get_string()
        if shell not in nodes:
            raise Exception(f'Expected one of {nodes}, got {shell}')

        if shell.endswith('.pool'):
            shell = shell.split('.')[0]
            assert shell in nodes, f'unknown network {shell}'
            context.shell = ShellQuery(RpcMultiNode(
                nodes[shell]))  # type: ignore
        elif shell in nodes:
            context.shell = ShellQuery(RpcNode(
                nodes[shell][0]))  # type: ignore
        else:
            context.shell = ShellQuery(RpcNode(shell))  # type: ignore

        context.network = shell  # type: ignore
        context.chain_id = context.shell.chains.main.chain_id()  # type: ignore
        context.big_maps = {}  # type: ignore
        stack.items = []
        return cls()
コード例 #22
0
    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)
コード例 #23
0
    def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext):

        res_type: MichelsonType
        res_type = cls.args[0]  # type: ignore

        if res_type.prim == 'AMOUNT':
            context.amount = None  # type: ignore
        elif res_type.prim == 'BALANCE':
            context.balance = None  # type: ignore
        elif res_type.prim == 'CHAIN_ID':
            context.chain_id = None  # type: ignore
        elif res_type.prim == 'SENDER':
            context.sender = None  # type: ignore
        elif res_type.prim == 'SOURCE':
            context.source = None  # type: ignore
        elif res_type.prim == 'NOW':
            context.now = None  # type: ignore
        else:
            raise ValueError(f'Expected one of {cls.allowed_primitives}, got {res_type.prim}')
        return cls()
コード例 #24
0
ファイル: domain.py プロジェクト: multisme/pytezos
 def dummy(cls, context: AbstractContext) -> 'LambdaType':
     return cls(Micheline.match(context.get_dummy_lambda()))
コード例 #25
0
ファイル: sapling.py プロジェクト: kengkiat/pytezos
 def attach_context(self, context: AbstractContext, big_map_copy=False):
     self.context = context
     self.ptr = context.get_tmp_sapling_state_id()
コード例 #26
0
ファイル: parameter.py プロジェクト: baking-bad/pytezos
 def execute(cls, stack, stdout: List[str], context: AbstractContext):
     context.set_parameter_expr(cls.as_micheline_expr())
     stdout.append(f'parameter: updated')
コード例 #27
0
 def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext):
     literal = cls.args[0]
     debug = bool(literal.get_int())  # type: ignore
     context.debug = debug  # type: ignore
     return cls()
コード例 #28
0
ファイル: domain.py プロジェクト: multisme/pytezos
 def dummy(cls, context: AbstractContext) -> 'ChainIdType':
     return cls.from_value(context.get_dummy_chain_id())
コード例 #29
0
ファイル: tzt.py プロジェクト: yourlabsopensource/pytezos
 def execute(cls, stack, stdout: List[str], context: AbstractContext):
     context.set_self_expr(cls.as_micheline_expr())
     stdout.append('self: updated')
コード例 #30
0
ファイル: domain.py プロジェクト: multisme/pytezos
 def dummy(cls, context: AbstractContext) -> 'AddressType':
     return cls.from_value(context.get_dummy_address())