Exemple #1
0
def _create_agent(payload, signer, timestamp, state):
    name = payload.name
    Type = payload.type

    if not name:
        raise InvalidTransaction(
            'Agent name cannot be empty string')

    address = addressing.make_agent_address(signer)
    container = _get_container(state, address)

    for agent in container.entries:
        if agent.public_key == signer:
            raise InvalidTransaction(
                'Agent already exists')

    agent = Agent(
        public_key=signer,
        name=name,
        timestamp=timestamp,
        type=Type,
    )

    container.entries.extend([agent])
    container.entries.sort(key=lambda ag: ag.public_key)

    _set_container(state, address, container)
Exemple #2
0
    def make_empty_payload(self, public_key):
        address = addressing.make_agent_address(public_key)

        return self._create_transaction(
            payload=SCPayload().SerializeToString(),
            inputs=[address],
            outputs=[address])
Exemple #3
0
    def create_proposal(self,
                        record_id,
                        receiving_agent,
                        role,
                        properties=None):
        if properties is None:
            properties = []

        payload = _make_sc_payload(action=SCPayload.CREATE_PROPOSAL,
                                   create_proposal=CreateProposalAction(
                                       record_id=record_id,
                                       receiving_agent=receiving_agent,
                                       role=role,
                                       properties=properties))

        proposal_address = addressing.make_proposal_address(
            record_id, receiving_agent)

        receiving_address = addressing.make_agent_address(receiving_agent)

        record_address = addressing.make_record_address(record_id)

        return self._create_transaction(
            payload,
            inputs=[
                proposal_address,
                record_address,
                receiving_address,
                self.signer_address,
            ],
            outputs=[proposal_address],
        )
Exemple #4
0
def _verify_agent(state, public_key):
    ''' Verify that public_key has been registered as an agent '''
    address = addressing.make_agent_address(public_key)
    container = _get_container(state, address)

    if all(agent.public_key != public_key for agent in container.entries):
        raise InvalidTransaction(
            'Agent must be registered to perform this action')
Exemple #5
0
    def __init__(self, signer=None):
        self._factory = MessageFactory(family_name=addressing.FAMILY_NAME,
                                       family_version='1.0',
                                       namespace=addressing.NAMESPACE,
                                       signer=signer)

        self.public_key = self._factory.get_public_key()
        self.signer_address = addressing.make_agent_address(self.public_key)
Exemple #6
0
    def __init__(self, private=None, public=None):
        self._factory = MessageFactory(
            encoding='application/protobuf',
            family_name=addressing.FAMILY_NAME,
            family_version='1.0',
            namespace=addressing.NAMESPACE,
            private=private,
            public=public)

        self.public_key = self._factory.get_public_key()
        self.private_key = self._factory.get_private_key()
        self.signer_address = addressing.make_agent_address(self.public_key)