Esempio n. 1
0
 def post(self, request, *args, **kwargs):
     data = validate_using(CreateFarmSerializer, data=request.data, view=self)
     farm = Farm(**data)
     resp = sawtooth_api.submit_event(
         farm_create=farm,
         inputs=[address.for_cert(c) for c in farm.certifications],
         outputs=[address.for_farm(data['key'])]  # this is the address we will be writing to
     )
     return Response(data=resp)
Esempio n. 2
0
 def post(self, request):
     # the output of validate_using should match the data format of the
     # Shipment object exactly
     data = validate_using(ShipmentCreateSerializer,
                           data=request.data,
                           view=self)
     shipment = Shipment(**data)
     resp = sawtooth_api.submit_event(
         shipment_create=shipment,
         inputs=[],
         outputs=[address.for_shipment(shipment.key)])
     return Response(data=resp)
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        data = validate_using(serializers.CreateCertSerializer,
                              data=request.data,
                              view=self)
        if settings.BIGCHAINDB_ENABLED:
            resp_json = bigchaindb_api.create(data)
        else:
            new_cert = Certification(**data)
            resp_json = sawtooth_api.submit_event(
                cert_create=new_cert, outputs=[address.for_cert(new_cert.key)])

        return Response(resp_json)
Esempio n. 4
0
    def post(self, request):
        data = validate_using(CreateHarvestSerializer,
                              data=request.data,
                              view=self)
        harvest = Harvest(**data)

        resp = sawtooth_api.submit_event(
            harvest_create=harvest,
            inputs=([address.for_farm(f) for f in harvest.farms] +
                    [address.for_shipment(s) for s in harvest.shipments]),
            outputs=[address.for_harvest(harvest.key)],
        )

        return Response(data=resp)
Esempio n. 5
0
    def post(self, request, key=None):
        roast = sawtooth_api.get_or_404(Roast, address.for_roast(key))
        data = validate_using(RoastAddHarvestSerializer,
                              data=request.data,
                              view=self)

        resp = sawtooth_api.submit_event(
            add_related=Events.AddRelated(action="roast_harvest",
                                          object_key=key,
                                          related_key=data['key']),
            inputs=[address.for_harvest(data['key'])],
            outputs=[address.for_roast(key)])

        return Response(data=resp)
Esempio n. 6
0
    def post(self, request, *args, **kwargs):
        data = validate_using(RoastCreateSerializer,
                              data=request.data,
                              view=self)
        roast = Roast(**data)

        resp = sawtooth_api.submit_event(
            roast_create=roast,
            inputs=[address.for_harvest(h) for h in roast.harvests],
            outputs=[address.for_roast(roast.key)
                     ]  # this is the address we will be writing to
        )

        return Response(data=resp)
Esempio n. 7
0
    def post(self, request, key):
        farm = sawtooth_api.get_or_404(Farm, address.for_farm(key))
        data = validate_using(AddCertSerializer, data=request.data, view=self)

        resp = sawtooth_api.submit_event(
            add_related=Events.AddRelated(
                action="farm_cert",
                object_key=key,
                related_key=data['key']
            ),
            inputs=[address.for_farm(data['key'])],  # farm  key is in the url
            outputs=[address.for_farm(key)]
        )

        return Response(data=resp)
Esempio n. 8
0
    def post(self, request, key):
        harvest = sawtooth_api.get_or_404(Harvest, address.for_harvest(key))
        data = validate_using(AddFarmSerializer, data=request.data, view=self)

        resp = sawtooth_api.submit_event(
            add_related=Events.AddRelated(
                action="harvest_farm",
                object_key=key,  # key from the URL, already validated
                related_key=data[
                    'key']  # key from the post-data, already validated
            ),
            inputs=[address.for_harvest(key),
                    address.for_farm(data['key'])],
            outputs=[address.for_harvest(key)
                     ]  # this is the address we will be writing to
        )

        return Response(data=resp)