Skip to content

Commit

Permalink
add requirements to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vlopes11 committed Nov 16, 2023
1 parent 5479a8e commit 00ec9d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# sov-snap-generator

This utility generates [Metamask Snaps](https://metamask.io/snaps/) for Sovereign SDK module implementations.
This utility creates [Metamask Snaps](https://metamask.io/snaps/) for Sovereign SDK modules.

## Requirements

- [Git](https://git-scm.com/)
- [Rust](https://www.rust-lang.org/tools/install)
- [Yarn](https://yarnpkg.com/)
- [binaryen](https://github.com/WebAssembly/binaryen)
- [wabt](https://github.com/WebAssembly/wabt)
- [Metamask Flask](https://metamask.io/flask/) (optional for development environment)

## Installation

Expand All @@ -25,7 +30,7 @@ cargo new --lib sov-runtime
cd sov-runtime
```

Then, we update the `Cargo.toml` with the following:
Next, update the `Cargo.toml` with the following:

```toml
[package]
Expand All @@ -46,13 +51,13 @@ demo-stf = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev =
sov-mock-da = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", rev = "df169be" }
```

Then, we fetch a default `constants.json`, required for module compilation:
Then, fetch the default `constants.json` required for module compilation.

```bash
wget https://raw.githubusercontent.com/Sovereign-Labs/sovereign-sdk/d42e289f26b9824b5ed54dbfbda94007dee305b2/constants.json
```

Finally, we update the `src/lib.rs` with the following:
Finally, update the `src/lib.rs` with the following:

```rust
/// The `Context` will be used to define the asymmetric key pair.
Expand All @@ -65,7 +70,7 @@ pub use sov_mock_da::MockDaSpec as DaSpec;
pub use demo_stf::runtime::RuntimeCall;
```

The utility will look, by default, for definitions of `Context`, `DaSpec`, and `RuntimeCall` at the root of the project. They, however, can be replaced by other paths.
The utility defaults to searching for `Context`, `DaSpec`, and `RuntimeCall` definitions at the project root. However, these can be replaced with other paths.

For a sanity check, run the following:

Expand All @@ -75,55 +80,55 @@ cargo check

#### Generate the Snap

Some prompts can be provided via CLI arguments. For more information, run:
Some prompts can be specified through CLI arguments. For more information, run:

```bash
sov-snap-generator --help
```

On the root of the project, run:
At the project root, execute:

```bash
sov-snap-generator
```

The first prompt will ask for the `path` of the project. It defaults to the current directory, so you can simply press `Enter`.
The first prompt will inquire about the project `path`. It defaults to the current directory, so you can simply press `Enter`.

```bash
Insert the path to your `Cargo.toml`
> /home/sovereign/sov-runtime
```

The next prompt asks for the manifest definition to use the module as dependency. It defaults to the parent directory of the resolved project manifest file.
The next prompt asks for the manifest definition to use the module as a dependency. It defaults to the parent directory of the resolved project manifest file.

The generated WASM file must have some dependencies. The next prompts will default to the dependency specified on the project manifest file, if present, and will ask for the following items, in order:
The generated WASM file requires certain dependencies. The subsequent prompts will default to the dependencies specified in the project manifest file, if present. It will then ask for the following items in order:

- Base project, usually a path pointing to the parent directory of the project manifest file.
- Base project (usually a path pointing to the parent directory of the project manifest file).
- [borsh](https://crates.io/crates/borsh)
- [serde_json](https://crates.io/crates/serde_json)
- [sov-modules-api](https://github.com/Sovereign-Labs/sovereign-sdk/tree/d42e289f26b9824b5ed54dbfbda94007dee305b2/module-system/sov-modules-api)

The next step is to define the target directory in which the generated Snap will be placed. It defaults to a new directory, neighbor to the current project, suffixed by `-snap`.
The next step is to define the target directory in which the generated Snap will be placed. It defaults to a new directory adjacent to the current project, suffixed by `-snap`.

The WASM files depends on a couple of definitions, usually customized by the module implementation. It will, by default, search the root of the project for exports of `Context`, `DaSpec`, and `RuntimeCall`. The next prompts will ask for such paths; if your implementation diverges from this standard, your just replace these items for their fully qualified paths.
The WASM file depends on specific definitions, typically customized by the module implementation. By default, it searches the root of the project for exports of `Context`, `DaSpec`, and `RuntimeCall`. The subsequent prompts will ask for these paths. If your implementation diverges from this standard, replace these items with their fully qualified paths.

The template snap will be downloaded from a github release. The next prompts queries for the repository origin and its branch/tag.
The template snap will be downloaded from a GitHub release. The next prompts inquire about the repository origin and its branch/tag.

After the installation is executed, you should see a `Snap generated on <TARGET>` message.
After the installation is executed, you should see a message indicating the project generated on `<TARGET>`.

#### Run a local development environment

Requirements: [Metamask Flask](https://metamask.io/flask/)

To start a web development environment with your Snap, run the following:
To initiate a web development environment with your Snap, execute the following:

```bash
cd ../sov-runtime-snap
yarn start
```

Your Snap will be available, by default, at `http://localhost:8000`. Click Connect/Reconnect to load the Snap into your Metamask Flask, and you can sign messages.
Your Snap will be accessible by default at http://localhost:8000. Click Connect/Reconnect to load the Snap into your Metamask Flask, enabling you to sign transactions.

This development environment will provide the possibility to submit a signed transaction to a [sov-sequencer](https://github.com/Sovereign-Labs/sovereign-sdk/tree/d42e289f26b9824b5ed54dbfbda94007dee305b2/full-node/sov-sequencer). However, most modern browsers queries external services for a [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) policy.
This development environment allows you to submit a signed transaction to a [sov-sequencer](https://github.com/Sovereign-Labs/sovereign-sdk/tree/d42e289f26b9824b5ed54dbfbda94007dee305b2/full-node/sov-sequencer). However, most modern browsers query external services for a [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) policy.

You can either disable CORS in your browser, or set a proxy that will handle the CORS requests and forward the payload to the sequencer.
You can either disable CORS in your browser or set up a proxy to handle CORS requests, forwarding the payload to the sequencer.
7 changes: 7 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ impl Interface {
if target.exists() {
if fs::remove_dir(&target).is_err() {
if !args.force {
if args.defaults {
anyhow::bail!(
"The `defaults` flag is set, but the target `{}` already exists. This operation is not permitted. To bypass this check for the `--defaults` arguments, combine it with `--force`.",
target.display()
);
}

let prompt = format!(
"The provided target `{}` is not empty and will be erased; confirm? [y/n]",
target.display()
Expand Down

0 comments on commit 00ec9d2

Please sign in to comment.