Documentation ¶
Overview ¶
Rollmelette is a high-level framework for Cartesi Rollups in Go.
Index ¶
- Variables
- func Run(ctx context.Context, opts *RunOpts, app Application) (err error)
- type AddressBook
- type Application
- type Deposit
- type ERC20Deposit
- type Env
- type EnvInspector
- type EtherDeposit
- type Metadata
- type RunOpts
- type TestAdvanceResult
- type TestInspectResult
- type TestNotice
- type TestReport
- type TestVoucher
- type Tester
- func (t *Tester) Advance(msgSender common.Address, payload []byte) TestAdvanceResult
- func (t *Tester) Book() AddressBook
- func (t *Tester) DepositERC20(token common.Address, msgSender common.Address, amount *big.Int, ...) TestAdvanceResult
- func (t *Tester) DepositEther(msgSender common.Address, value *big.Int, payload []byte) TestAdvanceResult
- func (t *Tester) Inspect(payload []byte) TestInspectResult
- func (t *Tester) RelayAppAddress(appAddress common.Address) TestAdvanceResult
Constants ¶
This section is empty.
Variables ¶
var MaxUint256 *big.Int
MaxUint256 is the max value for uint256.
Functions ¶
Types ¶
type AddressBook ¶
type AddressBook struct { CartesiAppFactory common.Address AppAddressRelay common.Address ERC1155BatchPortal common.Address ERC1155SinglePortal common.Address ERC20Portal common.Address ERC721Portal common.Address EtherPortal common.Address InputBox common.Address }
AddressBook contains the addresses of the rollups contracts.
func NewAddressBook ¶
func NewAddressBook() AddressBook
NewAddressBook returns the contract addresses for mainnet and devnet.
type Application ¶
type Application interface { // Advance is called to advance the application state. It receives env to interact with the // rollup environment, the advance input metadata, a interface representing the deposit if // the input came from a portal, and the input payload. If this method returns an error, // Rollmelette reverts the execution. Advance(env Env, metadata Metadata, deposit Deposit, payload []byte) error // Inspect is called to inspect the application state. It receives env to read the rollup // environment and the input payload. If this method returns an error, Rollmelette reverts // the execution. Inspect(env EnvInspector, payload []byte) error }
Application is the interface that should be implemented by the application developer. The application has one method for the advance request and another for the inspect request.
type ERC20Deposit ¶
type ERC20Deposit struct { // Token is the address of the ERC20 token. Token common.Address // Sender is the account that sent the deposit. Sender common.Address // Amount is the amount of tokens sent. Amount *big.Int }
ERC20Deposit represents an deposit that arrived to the ERC20 wallet.
func (*ERC20Deposit) String ¶
func (d *ERC20Deposit) String() string
type Env ¶
type Env interface { EnvInspector // Voucher sends a voucher and returns its index. Voucher(destination common.Address, payload []byte) int // Notice sends a notice and returns its index. Notice(payload []byte) int // EtherTransfer transfers the given amount of funds from source to destination. // It returns an error if source doesn't have enough funds. EtherTransfer(src common.Address, dst common.Address, value *big.Int) error // EtherWithdraw withdraws the asset from the wallet, generates the voucher to withdraw // it from the application contract, and returns the voucher index. // Before withdrawing Ether, the application must receive its contract address from the // address relay contract. // It returns an error if the address doesn't have enough funds. EtherWithdraw(address common.Address, value *big.Int) (int, error) // ERC20Transfer transfers the given amount of tokens from source to destination. // It returns an error if source doesn't have enough funds. ERC20Transfer(token common.Address, src common.Address, dst common.Address, value *big.Int) error // ERC20Withdraw withdraws the token from the wallet, generates the voucher to withdraw it // from the ERC20 contract, and returns the voucher index. // It returns an error if the address doesn't have enough funds. ERC20Withdraw(token common.Address, address common.Address, value *big.Int) (int, error) }
Env is the entrypoint for the Rollup API and to Rollmelette's asset management.
type EnvInspector ¶
type EnvInspector interface { // Report sends a report. Report(payload []byte) // AppAddress returns the application address sent by the address relay contract. // If the contract didn't send the address yet, the function returns false. AppAddress() (common.Address, bool) // EtherAddresses returns the list of addresses that have Ether. EtherAddresses() []common.Address // EtherBalanceOf returns the balance of the given address. EtherBalanceOf(address common.Address) *big.Int // ERC20Tokens returns the list of tokens that have a non-zero balance in the application. ERC20Tokens() []common.Address // ERC20Addresses returns the list of addresses that have the given token. ERC20Addresses(token common.Address) []common.Address // ERC20BalanceOf returns the balance of the given address for the given token. ERC20BalanceOf(token common.Address, address common.Address) *big.Int }
EnvInspector is the entrypoint for the inspect functions of the Rollup API.
type EtherDeposit ¶
type EtherDeposit struct { // Sender is the account that sent the deposit. Sender common.Address // Value is the amount of Wei deposited. Value *big.Int }
EtherDeposit represents an deposit that arrived to the Ether wallet.
func (*EtherDeposit) String ¶
func (d *EtherDeposit) String() string
type Metadata ¶
type Metadata struct { // InputIndex is the advance input index. InputIndex int // Sender is the account or contract that added the input to the input box. MsgSender common.Address // BlockNumber is the number of the block when the input was added to the L1 chain. BlockNumber int64 // BlockNumber is the timestamp of the block when the input was added to the L1 chain. BlockTimestamp int64 }
Metadata of the rollup advance input.
type RunOpts ¶
type RunOpts struct { AddressBook // RollupURL is the URL of the Rollup API. RollupURL string }
RunOpts allows the application developer to pass some parameters to the run function.
func NewRunOpts ¶
func NewRunOpts() *RunOpts
NewRunOpts creates a RunOpts struct with sensible default values.
type TestAdvanceResult ¶
type TestAdvanceResult struct { Vouchers []TestVoucher Notices []TestNotice Reports []TestReport Metadata Err error }
TestAdvanceResult is the result of the test advance function.
type TestInspectResult ¶
type TestInspectResult struct { Reports []TestReport Err error }
TestInspectResult
type TestNotice ¶
type TestNotice struct {
Payload []byte
}
TestNotice represents a notice received by the mock.
type TestReport ¶
type TestReport struct {
Payload []byte
}
TestReport represents a report received by the mock.
type TestVoucher ¶
TestVoucher represents a voucher received by the mock.
type Tester ¶
type Tester struct {
// contains filtered or unexported fields
}
Tester is an unit tester for the Application.
func NewTester ¶
func NewTester(app Application) *Tester
NewTester creates a Tester for the given application
func (*Tester) Advance ¶
func (t *Tester) Advance(msgSender common.Address, payload []byte) TestAdvanceResult
Advance sends an advance input to the application. It returns the metadata sent to the app and the outputs received from the app.
func (*Tester) Book ¶
func (t *Tester) Book() AddressBook
Book returns the address book used by the tester.
func (*Tester) DepositERC20 ¶
func (t *Tester) DepositERC20( token common.Address, msgSender common.Address, amount *big.Int, payload []byte, ) TestAdvanceResult
DepositERC20 simulates an advance input from the ERC20 portal.
func (*Tester) DepositEther ¶
func (t *Tester) DepositEther( msgSender common.Address, value *big.Int, payload []byte, ) TestAdvanceResult
DepositEther simulates an advance input from the Ether portal.
func (*Tester) Inspect ¶
func (t *Tester) Inspect(payload []byte) TestInspectResult
Inspect sends an inspect input to the application. It returns the outputs received from the app.
func (*Tester) RelayAppAddress ¶
func (t *Tester) RelayAppAddress(appAddress common.Address) TestAdvanceResult
RelayAppAddress simulates an advance input from the app address relay.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
jsonapp
Jsonapp contains an example of a simple game application that uses JSON as inputs and outputs.
|
Jsonapp contains an example of a simple game application that uses JSON as inputs and outputs. |
This package contains integration tests for rollmelette.
|
This package contains integration tests for rollmelette. |