2024-07-09 00:06:31 +03:00

79 lines
2.0 KiB
Python

from cartesi_wallet.util import str_to_hex
class Output():
"""
Base class representing a result generated by processing an input.
It is resposible for converting its payload to the format expected by
Cartesi rollups.
Parameters:
payload(str): the actual data generated after processing the input
"""
def __init__(self, payload: str):
if payload[:2] == "0x":
self.payload = payload
else:
self.payload = str_to_hex(payload)
class Voucher(Output):
"""
A Voucher is an `Output` representing a transaction
that can be carried out on the base layer blockchain,
such as a transfer of assets.
Parameters:
destination(str): destination of the contract who will execute the payload
payload(bytes): an ABI encoded contract function call
"""
def __init__(self, destination: str, payload: bytes):
self.destination = destination
hexpayload = "0x" + payload.hex()
super().__init__(hexpayload)
class Notice(Output):
"""
A Notice is an `Output` representing an informational statement
that can be validated in the base layer blockchain.
Parameters:
payload(str): a string containing arbitrary data
"""
def __init__(self, payload: str):
super().__init__(payload)
class Log(Output):
"""
A Log is an `Output` representing an application log.
Parameters:
payload(str): a string containing arbitrary data
"""
def __init__(self, payload: str):
super().__init__(payload)
class Error(Output):
"""
An Error is an `Output` representing that an error has ocurred
during the processing of an input.
If something unexpected such as an exception or error occurs during
the processing of an input, that input must be rejected.
Parameters:
payload(str): a string containing arbitrary data
"""
def __init__(self, payload: str):
super().__init__(payload)