Skip to content

Commit

Permalink
updated xcc, advanced-xcc guides
Browse files Browse the repository at this point in the history
  • Loading branch information
garikbesson committed Mar 11, 2024
1 parent 79ef9a1 commit a859a6f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 55 deletions.
102 changes: 60 additions & 42 deletions docs/3.tutorials/examples/advanced-xcc.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ they **all get reverted**.

<CodeTabs>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/xcc-advanced/blob/main/contract/src/batch_actions.rs"
<Github fname="batch_actions.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-rs/src/batch_actions.rs"
start="7" end="19" />
</Language>
<Language value="🌐 JavaScript" language="js">
<Github fname="index.js"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="67" end="80" />
<Github fname="contract.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/contract.ts"
start="37" end="40" />
<Github fname="batch_actions.js"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/batch_actions.ts"
start="5" end="17" />
</Language>
</CodeTabs>

Expand All @@ -38,17 +41,20 @@ action** from the chain.

<CodeTabs>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/xcc-advanced/blob/main/contract/src/batch_actions.rs"
<Github fname="batch_actions.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-rs/src/batch_actions.rs"
start="21" end="34" />
</Language>
<Language value="🌐 JavaScript" language="js">
<Github fname="callback"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="82" end="93" />
<Github fname="promiseResult"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="127" end="145" />
<Github fname="contract.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/contract.ts"
start="42" end="45" />
<Github fname="batch_actions.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/batch_actions.ts"
start="19" end="29" />
<Github fname="utils.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/utils.ts"
start="3" end="20" />
</Language>
</CodeTabs>

Expand All @@ -61,14 +67,17 @@ all in parallel. If one of them fails the rest **ARE NOT REVERTED**.

<CodeTabs>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/xcc-advanced/blob/main/contract/src/multiple_contracts.rs"
<Github fname="multiple_contracts.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-rs/src/multiple_contracts.rs"
start="18" end="56" />
</Language>
<Language value="🌐 JavaScript" language="js">
<Github fname="index.js"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="95" end="111" />
<Github fname="contract.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/contract.ts"
start="47" end="50" />
<Github fname="multiple_contracts.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/multiple_contracts.ts"
start="6" end="21" />
</Language>
</CodeTabs>

Expand All @@ -78,17 +87,20 @@ value returned by each call, or an error message.

<CodeTabs>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/xcc-advanced/blob/main/contract/src/multiple_contracts.rs"
start="58" end="91" />
<Github fname="multiple_contracts.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-rs/src/multiple_contracts.rs"
start="58" end="92" />
</Language>
<Language value="🌐 JavaScript" language="js">
<Github fname="callback"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="113" end="125" />
<Github fname="promiseResult"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="127" end="145" />
<Github fname="contract.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/contract.ts"
start="52" end="55" />
<Github fname="multiple_contracts.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/multiple_contracts.ts"
start="24" end="41" />
<Github fname="utils.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/utils.ts"
start="3" end="20" />
</Language>
</CodeTabs>

Expand All @@ -103,14 +115,17 @@ In this case, we call multiple contracts that will return the same type:

<CodeTabs>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/xcc-advanced/blob/main/contract/src/similar_contracts.rs"
start="18" end="31" />
<Github fname="similar_contracts.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-rs/src/similar_contracts.rs"
start="7" end="30" />
</Language>
<Language value="🌐 JavaScript" language="js">
<Github fname="index.js"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="95" end="111" />
<Github fname="contract.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/contract.ts"
start="57" end="60" />
<Github fname="similar_contracts.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/similar_contracts.ts"
start="6" end="35" />
</Language>
</CodeTabs>

Expand All @@ -120,16 +135,19 @@ results.

<CodeTabs>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/xcc-advanced/blob/main/contract/src/similar_contracts.rs"
start="33" end="61" />
<Github fname="similar_contracts.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-rs/src/similar_contracts.rs"
start="32" end="57" />
</Language>
<Language value="🌐 JavaScript" language="js">
<Github fname="callback"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="113" end="125" />
<Github fname="promiseResult"
url="https://github.com/garikbesson/cross-contract-hello-js/blob/batch_actions/contract/src/contract.ts"
start="127" end="145" />
<Github fname="contract.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/contract.ts"
start="62" end="65" />
<Github fname="similar_contracts.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/similar_contracts.ts"
start="37" end="54" />
<Github fname="utils.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-advanced-ts/src/internal/utils.ts"
start="3" end="20" />
</Language>
</CodeTabs>
38 changes: 25 additions & 13 deletions docs/3.tutorials/examples/xcc.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ You have two options to start using the project. The first and recommended is to

