Skip to content

Commit 689d83a

Browse files
committed
docs: update README to clarify contract module interface and features
1 parent 65a46f6 commit 689d83a

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,46 @@ This is a solidity implementation of [Cross Framework](https://github.com/datach
88
Currently, it provides the following features:
99
- the registry feature that allows developers to register their contracts
1010
- the coordinator feature of the simple commit protocol
11-
- the participant feature of the simple commit protocol
11+
- the participant feature
1212
- it's implemented on top of [yui-ibc-solidity](https://github.com/hyperledger-labs/yui-ibc-solidity)
1313

14-
The two-phase commit will be provided in the future.
14+
The coordinator feature of the two-phase commit will be provided in the future.
1515

1616
## Demo
1717

1818
For an ERC20 atomic swap demo, please refer to [ethereum-cross-demo](https://github.com/datachainlab/ethereum-cross-demo)
1919

2020
## Contract module development
2121

22-
A developer who develops contract using Cross Framework need to implement IContractModule, which is defined in [IContractModule.sol](./src/core/IContractModule.sol).
23-
24-
```
2522
// IContractModule defines the expected interface of a contract module on Cross Framework
23+
```solidity
2624
interface IContractModule {
27-
// onContractCall is a callback function that is called at the commit(simple-commit) phase
28-
function onContractCall(CrossContext calldata context, bytes calldata callInfo) external returns (bytes memory);
25+
// onContractCommitImmediately is a callback function that is called on the participant chain to execute the transaction logic immediately
26+
// This function is intended to be used only in the simple-commit protocol
27+
function onContractCommitImmediately(CrossContext calldata context, bytes calldata callInfo)
28+
external
29+
returns (bytes memory);
30+
31+
// onContractPrepare is a callback function that is called at the prepare(2pc) phase
32+
function onContractPrepare(CrossContext calldata context, bytes calldata callInfo) external returns (bytes memory);
33+
34+
// onCommit is a callback function that is called at the commit(2pc) phase
35+
// It is expected that it commits the changes in the contract module
36+
// IMPORTANT: This function MUST NOT revert.
37+
function onCommit(CrossContext calldata context) external;
38+
39+
// onAbort is a callback function that is called at the commit(2pc) phase
40+
// It is expected that it aborts the changes in the contract module
41+
// IMPORTANT: This function MUST NOT revert.
42+
function onAbort(CrossContext calldata context) external;
2943
}
3044
```
3145

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

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

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

3852
## How to deploy a contract module
3953

0 commit comments

Comments
 (0)