Version: 0.4.0
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 = {
'address': 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