| Gitpod | Clone locally |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- |
| <a href="https://gitpod.io/#https://github.com/near-examples/cross-contract-hello-js"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" /></a> | 🌐 `https://github.com/near-examples/cross-contract-hello-js.git` |
| <a href="https://gitpod.io/#https://github.com/near-examples/cross-contract-calls/tree/main/contract-simple-ts"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" /></a> | 🌐 `https://github.com/near-examples/cross-contract-calls.git` |

</TabItem>

<TabItem value="🦀 Rust">

| Gitpod | Clone locally |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- |
| <a href="https://gitpod.io/#https://github.com/near-examples/cross-contract-hello-rust"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" /></a> | 🦀 `https://github.com/near-examples/cross-contract-hello-rust.git` |
| <a href="https://gitpod.io/#https://github.com/near-examples/cross-contract-calls/tree/main/contract-simple-rs"><img src="https://gitpod.io/button/open-in-gitpod.svg" alt="Open in Gitpod" /></a> | 🦀 `https://github.com/near-examples/cross-contract-calls.git` |

</TabItem>
</Tabs>
Expand All @@ -47,17 +47,24 @@ Since this example does not have a frontend, we will interact with it through th
<!-- Expand on this explanation adding snippets -->
Check the README.md. Briefly, you will need to:

#### 1. Build and Deploy the Contract
You can automatically compile and deploy the contract in the NEAR testnet by running:
#### 1. Create a new account

In order to deploy the contract you will need to [create a NEAR account](https://docs.near.org/develop/contracts/quickstart#create-a-testnet-account).

```bash
./contract/deploy.sh
# Create an account
near create-account <accountId> --useFaucet
```

Once finished, check the `neardev/dev-account` file to find the address in which the contract was deployed:
#### 2. Build and Deploy the Contract
You can automatically compile and deploy the contract in the NEAR testnet by running:

```bash
cat ./contract/neardev/dev-account # e.g. dev-1659899566943-21539992274727
# Build the contract
cargo near build

# Deploy the contract
cargo near deploy <accountId>
```

#### 2. Get the Greeting
Expand All @@ -68,7 +75,7 @@ cat ./contract/neardev/dev-account # e.g. dev-1659899566943-21539992274727

```bash
# Use near-cli to ask the contract to query the greeting
near call <dev-account> query_greeting --accountId <dev-account>
near call <accountId> query_greeting --accountId <accountId>
```

---
Expand All @@ -80,12 +87,12 @@ The contract exposes methods to query the greeting and change it. These methods
<CodeTabs>
<Language value="🌐 JavaScript" language="ts">
<Github fname="contract.ts"
url="https://github.com/near-examples/cross-contract-hello-js/blob/master/contract/src/contract.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-ts/src/contract.ts"
start="17" end="39" />
</Language>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/cross-contract-hello-rust/blob/main/contract/src/lib.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-rs/src/lib.rs"
start="24" end="49" />
</Language>
</CodeTabs>
Expand All @@ -110,14 +117,19 @@ method works. This is because unit tests are **cannot test** cross-contract call

In this project in particular, the integration tests first deploy the `hello-near` contract. Then,
they test that the cross-contract call correctly sets and retrieves the message. You will find the integration tests
in `integration-tests/`.
in `sandbox-ts/` for the JavaScript version and in `tests/` for the Rust version.

<CodeTabs>
<Language value="🌐 JavaScript" language="rust">
<Github fname="main.test.js"
url="https://github.com/near-examples/cross-contract-hello-js/blob/master/integration-tests/src/main.ava.ts"
<Github fname="main.ava.ts"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-ts/sandbox-ts/src/main.ava.ts"
start="9" end="59" />
</Language>
<Language value="🦀 Rust" language="rust">
<Github fname="lib.rs"
url="https://github.com/near-examples/cross-contract-calls/blob/main/contract-simple-rs/tests/tests.rs"
start="5" end="77" />
</Language>
</CodeTabs>

---
Expand Down

0 comments on commit a859a6f

Please sign in to comment.