def get(self, request, key=""): if settings.BIGCHAINDB_ENABLED: err, data = bigchaindb_api.find_one(key) if err: return Response(status=err, data={ "error": data, "details": { "error_code": err, "key": key } }) else: cert_address = address.for_cert(key) err, cert = sawtooth_api.get_state_as(Certification, cert_address) if err: return Response(status=400, data={ "error": "Error getting certification", "details": { "error_code": err, "address": cert_address } }) data = sawtooth_api.proto_to_dict(cert) return Response(data)
def get(self, request, key=None): farm = sawtooth_api.get_or_404(Farm, address.for_farm(key)) data = sawtooth_api.proto_to_dict(farm) sawtooth_api.resolve_keys(data, 'certifications', Certification) return Response( data=data )
def get(self, request, key=None): addr = address.addr_map[pb_class](key) roast = sawtooth_api.get_or_404(pb_class, addr) state_data = sawtooth_api.client.state(addr) return Response( data={ "address": addr, "state": state_data, "head_block": sawtooth_api.client.block( state_data['head']), "object": sawtooth_api.proto_to_dict(roast) })
def get(self, request, key=None): roast = sawtooth_api.get_or_404(Roast, address.for_roast(key)) data = sawtooth_api.proto_to_dict(roast) sawtooth_api.resolve_keys(data, 'harvests', Harvest) for h in data['harvests']: sawtooth_api.resolve_keys(h, 'shipments', Shipment) sawtooth_api.resolve_keys(h, 'farms', Farm) # sort farms by date for f in h['farms']: sawtooth_api.resolve_keys(f, 'certifications', Certification) data['harvests'] = sorted(data['harvests'], key=itemgetter("year", "month")) return Response(data=data)
def get(self, request, addr, as_type=None): data = sawtooth_api.client.state(addr) data['address'] = addr if as_type: bytes_data = b64decode(data['data']) try: cls = pb_class_map.get(as_type, None) if None: raise ValidationError("Type '%s' is not known" % as_type) obj = cls() obj.ParseFromString(bytes_data) data['object'] = sawtooth_api.proto_to_dict(obj) except Exception as e: data['object'] = None data['object_decode_error'] = { "message": "%s" % e, "raw_data": repr(bytes_data).lstrip("b'").rstrip('').replace( "\\", "\\") } return Response(data=data)
def get(self, request, key=None): harvest = sawtooth_api.get_or_404(Shipment, address.for_shipment(key)) return Response(data=sawtooth_api.proto_to_dict(harvest))
def get(self, request, key): code = sawtooth_api.get_or_404(Code, address.for_code(key)) return Response(sawtooth_api.proto_to_dict(code))