-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
267 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
workspace = { members = ["sdk/cli"] } | ||
[package] | ||
name = "scrolls" | ||
description = "Cardano Scrolls" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.