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

Introduce the Sway-Libs Book #225

Merged
merged 19 commits into from
Apr 5, 2024
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
24 changes: 0 additions & 24 deletions .docs/contributing-book/src/SUMMARY.md

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
project: [".docs/contributing-book/src/code"]
project: ["docs/contributing-book/src/code"]
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Docs

on:
pull_request:
paths:
- docs/**

jobs:
test:
uses: FuelLabs/github-actions/.github/workflows/mdbook-docs.yml@master
with:
docs-src-path: 'docs/book/src'
spellcheck-config-path: 'docs/book/.spellcheck.yml'

24 changes: 22 additions & 2 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,33 @@ jobs:
with:
mdbook-version: "0.4.15"

- run: mdbook build ./.docs/contributing-book
- run: mdbook build ./docs/contributing-book

- name: Deploy master
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./.docs/contributing-book/book
publish_dir: ./docs/contributing-book/book
destination_dir: contributing-book
if: github.ref == 'refs/heads/master'

deploy-book:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: "0.4.15"

- run: mdbook build ./docs/book

- name: Deploy master
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/book/book
destination_dir: book
if: github.ref == 'refs/heads/master'

Expand Down
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".docs/sway-libs-logo-dark-theme.png">
<img alt="SwayLibs logo" width="400px" src=".docs/sway-libs-logo-light-theme.png">
<source media="(prefers-color-scheme: dark)" srcset="docs/sway-libs-logo-dark-theme.png">
<img alt="SwayLibs logo" width="400px" src="docs/sway-libs-logo-light-theme.png">
</picture>
</p>

Expand Down Expand Up @@ -29,32 +29,40 @@ These libraries contain helper functions and other tools valuable to blockchain
> **NOTE:**
> Sway is a language under heavy development therefore the libraries may not be the most ergonomic. Over time they should receive updates / improvements in order to demonstrate how Sway can be used in real use cases.

### Libraries
## Sway Libs Book

Please refer to the [Sway Libs Book](https://fuellabs.github.io/sway-libs/book/index.html) for documentation for a general overview on Sway Libs and how to implement libraries.

## Sway Docs

For implementation details on the libraries please see the [Sway Libs Docs](https://fuellabs.github.io/sway-libs/master/sway_libs/).

## Libraries

#### Assets

- [Native Asset](./libs/src/asset/) provides helper functions for the [SRC-20](https://github.com/FuelLabs/sway-standards/tree/master/standards/src20-native-asset), [SRC-3](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_3), and [SRC-7](https://github.com/FuelLabs/sway-standards/tree/master/standards/src_7) standards.
- [Native Asset](https://fuellabs.github.io/sway-libs/book/documentation/libraries/asset/index.html) provides helper functions for the [SRC-20](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-20.md), [SRC-3](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-3.md), and [SRC-7](https://github.com/FuelLabs/sway-standards/blob/master/SRCs/src-7.md) standards.

#### Access Control and Security

- [Ownership](./libs/src/ownership/) is used to apply restrictions on functions such that only a **single** user may call them.
- [Admin](./libs/src/admin/) is used to apply restrictions on functions such that only a select few users may call them like a whitelist.
- [Pausable](./libs/src/pausable/) allows contracts to implement an emergency stop mechanism.
- [Reentrancy](./libs/src/reentrancy) is used to detect and prevent reentrancy attacks.
- [Ownership](https://fuellabs.github.io/sway-libs/book/documentation/libraries/ownership/index.html) is used to apply restrictions on functions such that only a **single** user may call them.
- [Admin](https://fuellabs.github.io/sway-libs/book/documentation/libraries/admin/index.html) is used to apply restrictions on functions such that only a select few users may call them like a whitelist.
- [Pausable](https://fuellabs.github.io/sway-libs/book/documentation/libraries/pausable/index.html) allows contracts to implement an emergency stop mechanism.
- [Reentrancy](https://fuellabs.github.io/sway-libs/book/documentation/libraries/reentrancy/index.html) is used to detect and prevent reentrancy attacks.

#### Cryptography

- [Bytecode](./libs/src/bytecode/) is used for on-chain verification and computation of bytecode roots for contracts and predicates.
- [Merkle Proof](./libs/src/merkle/) is used to verify Binary Merkle Trees computed off-chain.
- [Bytecode](https://fuellabs.github.io/sway-libs/book/documentation/libraries/bytecode/index.html) is used for on-chain verification and computation of bytecode roots for contracts and predicates.
- [Merkle Proof](https://fuellabs.github.io/sway-libs/book/documentation/libraries/merkle/index.html) is used to verify Binary Merkle Trees computed off-chain.

#### Math

- [Fixed Point Number](./libs/src/fixed_point/) is an interface to implement fixed-point numbers.
- [Signed Integers](./libs/src/signed_integers/) is an interface to implement signed integers.
- [Fixed Point Number](https://fuellabs.github.io/sway-libs/book/documentation/libraries/fixed_point/index.html) is an interface to implement fixed-point numbers.
- [Signed Integers](https://fuellabs.github.io/sway-libs/book/documentation/libraries/signed_integers/index.html) is an interface to implement signed integers.

#### Data Structures

- [Queue](./libs/src/queue/) is a linear data structure that provides First-In-First-Out (FIFO) operations.
- [Queue](https://fuellabs.github.io/sway-libs/book/documentation/libraries/queue/index.html) is a linear data structure that provides First-In-First-Out (FIFO) operations.

## Using a library

Expand All @@ -79,6 +87,8 @@ For example, to import the `only_owner()` function use the following statement:
use sway_libs::ownership::only_owner;
```

For more information about implementation please refer to the [Sway Libs Book](https://fuellabs.github.io/sway-libs/book/index.html)

## Running Tests

There are two sets of tests that should be run: inline tests and sdk-harness tests.
Expand All @@ -100,7 +110,7 @@ forc test && cargo test
```

> **NOTE:**
> This may take a while depending on your hardware, future improvements to Sway will decrease build times. After this has been run once, indiviual test projects may be built on their own to save time.
> This may take a while depending on your hardware, future improvements to Sway will decrease build times. After this has been run once, individual test projects may be built on their own to save time.

Any instructions related to using a specific library should be found within the README.md of that library.

Expand All @@ -109,4 +119,4 @@ Any instructions related to using a specific library should be found within the

## Contributing

Check out the [book](https://fuellabs.github.io/sway-libs/book/index.html) for more info!
Check out the [book](https://fuellabs.github.io/sway-libs/contributing-book/index.html) for more info!
File renamed without changes.
29 changes: 29 additions & 0 deletions docs/book/.spellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
matrix:
- name: SPCheck
aspell:
lang: en
dictionary:
encoding: utf-8
wordlists:
- docs/book/spell-check-custom-words.txt
pipeline:
- pyspelling.filters.context:
context_visible_first: true
escapes: \\[\\`~]
delimiters:
# Ignore all code blocks
- open: '(?s)^(?P<open> *`{3,}\s*(\w+\s*,?\s*)+.*?)$'
close: '^( *`{3,})$'
- pyspelling.filters.markdown:
markdown_extensions:
- pymdownx.superfences:
- pyspelling.filters.html:
comments: false
ignores:
- code
- pre
sources:
- '**/book/src/*.md'
- '**/book/src/**/*.md'
default_encoding: utf-8

28 changes: 28 additions & 0 deletions docs/book/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Installation

If you wish to alter the documentation presented in this book then follow the following instructions.

1. Install [Rust](https://www.rust-lang.org/tools/install) if it's not installed.
2. Install [mdbook](https://rust-lang.github.io/mdBook/).

```bash
cargo install mdbook
```

3. To [build](https://rust-lang.github.io/mdBook/cli/build.html) the book make sure that you are in `/.docs/book` and run

```bash
mdbook build
```

4. To develop the book in real time, in the browser, run

```bash
mdbook serve --open
```

## How to edit the book

Each page is written in markdown so there's not much to learn specifically for `mdbook` but you're free to read their documentation for additional information.

If you wish to add a new page then it must be listed in the [SUMMARY.md](src/SUMMARY.md).
14 changes: 14 additions & 0 deletions docs/book/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[book]
authors = ["Fuel Labs <[email protected]>"]
language = "en"
multilingual = false
src = "src"
title = "Sway Libraries"

[output.html]
git-repository-url = "https://github.com/FuelLabs/sway-libs"

[preprocessor.forc-documenter]

[rust]
edition = "2021"
Loading
Loading