Skip to content

Commit

Permalink
chore(docs): xapp example fixes (#1632)
Browse files Browse the repository at this point in the history
Update xapp example docs.

- rename `GlobalGreeter` section to `GreetingBook`
- update code blocks
- cleanup `isXCall` section

issue: none
  • Loading branch information
kevinhalliday authored Aug 2, 2024
1 parent 434766f commit 9fecc1a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions docs/site/docs/develop/xapp/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ function greet(string calldata greeting) external payable {
```

## `GlobalGreeter` Contract
## `GreetingBook` Contract

<GitHubCodeBlock url="https://github.com/omni-network/hello-world-template/blob/48ff2f5277b4c144802c1ffa894a03ac071f02fc/src/GreetingBook.sol" />
<GitHubCodeBlock url="https://github.com/omni-network/hello-world-template/blob/eb02c55bc8ef92c09e7cb6e40420353e41e2841c/src/GreetingBook.sol" />

### Walkthrough

Expand Down Expand Up @@ -84,7 +84,7 @@ With this context, we can have our `GreetingBook` extract the source chain and s

```solidity
function greet(address user, string calldata _greeting) external xrecv {
require(omni.isXCall(), "GreetingBook: only xcalls");
// ...
lastGreet = Greeting(user, _greeting, xmsg.sourceChainId, block.timestamp);
}
Expand All @@ -111,8 +111,12 @@ xmsg.sourceChainId // 0
xmsg.sender // address(0)
```

You can check if the current call is an `xcall` with `isXCall`.
You can check if the current call is an `xcall`, and the sender is the portal, with `isXCall()`.

<GitHubCodeBlock url="https://github.com/omni-network/omni/blob/ad2f5b7dddc245e7f5b6b662d6c1fc44170694ab/contracts/src/xchain/OmniPortal.sol#L200-L202" />
```solidity
function greet(address user, string calldata _greeting) external xrecv {
require(isXCall(), "GreetingBook: only xcalls");
Note that not only does `isXCall` check with the portal that the current transaction is an `xcall`. This helps avoid mistaking calls later in an `xcall` stacktrace with the original `xcall`. Using this helper, we can ensure that `greet()` can only ever be called via an `xcall`.
// ...
}
```

0 comments on commit 9fecc1a

Please sign in to comment.