Esempio n. 1
0
    def toJSON(self):
        obj = {
            'data': {
                'staker': self.staker,
                'claimable_stake': self.claimable_stake,
                'token': {
                    'name': self.token.name,
                    'symbol': self.token.symbol,
                    'address': self.token.address
                },
                'minimum_fee': self.minimum_fee,
                'data': self.data,
                'claim_deadline': str( int(Decimal(self.claim_deadline.real)) ),
                'arbiter': {
                    'name': '',
                    'description': '',
                    'address': self.arbiter.address
                },
                'whitelist': [w.claimant for w in self.whitelist],
                'claims': [json.loads(c.toJSON()) for c in self.claims],
                'settlements': [] # TODO
            },
            'errors': []
        }

        return json.dumps(obj)
Esempio n. 2
0
    def process_request(self, req, resp):
        if req.content_length in (None, 0):
            return

        body = req.stream.read()
        if not body:
            raise HTTPError(400, "A valid JSON document is required.")

        try:
            req.context["doc"] = json.loads(body.decode("utf-8"))

        except (ValueError, UnicodeDecodeError):
            raise HTTPError(400, "Could not decode the request body. The "
                                 "JSON was incorrect or not encoded as "
                                 "UTF-8.")
Esempio n. 3
0
    def process_request(self, req, resp):
        if req.content_length in (None, 0):
            return

        body = req.stream.read()
        if not body:
            raise HTTPError(
                falcon.HTTP_BAD_REQUEST,
                "Empty request body. A valid JSON document is required.",
            )

        try:
            req.context.doc = json.loads(body.decode("utf-8"))

        except (ValueError, UnicodeDecodeError):
            raise HTTPError(
                falcon.HTTP_BAD_REQUEST,
                "Malformed JSON. "
                "Could not decode the request body. The "
                "JSON was incorrect or not encoded as "
                "UTF-8.",
            )
Esempio n. 4
0
 def simulate_request(self, path, *args, **kwargs):
     env = falcon.testing.create_environ(path, *args, **kwargs)
     resp = self.app(env, self.srmock)
     if len(resp) >= 1:
         return json.loads(resp[0].decode("utf-8"))
     return resp