Skip to content

Commit

Permalink
Merge pull request #13 from multiversx/update-15
Browse files Browse the repository at this point in the history
Reference newer tools, update documentation
  • Loading branch information
andreibancioiu authored Sep 18, 2023
2 parents 2c8d828 + c36ba71 commit 25d3e77
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-image-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: ./resources/smart-contracts-rust
push: true
Expand All @@ -43,7 +43,7 @@ jobs:
tags: multiversx/devcontainer-smart-contracts-rust:${{ env.VERSION }}

- name: Push to "latest"
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
context: ./resources/smart-contracts-rust
push: ${{ inputs.latest }}
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export DOCKER_USER=$(id -u):$(id -g)
# Mandatory: run the container as the current user (should be 1000:1000), not as root.
# Suggestion: use a stateless container; remove it after use (--rm).
# Suggestion: map the current directory to "/data" in the container.
export RUN="docker run --user=${DOCKER_USER} --rm -it --volume $(pwd):/data"
export RUN="docker run --network=host --user=${DOCKER_USER} --rm -it --volume $(pwd):/data"
```

Run the container and do a quick inspection:
Expand All @@ -36,56 +36,57 @@ Run the container and do a quick inspection:
${RUN} ${IMAGE} whoami
${RUN} ${IMAGE} mxpy --version
${RUN} ${IMAGE} mxpy deps check rust
${RUN} ${IMAGE} sc-meta --version
```

Clone `mx-contracts-rs` locally, then build a few contracts within the container:

```
git clone https://github.com/multiversx/mx-contracts-rs.git --single-branch --depth=1
${RUN} ${IMAGE} mxpy contract build /data/mx-contracts-rs/contracts/adder
${RUN} ${IMAGE} mxpy contract build --path /data/mx-contracts-rs/contracts/adder
stat ./mx-contracts-rs/contracts/adder/output/adder.wasm
${RUN} ${IMAGE} mxpy contract build /data/mx-contracts-rs/contracts/ping-pong-egld
${RUN} ${IMAGE} mxpy contract build --path /data/mx-contracts-rs/contracts/ping-pong-egld
stat ./mx-contracts-rs/contracts/ping-pong-egld/output/ping-pong-egld.wasm
```

Deploy a previously-built smart contract on Testnet:
Deploy a previously-built smart contract on Devnet:

```
${RUN} ${IMAGE} mxpy contract deploy \
--bytecode /data/mx-contracts-rs/contracts/adder/output/adder.wasm \
--arguments 0 \
--pem /home/developer/multiversx-sdk/testwallets/latest/users/frank.pem \
--pem /home/developer/multiversx-sdk/testwallets/latest/users/alice.pem \
--recall-nonce \
--gas-limit 5000000 \
--chain T \
--proxy https://testnet-gateway.multiversx.com \
--chain D \
--proxy https://devnet2-gateway.multiversx.com \
--send
```

Call a function of a previously-deployed smart contract:

```
${RUN} ${IMAGE} mxpy contract call \
erd1qqqqqqqqqqqqqpgq5v3ra8mxjkv6g2pues9tdkkzwmtm9fdht7asp8wtnr \
erd1qqqqqqqqqqqqqpgqfzydqmdw7m2vazsp6u5p95yxz76t2p9rd8ss0zp9ts \
--function "add" \
--arguments 42 \
--pem /home/developer/multiversx-sdk/testwallets/latest/users/frank.pem \
--pem /home/developer/multiversx-sdk/testwallets/latest/users/alice.pem \
--recall-nonce \
--gas-limit 5000000 \
--chain T \
--proxy https://testnet-gateway.multiversx.com \
--chain D \
--proxy https://devnet2-gateway.multiversx.com \
--send
```

Query a smart contract:

