Пример #1
0
    def bulk(self, *operations: Union[OperationGroup, ContractCall]) -> OperationGroup:
        """ Batch multiple operations and contract calls in a single operation group

        :param operations: a tuple of operations or contract calls
        :rtype: OperationGroup
        """
        contents = []
        reset_fields = {
            'pkh': '',
            'source': '',
            'delegate': '',
            'counter': '0',
            'secret': '',
            'period': '0',
            'public_key': '',
            'fee': '0',
            'gas_limit': '0',
            'storage_limit': '0'
        }
        for opg in operations:
            if isinstance(opg, ContractCall):
                opg = opg.as_transaction()
            else:
                assert isinstance(opg, OperationGroup), f'expected OperationGroup or ContractCall, got {opg}'
            for content in opg.contents:
                contents.append({k: reset_fields.get(k, v) for k, v in content.items()})
        return OperationGroup(context=self._spawn_context(), contents=contents)
Пример #2
0
    def operation(self, content: dict) -> OperationGroup:
        """ Create an operation group with single content.

        :param content: Operation body (depending on `kind`)
        :rtype: OperationGroup
        """
        return OperationGroup(context=self._spawn_context(), contents=[content])
Пример #3
0
 def operation(self, content: dict) -> OperationGroup:
     """
     Create an operation group with single content
     :param content: Operation body (depending on `kind`)
     :return: OperationGroup
     """
     return OperationGroup(contents=[content],
                           shell=self.shell,
                           key=self.key)
Пример #4
0
    def as_transaction(self) -> OperationGroup:
        """ Get operation content

        :rtype: OperationGroup
        """
        return OperationGroup(context=self._spawn_context()) \
            .transaction(destination=self.address,
                         amount=self.amount,
                         parameters=self.parameters)
Пример #5
0
 def operation_group(self) -> OperationGroup:
     """
     Show generated operation group.
     :return: OperationGroup
     """
     return OperationGroup(shell=self.shell, key=self.key) \
         .transaction(destination=self.address,
                      amount=self.amount,
                      parameters=self.parameters) \
         .fill()
Пример #6
0
    def operation_group(self, protocol=None, branch=None, contents=None, signature=None) -> OperationGroup:
        """ Create new operation group (multiple contents).
        You can leave all fields empty in order to create an empty operation group.

        :param protocol: Leave None for autocomplete, unless you know what you are doing
        :param branch: Leave None for autocomplete
        :param contents: List of operation contents (optional)
        :param signature: Can be set later
        :rtype: OperationGroup
        """
        return OperationGroup(
            context=self._spawn_context(),
            protocol=protocol,
            branch=branch,
            contents=contents,
            signature=signature
        )
Пример #7
0
    def originate(self,
                  initial_storage=None,
                  mode: Optional[str] = None,
                  balance: Union[int, Decimal] = 0,
                  delegate: Optional[str] = None) -> OperationGroup:
        """ Create an origination operation

        :param initial_storage: Python object, leave None to generate default
        :param mode: whether to use `readable` or `optimized` (or `legacy_optimized`) encoding for initial storage
        :param balance: initial balance
        :param delegate: initial delegator
        :rtype: OperationGroup
        """
        return OperationGroup(context=self._spawn_context()) \
            .origination(script=self.script(initial_storage, mode=mode),
                         balance=balance,
                         delegate=delegate)
Пример #8
0
    def operation_group(self, protocol=None, branch=None, contents=None, signature=None) -> OperationGroup:
        """ Create new operation group (multiple contents).
        You can leave all fields empty in order to create an empty operation group.

        :param protocol: Leave None for autocomplete, otherwise you know what to do
        :param branch: Leave None for autocomplete
        :param contents: List of operation contents (optional)
        :param signature: Can be set later
        :rtype: OperationGroup
        """
        return OperationGroup(
            protocol=protocol,
            branch=branch,
            contents=contents,
            signature=signature,
            shell=self.shell,
            key=self.key
        )
Пример #9
0
def inject(tz: PyTezosClient,
           op_group: OperationGroup,
           max_wait_blocks=100,
           min_confirmations=1) -> Dict:
    """A replacement for pytezos's OperationGroup.inject

    Submits the provided operation group and waits for the specified number of confirmations.

    Args:
        tz: pytezos client instance
        op_group: The operation group to inject
        max_wait_blocks: Maximum number of blocks to wait for a confirmation
        min_confirmations: Minimum number of blocks required to consider operations as having been
            included on the chain.
    Raises:
        BlockchainReorg: If the confirmation search encountered more than 3 reorgs
        Exception: If the operation group was not confirmed

    Returns:
        The confirmed operation group's metadata
    """
    level = tz.shell.head.header()["level"]
    op_hash = op_group.inject(min_confirmations=0)["hash"]
    for attempt in range(1, N_ALLOWED_REORGS + 1):
        try:
            all_confirmed, op_levels = await_operations(
                tz,
                [op_hash],
                level,
                max_blocks=max_wait_blocks,
                min_confirmations=min_confirmations,
            )
            break
        except BlockchainReorg as e:
            if attempt >= N_ALLOWED_REORGS:
                raise e
            time.sleep(1)
    if not all_confirmed:
        raise Exception(f"Operation {op_hash} was not confirmed.")
    return _get_op_data(tz, op_hash, op_levels[op_hash])