Version: 0.5.1
Cartesi Rollup HTTP API
API that the Cartesi Rollup HTTP Server implements.
In the box below, there is an example of a dApp backend that uses the Rollup HTTP API.
import requests
import sys
rollup = sys.argv[1]
def check_status_code(response):
if response.status_code not in range(200, 300):
print(f'Error: invalid status code {response.status_code}')
sys.exit(1)
return response
finish = {'status': 'accept'}
while True:
print('Sending finish')
r = check_status_code(requests.post(rollup + '/finish', json=finish))
if r.status_code == 202:
print('No pending rollup request, trying again')
continue
rollup_request = r.json()
if rollup_request['request_type'] == 'advance_state':
print('Sending voucher')
voucher = {
'destination': rollup_request['data']['metadata']['msg_sender'],
'payload': rollup_request['data']['payload']
}
check_status_code(requests.post(rollup + '/voucher', json=voucher))
print('Sending notice')
notice = {'payload': rollup_request['data']['payload']}
check_status_code(requests.post(rollup + '/notice', json=notice))
print('Sending report')
report = {'payload': rollup_request['data']['payload']}
check_status_code(requests.post(rollup + '/report', json=report))
finish['status'] = 'accept'
elif rollup_request['request_type'] == 'inspect_state':
print('Sending report per inspect request')
report = {'payload': rollup_request['data']['payload']}
check_status_code(requests.post(rollup + '/report', json=report))
else:
print('Throwing rollup exception')
exception = {'payload': rollup_request['data']['payload']}
requests.post(rollup + '/exception', json=exception)
break
In production mode, if the dApp exits the Rollups initialization script will register a Rollup Exception. See /exception.
In host mode, the Cartesi Rollups infrastructure is not able to detect that the dApp exited. It is up to the dApp developer to re-launch the dApp.