Skip to content

Commit

Permalink
feat: organize code as SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega committed Jan 20, 2024
1 parent 4641eca commit e31a1ab
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 32 deletions.
164 changes: 162 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
workspace = { members = ["sdk/cli"] }
[package]
name = "scrolls"
description = "Cardano Scrolls"
Expand Down
7 changes: 6 additions & 1 deletion book/src/reducers/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Reducers

- [Deno](deno.md): custom reducers in js
Scroll Reducers are Map/Reduce algorithms that turn block data into a relevant information to be queried by end-users.

There are several ways to implement reducers in Scrolls:

- [Typescript](typescript.md): using custom Typescript code to implement the map/reduce logic
- [Rust](rust.md): using custom Rust code to implement the map/reduce logic
29 changes: 0 additions & 29 deletions book/src/reducers/deno.md

This file was deleted.

27 changes: 27 additions & 0 deletions book/src/reducers/rust.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Using Rust to build custom reducers

To build reducer using Rust, we need to code our custom logic as any other Rust-based program and compile it with a WASM target. The resulting file (.wasm) can then be referenced by Scrolls configuration so that it's loaded dynamically at the moment of execution.

## Configuration

Example of a configuration

```toml
[reducer]
type = "Wasm"
main_module = "./examples/wasm/enrich.wasm"
```

### Section: `reducer`

- `type`: the literal value `Wasm`.
- `main_module`: the wasm file containing the reducer logic


## Run code

To run a custom WASM reducer, it will be necessary to trigger scrolls enabling the `wasm` feature

```sh
cargo run --features=wasm -- daemon --config ./examples/wasm/daemon.toml
```
37 changes: 37 additions & 0 deletions book/src/reducers/typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Using Typescript to build custom reducers

With the Typescript reducer is possible to create a custom reducer for logics that the builtin reducers don't have support. This reducer is only enable with the deno feature on build.

To build reducer using Typescript, we need to code our custom logic as any other Typescript module and transpile it into JS code using Deno. The resulting file (.js) can then be referenced by Scrolls configuration so that it's loaded dynamically at the moment of execution.

To transpile your Typescript code using Deno, run the following command:

```
deno bundle reducer.ts reducer.js
```

## Configuration

Example of a configuration

```toml
[reducer]
type = "Deno"
main_module = "./examples/deno/reducer.js"
use_async = true
```

### Section: `reducer`

- `type`: the literal value `Deno`.
- `main_module`: the js file with the reducer logic
- `use_async`: run the js in async mode


## Run code

To run the code with the deno will be necessary to use deno feature

```sh
cargo run --features=deno -- daemon --config ./examples/deno/daemon.toml
```
10 changes: 10 additions & 0 deletions sdk/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "4.4.18"
inquire = "0.6.2"
3 changes: 3 additions & 0 deletions sdk/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
7 changes: 7 additions & 0 deletions sdk/templates/reducer-oura-typescript/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build:
deno bundle reducer.js

run: build
oura daemon --config ./oura.toml

.PHONY: build run
14 changes: 14 additions & 0 deletions sdk/templates/reducer-oura-typescript/oura.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[source]
type = "UtxoRpc"
endpoint = "https://mainnet.utxorpc-v0.demeter.run"

[[filters]]
type = "Deno"
main_js = "reducer.js"
use_async = true

[sink]
type = "SqlTable"
mode = "SlotSeries"
table = "my_reducer_1"
connection = "sqlite://scrolls.db"
Empty file.

0 comments on commit e31a1ab

Please sign in to comment.