Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: single crate #22

Merged
merged 8 commits into from
Nov 27, 2023
Merged
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
File renamed without changes.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "CI"

on:
workflow_dispatch:
pull_request:
push:
branches:
- "main"

jobs:
check:
name: "Check"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "dtolnay/rust-toolchain@stable"
- run: "cargo check"

fmt:
name: "Rustfmt"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "dtolnay/rust-toolchain@nightly"
with:
components: "rustfmt"
- run: "cargo +nightly fmt --all -- --check"

clippy:
name: "Clippy"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- uses: "dtolnay/rust-toolchain@nightly"
with:
components: "clippy"
- run: "cargo clippy -- -D warnings"
28 changes: 18 additions & 10 deletions .github/workflows/deploy-merkle-api.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
name: "Deploy Merkle API on Vercel"

env:
PACKAGE_NAME: "@sablier/v2-merkle-api"
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}

on:
workflow_dispatch:

# This probably requires a Linux image to be created
# Some experiments are still required re. prebuilt deployments (https://github.com/vercel-community/rust#prebuilt-deployments)

jobs:
deploy:
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"

- name: "Install Rust target for Linux"
run: "rustup target add x86_64-unknown-linux-gnu"
- name: "Install Rust with the musl target"
uses: "moonrepo/setup-rust@v1"
with:
targets: "x86_64-unknown-linux-musl"

- name: "Install musl-tools to provide musl-gcc"
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: "musl-tools"
version: "1.0"

- name: Install Vercel CLI
run: "npm install --global vercel"
# See https://github.com/vercel-community/rust/issues/134
- name: "Add Cargo config file"
run: |
mkdir -p .cargo
echo '[build]' > .cargo/config.toml
echo 'target = "x86_64-unknown-linux-musl"' >> .cargo/config.toml

- name: "Vercel: pull environment"
run: "npx vercel pull --environment=production --token=$VERCEL_TOKEN --yes"

- name: "Vercel: build project artifacts for ${{env.PACKAGE_NAME}}"
- name: "Vercel: build project artifacts for v2-merkle-api"
run: "npx vercel build --prod --token=$VERCEL_TOKEN"

- name: "Deploy to Vercel"
run: "vercel deploy --prod --prebuilt --token=$VERCEL_TOKEN"
run: "npx vercel deploy --prod --prebuilt --token=$VERCEL_TOKEN"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# directories
.vercel
**/target
target

# files
.env
2 changes: 1 addition & 1 deletion apps/merkle-api/.vercelignore → .vercelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# directories
target/
target
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 52 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
[workspace]
resolver = "2"
members = ["apps/*"]
[[bin]]
name = "create"
path = "api/create.rs"
[[bin]]
name = "eligibility"
path = "api/eligibility.rs"
[[bin]]
name = "health"
path = "api/health.rs"
[[bin]]
name = "validity"
path = "api/validity.rs"

[package]
authors = ["Sablier Labs Ltd <contact@sablier.com>"]
description = "A web API for generating and verifying Merkle trees used in Sablier V2"
edition = "2021"
homepage = "https://github.com/sablier-labs/v2-merkle-api"
name = "sablier_merkle_api"
version = "0.0.1"

[profile.release]
opt-level = 3

