Skip to content

Commit

Permalink
Merge pull request #14 from multiversx/update-2024-01-31
Browse files Browse the repository at this point in the history
Update Rust, mxpy etc.
  • Loading branch information
andreibancioiu committed Feb 1, 2024
2 parents 25d3e77 + fdaaeae commit ac7b78e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Run the container and do a quick inspection:
```
${RUN} ${IMAGE} whoami
${RUN} ${IMAGE} mxpy --version
${RUN} ${IMAGE} mxpy deps check rust
${RUN} ${IMAGE} cargo --version
${RUN} ${IMAGE} rustc --version
${RUN} ${IMAGE} sc-meta --version
```

Expand All @@ -44,10 +45,10 @@ 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 --path /data/mx-contracts-rs/contracts/adder
${RUN} ${IMAGE} sc-meta all build --path /data/mx-contracts-rs/contracts/adder
stat ./mx-contracts-rs/contracts/adder/output/adder.wasm
${RUN} ${IMAGE} mxpy contract build --path /data/mx-contracts-rs/contracts/ping-pong-egld
${RUN} ${IMAGE} sc-meta all build --path /data/mx-contracts-rs/contracts/ping-pong-egld
stat ./mx-contracts-rs/contracts/ping-pong-egld/output/ping-pong-egld.wasm
```

Expand All @@ -61,32 +62,32 @@ ${RUN} ${IMAGE} mxpy contract deploy \
--recall-nonce \
--gas-limit 5000000 \
--chain D \
--proxy https://devnet2-gateway.multiversx.com \
--proxy https://devnet-gateway.multiversx.com \
--send
```

Call a function of a previously-deployed smart contract:

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

Query a smart contract:

```
${RUN} ${IMAGE} mxpy contract query \
erd1qqqqqqqqqqqqqpgqfzydqmdw7m2vazsp6u5p95yxz76t2p9rd8ss0zp9ts \
erd1qqqqqqqqqqqqqpgqr3clh6ghpww5fc4uhwh2amsseuvecswzd8ssxu68s3 \
--function "getSum" \
--proxy https://devnet2-gateway.multiversx.com
--proxy https://devnet-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
40 changes: 21 additions & 19 deletions resources/smart-contracts-rust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ ARG USERNAME=developer
ARG USER_UID=1000
ARG USER_GID=$USER_UID

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"
ARG VERSION_MXPY="v9.4.1"
ARG VERSION_RUST="nightly-2023-12-11"
ARG VERSION_SC_META="0.47.1"
ARG VERSION_WASM_OPT="0.112.0"
ARG VERSION_VMTOOLS="v1.5.24"

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
Expand All @@ -23,7 +24,7 @@ RUN groupadd --gid $USER_GID $USERNAME \
RUN apt-get update && apt-get install -y \
wget \
build-essential \
python3.10 python3-pip \
python3.10 python3-pip python3.10-venv \
git \
pkg-config \
libssl-dev && \
Expand All @@ -33,28 +34,29 @@ RUN apt-get update && apt-get install -y \
USER $USERNAME
WORKDIR /home/${USERNAME}

# Create "~/multiversx-sdk"
ENV MULTIVERSX=/home/${USERNAME}/multiversx-sdk
RUN mkdir ${MULTIVERSX}
ENV MULTIVERSX="/home/${USERNAME}/multiversx-sdk"
ENV PATH="/home/${USERNAME}/.local/bin:${PATH}"
ENV PATH="/home/${USERNAME}/.cargo/bin:${PATH}"
ENV PATH="${MULTIVERSX}/vmtools:${PATH}"

# Install pipx
RUN python3 -m pip install --no-cache-dir --user pipx

# Install mxpy
RUN pip3 install --no-cache-dir https://github.com/multiversx/mx-sdk-py-cli/archive/refs/tags/${VERSION_MXPY}.zip
ENV PATH="${MULTIVERSX}:${PATH}"
COPY "mxpy" "${MULTIVERSX}/mxpy"
RUN pipx install multiversx-sdk-cli==${VERSION_MXPY}

# Install rust and other tools
RUN mxpy deps install rust --tag=${VERSION_RUST} && rm -rf ${MULTIVERSX}/vendor-rust/registry/*
RUN mxpy deps install wasm-opt --tag=${VERSION_WASM_OPT} && rm ${MULTIVERSX}/*.tar.gz
RUN mxpy deps install vmtools --tag=${VERSION_VMTOOLS} && rm ${MULTIVERSX}/*.tar.gz && sudo rm -rf ${MULTIVERSX}/golang
RUN mxpy config set "dependencies.rust.tag" ${VERSION_RUST} && \
mxpy config set "dependencies.sc-meta.tag" ${VERSION_SC_META} && \
mxpy config set "dependencies.wasm-opt.tag" ${VERSION_WASM_OPT} && \
mxpy config set "dependencies.vmtools.tag" ${VERSION_VMTOOLS}
RUN mxpy deps install rust && rm -rf /home/${USERNAME}/.cargo/registry/* && rm -rf /home/${USERNAME}/.cargo/git/*
RUN mxpy deps install vmtools && rm ${MULTIVERSX}/*.tar.gz && sudo rm -rf ${MULTIVERSX}/golang

# Install test wallets
RUN mxpy deps install testwallets && rm ${MULTIVERSX}/*.tar.gz

ENV PATH="${MULTIVERSX}/vendor-rust/bin:${MULTIVERSX}/vmtools:${PATH}"
ENV CARGO_HOME="${MULTIVERSX}/vendor-rust"
ENV RUSTUP_HOME="${MULTIVERSX}/vendor-rust"

RUN rustup component add rustfmt && rm -rf ${MULTIVERSX}/vendor-rust/registry/*
RUN rustup component add rustfmt && rm -rf /home/${USERNAME}/.cargo/registry/* && rm -rf /home/${USERNAME}/.cargo/git/*

# This command will be executed once the devcontainer is created
COPY "post_create_command.py" "${MULTIVERSX}/devcontainer-resources/"
2 changes: 0 additions & 2 deletions resources/smart-contracts-rust/mxpy

This file was deleted.

6 changes: 2 additions & 4 deletions resources/smart-contracts-rust/post_create_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
prepare_vscode_settings()
prepare_gitignore()
add_samples()


def prepare_vscode_settings():
vscode_path = Path(".vscode")
Expand Down Expand Up @@ -49,8 +49,6 @@ def prepare_gitignore():
**/target/**
**/output/**
**/trace*.scen.json
Cargo.lock
!**/wasm*/Cargo.lock
""")


Expand All @@ -63,7 +61,7 @@ def add_samples():

if samples_folder.exists():
return

urllib.request.urlretrieve(archive_url, download_path)
shutil.unpack_archive(download_path, extract_path)
shutil.move(str(extract_path / contracts_in_extract_path), str(samples_folder))
Expand Down
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.6",
"version": "0.2.0",
"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 ac7b78e

Please sign in to comment.