Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,47 @@ This is a solidity implementation of [Cross Framework](https://github.com/datach

Currently, it provides the following features:
- the registry feature that allows developers to register their contracts
- the participant feature of the simple commit protocol
- the coordinator feature of the simple commit protocol
- the participant features for the simple-commit and two-phase commit protocols
- it's implemented on top of [yui-ibc-solidity](https://github.com/hyperledger-labs/yui-ibc-solidity)

A coordinator feature of the simple commit and two-phase commit will be provided in the future.
The coordinator feature of the two-phase commit will be provided in the future.

## Contract module development
## Demo

A developer who develops contract using Cross Framework need to implement IContractModule, which is defined in [IContractModule.sol](./src/core/IContractModule.sol).
For an ERC20 atomic swap demo, please refer to [ethereum-cross-demo](https://github.com/datachainlab/ethereum-cross-demo)

## Contract module development

```
// IContractModule defines the expected interface of a contract module on Cross Framework
```solidity
interface IContractModule {
// onContractCall is a callback function that is called at the commit(simple-commit) phase
function onContractCall(CrossContext calldata context, bytes calldata callInfo) external returns (bytes memory);
// onContractCommitImmediately is a callback function that is called on the participant chain to execute the transaction logic immediately
// This function is intended to be used only in the simple-commit protocol
function onContractCommitImmediately(CrossContext calldata context, bytes calldata callInfo)
external
returns (bytes memory);

// onContractPrepare is a callback function that is called at the prepare(2pc) phase
function onContractPrepare(CrossContext calldata context, bytes calldata callInfo) external returns (bytes memory);

// onCommit is a callback function that is called at the commit(2pc) phase
// It is expected that it commits the changes in the contract module
// IMPORTANT: This function MUST NOT revert.
function onCommit(CrossContext calldata context) external;

// onAbort is a callback function that is called at the commit(2pc) phase
// It is expected that it aborts the changes in the contract module
// IMPORTANT: This function MUST NOT revert.
function onAbort(CrossContext calldata context) external;
}
```

- Currently, only one function `onContractCall` is defined, which implements the process of a transaction called via the cross-chain transaction.
- For the current simple-commit coordinator flow, the coordinator-side participant uses `onContractPrepare` to execute and lock state changes, and later finalizes them with `onCommit` or `onAbort` based on the acknowledgement from the counterparty.

- The return value of `onContractCall` is emitted as an Event `OnContractCall` with the transaction info.
- The counterparty participant executes the incoming call and finalizes immediately via `onContractCommitImmediately`.

- If it gets an unexpected call, the developer need to perform `revert` in the contract. This will request the coordinator to abort the transaction.
- IMPORTANT: `onCommit` and `onAbort` MUST NOT revert.

## How to deploy a contract module

Expand Down
Loading