Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
Cargo.lock
**/target
**/Cargo.lock
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ sha2 = "0.10.9"

[dev-dependencies]
bitcoinkernel = "0.0.22"


[workspace]
members = [
"examples"
]
36 changes: 36 additions & 0 deletions Dockerfile.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM ubuntu:24.04 AS builder

ARG RUST=1.89.0
ARG ZIG_VER=0.14.1
ARG TARGET=aarch64-unknown-linux-musl

RUN apt-get update && apt-get install -y \
curl xz-utils cmake libboost1.83-dev libclang-17-dev \
&& rm -rf /var/lib/apt/lists/*

RUN curl -fSL "https://ziglang.org/download/${ZIG_VER}/zig-aarch64-linux-${ZIG_VER}.tar.xz" -o /tmp/zig.tar.xz \
&& tar -C /opt -xJf /tmp/zig.tar.xz \
&& mv /opt/zig-aarch64-linux-* /opt/zig \
&& ln -sf /opt/zig/zig /usr/local/bin/zig \
&& rm /tmp/zig.tar.xz

RUN curl -sSf https://sh.rustup.rs | RUSTUP_INIT_SKIP_PATH_CHECK=yes sh -s -- -y --profile minimal --default-toolchain "${RUST}" \
&& /root/.cargo/bin/rustup target add "${TARGET}" \
&& /root/.cargo/bin/cargo install --locked cargo-zigbuild
ENV PATH="/root/.cargo/bin:${PATH}"

ENV ZIG_TARGET=aarch64-linux-musl
ENV CC="zig cc -target ${ZIG_TARGET}"
ENV CXX="zig c++ -target ${ZIG_TARGET}"
ENV CXXFLAGS="-UNDEBUG"

WORKDIR /app
COPY . ./

ENV Boost_DIR=/usr/lib/aarch64-linux-gnu/cmake/Boost-1.83.0

RUN cargo zigbuild --release --target aarch64-unknown-linux-musl -p examples --bin covenants_example
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice example using Zig.


FROM alpine:3.22.1
COPY --from=builder /app/target/*/release/covenants_example /covenants_example
CMD ["/covenants_example","--port","5005"]
18 changes: 18 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "examples"
version = "0.0.1"
edition = "2021"
publish = false

[[bin]]
name = "covenants_example"
path = "src/covenants_example.rs"

[dependencies]
bitcoin = { version = "0.32.7", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
vsock = "0.5.1"
serde_json = "1.0"
bitcoinkernel-covenants = "0.0.23"
confidential-script-lib = { path = "../" }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My instinct is that examples should point to the latest version of the published library. That way users can just copy the example and run it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated Cargo.toml to use the latest verson of the bitcoinkernel-covenats crate with this commit 6cacaa6

hex = "0.4.3"
39 changes: 39 additions & 0 deletions examples/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Covenants Example

> **Experimental build using [`bitcoinkernel-covenants`](https://github.com/stutxo/rust-bitcoinkernel-covenants)** with OP_CAT, OP_CSFS and OP_CTV enabled
> Not intended for production use. Use at your own risk.

## Run Tests

```bash
cargo test
```

## Build Docker Image for Nitro Enclave

```bash
docker build -f Dockerfile.example -t covenants-example .
```

## Build and Run Nitro Enclave

```bash
# Build the enclave image
nitro-cli build-enclave \
--docker-uri covenants-example \
--output-file covenants_example.eif

# Run the enclave with specified CPU, memory, and CID
nitro-cli run-enclave \
--cpu-count 2 \
--memory 512 \
--enclave-cid 16 \
--eif-path covenants_example.eif \
--debug-mode

# Inspect running enclaves
nitro-cli describe-enclaves

# Connect to the enclave console (replace <id> with the Enclave ID)
nitro-cli console --enclave-id <id>
```
Loading