mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: Imprecise POST transaction responses (#2198)
Solution: Improve responses
This commit is contained in:
parent
006a0a6a2a
commit
a29e9c6dd9
@ -52,12 +52,36 @@ class BigchainDB(Bigchain):
|
|||||||
'id': str(uuid4())
|
'id': str(uuid4())
|
||||||
}
|
}
|
||||||
# TODO: handle connection errors!
|
# TODO: handle connection errors!
|
||||||
requests.post(ENDPOINT, json=payload)
|
return requests.post(ENDPOINT, json=payload)
|
||||||
|
|
||||||
def write_transaction(self, transaction, mode):
|
def write_transaction(self, transaction, mode):
|
||||||
# This method offers backward compatibility with the Web API.
|
# This method offers backward compatibility with the Web API.
|
||||||
"""Submit a valid transaction to the mempool."""
|
"""Submit a valid transaction to the mempool."""
|
||||||
self.post_transaction(transaction, mode)
|
response = self.post_transaction(transaction, mode)
|
||||||
|
return self._process_post_response(response, mode)
|
||||||
|
|
||||||
|
def _process_post_response(self, response, mode):
|
||||||
|
result = response['result']
|
||||||
|
if mode == MODE_LIST[1]:
|
||||||
|
status_code = result['check_tx']['code']
|
||||||
|
return self._process_status_code(status_code,
|
||||||
|
'Error while validating the transaction')
|
||||||
|
elif mode == MODE_LIST[2]:
|
||||||
|
return self._process_commit_mode_response(result)
|
||||||
|
|
||||||
|
return (202, '')
|
||||||
|
|
||||||
|
def _process_commit_mode_response(self, result):
|
||||||
|
check_tx_status_code = result['check_tx']['code']
|
||||||
|
if check_tx_status_code == 0:
|
||||||
|
deliver_tx_status_code = result['deliver_tx']['code']
|
||||||
|
return self._process_status_code(deliver_tx_status_code,
|
||||||
|
'Error while commiting the transaction')
|
||||||
|
else:
|
||||||
|
return (500, 'Error while validating the transaction')
|
||||||
|
|
||||||
|
def _process_status_code(self, status_code, failure_msg):
|
||||||
|
return (202, '') if status_code == 0 else (500, failure_msg)
|
||||||
|
|
||||||
def get_latest_block_height_from_tendermint(self):
|
def get_latest_block_height_from_tendermint(self):
|
||||||
r = requests.get(ENDPOINT + 'status')
|
r = requests.get(ENDPOINT + 'status')
|
||||||
|
@ -90,9 +90,11 @@ class TransactionListApi(Resource):
|
|||||||
'Invalid transaction ({}): {}'.format(type(e).__name__, e)
|
'Invalid transaction ({}): {}'.format(type(e).__name__, e)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
bigchain.write_transaction(tx_obj, mode)
|
status_code, message = bigchain.write_transaction(tx_obj, mode)
|
||||||
|
|
||||||
|
if status_code == 202:
|
||||||
response = jsonify(tx)
|
response = jsonify(tx)
|
||||||
response.status_code = 202
|
response.status_code = 202
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
else:
|
||||||
|
return make_error(status_code, message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user