コード例 #1
0
def make_update_emp_transaction(transaction_signer, batch_signer, emp_id, age,
                                address, email, com_id, timestamp):
    user_address = addresser.get_user_address(
        transaction_signer.get_public_key().as_hex())
    emp_address = addresser.get_employee_address(emp_id)

    inputs = [user_address, emp_address]
    outputs = [emp_address]

    action = payload_pb2.UpdateEmp(id=emp_id,
                                   age=age,
                                   address=address,
                                   email=email,
                                   com_id=com_id)
    payload = payload_pb2.SimpleSupplyPayload(
        action=payload_pb2.SimpleSupplyPayload.UPDATE_EMP,
        update_emp=action,
        timestamp=timestamp)
    LOGGER.info(payload)
    payload_bytes = payload.SerializeToString()

    return _make_batch(payload_bytes=payload_bytes,
                       inputs=inputs,
                       outputs=outputs,
                       transaction_signer=transaction_signer,
                       batch_signer=batch_signer)
コード例 #2
0
    def get_emp(self, emp_id):
        employee_address = addresser.get_employee_address(emp_id)
        state_entries = self._context.get_state(addresses=[employee_address],
                                                timeout=self._timeout)
        if state_entries:
            container = employee_pb2.EmployeeContainer()
            container.ParseFromString(state_entries[0].data)
            for employee in container.entries:
                if employee.id == emp_id:
                    return employee

        return None
コード例 #3
0
    def create_emp(self, emp_id, name, timestamp):
        employee_address = addresser.get_employee_address(emp_id)
        employee = employee_pb2.Employee(id=emp_id, name=name)
        container = employee_pb2.EmployeeContainer()
        state_entries = self._context.get_state(addresses=[employee_address],
                                                timeout=self._timeout)
        if state_entries:
            container.ParseFromString(state_entries[0].data)
        container.entries.extend([employee])
        data = container.SerializeToString()

        updated_state = {employee_address: data}
        self._context.set_state(updated_state, timeout=self._timeout)
コード例 #4
0
    def update_emp(self, emp_id, age, address, email, com_id, timestamp):
        employee_address = addresser.get_employee_address(emp_id)
        update = employee_pb2.Employee.Update(timestamp=timestamp,
                                              age=age,
                                              address=address,
                                              email=email,
                                              com_id=com_id)
        container = employee_pb2.EmployeeContainer()
        state_entries = self._context.get_state(addresses=[employee_address],
                                                timeout=self._timeout)
        if state_entries:
            container.ParseFromString(state_entries[0].data)
            for employee in container.entries:
                if employee.id == emp_id:
                    employee.updates.extend([update])

        data = container.SerializeToString()
        updated_state = {employee_address: data}
        self._context.set_state(updated_state, timeout=self._timeout)