Beispiel #1
0
    def _record_create(self, state, originator, data):
        txn_data = RecordCreatePayload()
        txn_data.ParseFromString(data)

        agent_addr = Addressing.agent_address(originator)
        record_addr = Addressing.record_address(txn_data.identifier)

        state_items = self._get(state, [agent_addr, record_addr])

        agents = state_items.get(agent_addr, None)
        records = state_items.get(record_addr, RecordContainer())

        # check that the agent exists
        if self._find_agent(agents, originator) is None:
            raise InvalidTransaction("Agent is not registered.")

        # check that the record does not exists
        record = self._find_record(records, txn_data.identifier)
        if record is not None:
            raise InvalidTransaction("Record already exists.")

        # create the new record
        record = records.entries.add()
        record.identifier = txn_data.identifier
        record.creation_time = txn_data.creation_time
        owner = record.owners.add()
        owner.agent_identifier = originator
        owner.start_time = txn_data.creation_time
        custodian = record.custodians.add()
        custodian.agent_identifier = originator
        custodian.start_time = txn_data.creation_time
        record.final = False

        # send back the updated agents list
        self._set(state, [(record_addr, records)])
Beispiel #2
0
    def record_create(self, record_identifier, creation_time=None, wait=None):
        outputs = [Addressing.record_address(record_identifier)]
        inputs = outputs + \
            [Addressing.agent_address(self._public_key)]

        return self._send_txn(SupplyChainPayload.RECORD_CREATE,
                              RecordCreatePayload(identifier=record_identifier,
                                                  creation_time=creation_time
                                                  or int(time.time())),
                              inputs=inputs,
                              outputs=outputs,
                              wait=wait)
Beispiel #3
0
    def create_record_tp_process_request(self,
                                         identifier,
                                         timestamp):
        record_addr = Addressing.record_address(identifier)
        agent_pub_key = self.public_key
        agent_addr = Addressing.agent_address(agent_pub_key)
        inputs = [agent_addr, record_addr]
        outputs = [agent_addr, record_addr]

        return self.create_tp_process_request(
            SupplyChainPayload.RECORD_CREATE,
            RecordCreatePayload(identifier=identifier,
                                creation_time=timestamp),
            inputs, outputs)