[dependencies]
bytes = "1.5"
chrono = "0.4"
csv = "1.1"
dotenvy = "0.15"
ethers-rs = "0.2"
futures = "0.3"
hex = "0.4"
merkle-tree-rs = "0.1"
multipart = "0.18"
openssl = { version = "0.10", features = ["vendored"] }
regex = "1.9"
reqwest = { version = "0.11", features = ["json", "multipart"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.24", features = ["full"] }
url = "2.4"
vercel_runtime = "1.1"
warp = "0.3"
warp_lambda = "0.1"

[dependencies.uuid]
features = [
"fast-rng", # Use a faster (but still sufficiently random) RNG
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
"v4", # Lets you generate random UUIDs
]
version = "1.4"
42 changes: 14 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
# Sablier V2 Services [![Discord][discord-badge]][discord] [![Twitter][twitter-badge]][twitter]
# Sablier V2 Merkle API [![Discord][discord-badge]][discord] [![Twitter][twitter-badge]][twitter]

[discord]: https://discord.gg/bSwRCwWRsT
[discord-badge]: https://dcbadge.vercel.app/api/server/bSwRCwWRsT?style=flat
[twitter]: https://twitter.com/Sablier
[twitter-badge]: https://img.shields.io/twitter/follow/Sablier?label=%40Sablier

Web services that extend the functionality of the Sablier V2 token distribution protocol.
A web API for generating and verifying Merkle trees used in Sablier V2.

For more details about Sablier, check out our [website](https://sablier.com) and our
[documentation](https://docs.sablier.com).

## Usage

In the [`apps/merkle-api`](./apps/merkle-api/) directory, you will find an `.env.example` file that looks like this:
In order to make the API work properly, you will need to create a `.env` file by following the `.env.example` file:

```text
PINATA_API_KEY=
PINATA_SECRET_API_KEY=
IPFS_GATEWAY=
```

In order to make the API work properly you will need to create a .env file at the same level with the .env.example.
After a campaign is validated and created we use Pinata to upload and in the file to IPFS. In order to obtain the
PINATA_API_KEY and PINATA_SECRET_API_KEY follow this steps:
After a campaign is created via the API, we use Pinata to upload and pin the file to IPFS. In order to obtain the
`PINATA_API_KEY` and `PINATA_SECRET_API_KEY`, follow this steps:

1. Sign up or log in on https://app.pinata.cloud/
1. Select the API Keys tab
Expand All @@ -32,9 +31,9 @@ PINATA_API_KEY and PINATA_SECRET_API_KEY follow this steps:
1. Click Create Key
1. From the popup, take the API Key and the API Secret and put them in the `.env` file. The `IPFS_GATEWAY` variable can
be any IPFS gateway but we recommend using a private one (Pinata offers this as well). For more details about the
interactions with IPFS, check [`apps/merkle-api/src/services/ipfs.rs`](./apps/merkle-api/src/services/ipfs.rs).
interactions with IPFS, check [`src/services/ipfs.rs`](./src/services/ipfs.rs).

We use Vercel for hosting, and this is why we have separate binaries for each endpoint. To run locally, you can use this
We use Vercel for hosting, and this is why we have separate binaries for each endpoint. To run locally, use this
command:

```sh
Expand All @@ -44,36 +43,31 @@ $ vercel dev
Or, to simulate the cloud environment locally:

```sh
$ cd apps/merkle-api
$ cargo run --bin sablier_merkle_api
```

This command will run a standard web API and expose it on port 8000 on localhost. Even tough we are using Cargo
workspaces, the `cargo run` command should be run from inside the [`apps/merkle-api`](./apps/merkle-api) directory in
order to properly use the `.env` files.
This command will run a standard web API and expose it on port 8000 on localhost.

### Local Development

The `.cargo/config.toml` file is used strictly for Vercel, so you can remove it during local development. However, if
you would prefer not to remove it and you happen to use macOS, configure your `config.toml` file like this:

```sh
```toml
[build]
#target = "x86_64-unknown-linux-gnu"
#target = "x86_64-unknown-linux-gnu"

[target.x86_64-unknown-linux-musl]
linker = "x86_64-unknown-linux-gnu-gcc"
linker = "x86_64-unknown-linux-gnu-gcc"
```

Alternatively, on Linux:

```sh
[build]
target = "x86_64-unknown-linux-gnu"
target = "x86_64-unknown-linux-gnu"
```

Now you can start making changes.

## API

Do not add trailing slashes to the API endpoints.
Expand Down Expand Up @@ -111,17 +105,9 @@ $ cargo build
To run the app locally, you can use this command:

```sh
$ cd apps/merkle-api
$ cargo run --bin sablier_merkle_api
```

To add another crate, you can use this command:

```sh
$ cd apps/merkle-api
$ cargo add crate_name
```

### CSV

You can an example of a Rust CSV Generator here:
Expand All @@ -130,8 +116,8 @@ https://gist.github.com/gavriliumircea/2a9797f207a2a2f3832ddaa376337e8c

## Contributing

Feel free to dive in! [Open](https://github.com/sablier-labs/v2-services/issues/new) an issue,
[start](https://github.com/sablier-labs/v2-services/discussions/new) a discussion or submit a PR.
Feel free to dive in! [Open](https://github.com/sablier-labs/v2-merkle-api/issues/new) an issue,
[start](https://github.com/sablier-labs/v2-merkle-api/discussions/new) a discussion or submit a PR.

### Pre Requisites

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions apps/merkle-api/.cargo/config.toml

This file was deleted.

51 changes: 0 additions & 51 deletions apps/merkle-api/Cargo.toml

This file was deleted.

2 changes: 1 addition & 1 deletion apps/merkle-api/index.html → index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Sablier V2 Services</title>
<title>Sablier V2 Merkle API</title>
</head>
<body
style="
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading