at5500 / sway-libs

Miscellaneous Sway libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwayApps logo

Overview

The purpose of this repository is to contain libraries which users can import and use that are not part of the standard library.

These libraries contain helper functions, generalized standards, and other tools valuable to blockchain development.

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

  • Binary Merkle Proof is used to verify Binary Merkle Trees computed off-chain.
  • Non-Fungible Token (NFT) is a token library which provides unqiue collectibles, identified and differentiated by token IDs.
  • Ownership is used to apply restrictions on functions such that only a single user may call them.
  • Reentrancy is used to detect and prevent reentrancy attacks.
  • String is an interface to implement dynamic length strings that are UTF-8 encoded.
  • Signed Integers is an interface to implement signed integers.
  • Unsigned Fixed Point Number is an interface to implement fixed-point numbers.
  • StorageMapVec is a temporary workaround for a StorageMap<K, StorageVec> type.

Standards

Using a library

To import the Merkle Proof library the following should be added to the project's Forc.toml file under [dependencies] with the most recent release:

merkle_proof = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.1.0" }

You may then import your desired library in your Sway Smart Contract as so:

use merkle_proof::<library_function>;

For example, to import the Merkle Proof library use the following statement:

merkle_proof::binary_merkle_proof::verify_proof;

Running Tests

In order to run the tests make sure you are in the tests folder of this repository sway-libs/tests/<you are here>.

Build the test projects:

forc build

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.

Run the tests:

cargo test

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

Note All projects currently use forc v0.35.3, fuels-rs v0.36.1 and fuel-core 0.17.3.

Contributing

Check out the book for more info!

About

Miscellaneous Sway libraries.

License:Apache License 2.0


Languages

Language:Rust 91.7%Language:JavaScript 8.3%