Beispiel #1
0
    def find_proposal_inject_operation(self, proposal_id) -> Operation:
        level = self.find_proposal_inject_level(proposal_id)
        operations = self.blocks[level].operations.votes()
        if not operations:
            raise ValueError('Injection operation not found.')

        return Operation.from_data(operations[0])
Beispiel #2
0
 def _get_operations_list(self, key, kind=None):
     operations = self.get(key)
     if kind:
         operations = filter(lambda x: x['contents'][0]['kind'] == kind,
                             operations)
     return list(
         map(lambda x: Operation(data=x, node=self._node, **self._kwargs),
             operations))
Beispiel #3
0
 def create_endorsement(self) -> Operation:
     header = self.header()
     return Operation(
         data={
             'branch': header['hash'],
             'contents': [{
                 'kind': 'endorsement',
                 'level': header['level']
             }]
         })
Beispiel #4
0
 def find_storage_change_operations(self,
                                    contract_id,
                                    origination_level=None) -> Generator:
     for level in self.find_storage_change_levels(contract_id,
                                                  origination_level):
         for operation in self.blocks[level].operations.managers():
             if any(
                     map(lambda x: x.get('destination') == contract_id,
                         operation['contents'])):
                 yield Operation.from_data(operation)
Beispiel #5
0
    def find_contract_origination_operation(self, contract_id) -> Operation:
        level = self.find_contract_origination_level(contract_id)
        operations = self.blocks[level].operations.managers()

        for operation in operations:
            for content in filter_contents(operation, kind='origination'):
                if content.get('metadata'):
                    result = content['metadata']['operation_result']
                else:
                    result = content['result']
                if contract_id in result['originated_contracts']:
                    return Operation.from_data(operation)

        raise ValueError('Origination operation not found.')
Beispiel #6
0
    def _get_operations_list(self, key, kind=None):
        operations = self.get(key)

        if kind:
            if isinstance(kind, str):
                kind = {kind}
            elif isinstance(kind, list):
                kind = set(kind)

            operations = filter(
                lambda op: any(map(lambda x: x['kind'] in kind, op['contents'])
                               ), operations)

        return list(
            map(lambda x: Operation(data=x, node=self._node, **self._kwargs),
                operations))
Beispiel #7
0
 def find_proposal_votes_operations(self, proposal_id) -> Generator:
     for level in self.find_proposal_votes_levels(proposal_id):
         for operation in self.blocks[level].operations.votes():
             yield Operation.from_data(operation)