```
${RUN} ${IMAGE} mxpy contract query \
erd1qqqqqqqqqqqqqpgq5v3ra8mxjkv6g2pues9tdkkzwmtm9fdht7asp8wtnr \
erd1qqqqqqqqqqqqqpgqfzydqmdw7m2vazsp6u5p95yxz76t2p9rd8ss0zp9ts \
--function "getSum" \
--proxy https://testnet-gateway.multiversx.com
--proxy https://devnet2-gateway.multiversx.com
```

Setup a localnet (make sure to set the `--workdir`, as well), then inspect the generated files (on the mapped volume):
Expand Down Expand Up @@ -126,7 +127,7 @@ Resources:
Build the Docker images for local testing:

```
docker build ./resources/smart-contracts-rust -t multiversx/devcontainer-smart-contracts-rust:latest -f ./resources/smart-contracts-rust/Dockerfile
docker build --network=host ./resources/smart-contracts-rust -t multiversx/devcontainer-smart-contracts-rust:latest -f ./resources/smart-contracts-rust/Dockerfile
```

### Test the templates
Expand All @@ -137,14 +138,14 @@ cp -R "src/smart-contracts-rust/.devcontainer" "/tmp/test-workspace" && \
code "/tmp/test-workspace/"
```

Then, in VSCode, launch the command `Dev Containers: Rebuild and Reopen in Container`, wait, then inspect the environment (e.g. check version of `mxpy`, `rust`, build the sample smart contracts, verify output of rust-analyzer).
Then, in VSCode, launch the command `Dev Containers: Rebuild and Reopen in Container`, wait, then inspect the environment. For example, check version of `mxpy`, `rust`, `sc-meta`, build the sample smart contracts, verify output of `rust-analyzer`.

### Publish images

Locally:

```
docker build ./resources/smart-contracts-rust -t multiversx/devcontainer-smart-contracts-rust:latest -f ./resources/smart-contracts-rust/Dockerfile
docker build --network=host ./resources/smart-contracts-rust -t multiversx/devcontainer-smart-contracts-rust:latest -f ./resources/smart-contracts-rust/Dockerfile
docker push multiversx/devcontainer-smart-contracts-rust:latest
```

Expand Down
9 changes: 5 additions & 4 deletions resources/smart-contracts-rust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ ARG USERNAME=developer
ARG USER_UID=1000
ARG USER_GID=$USER_UID

ARG VERSION_MXPY="v7.2.1"
ARG VERSION_RUST="nightly-2023-04-24"
ARG VERSION_MXPY="v8.1.0"
ARG VERSION_RUST="nightly-2023-05-26"
ARG VERSION_WASM_OPT="version_112"
ARG VERSION_VMTOOLS="v1.4.60"

Expand All @@ -24,7 +24,9 @@ RUN apt-get update && apt-get install -y \
wget \
build-essential \
python3.10 python3-pip \
git && \
git \
pkg-config \
libssl-dev && \
rm -rf /var/lib/apt/lists/*

# Switch to regular user
Expand Down Expand Up @@ -53,7 +55,6 @@ ENV CARGO_HOME="${MULTIVERSX}/vendor-rust"
ENV RUSTUP_HOME="${MULTIVERSX}/vendor-rust"

RUN rustup component add rustfmt && rm -rf ${MULTIVERSX}/vendor-rust/registry/*
RUN cargo install multiversx-sc-meta && rm -rf ${MULTIVERSX}/vendor-rust/registry/*

# This command will be executed once the devcontainer is created
COPY "post_create_command.py" "${MULTIVERSX}/devcontainer-resources/"
2 changes: 1 addition & 1 deletion src/smart-contracts-rust/devcontainer-template.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "smart-contracts-rust",
"version": "0.1.5",
"version": "0.1.6",
"name": "MultiversX: Smart Contracts Development (Rust)",
"description": "Develop smart contracts for MultiversX. Includes Rust, mxpy, VSCode extensions etc.",
"documentationURL": "https://github.com/multiversx/mx-template-devcontainers/blob/main/src/smart-contracts-rust",
Expand Down

0 comments on commit 25d3e77

Please sign in to comment.