IoTone / substrate-coffee-supplychain

A Coffee Supply Chain example based on A fork of the blockchain project substrate-enterprise-sample-v3 (Polkadot)
Apache License 2.0
0 stars 1 forks source link
blockchain polkadot substrate

Substrate & FRAME Supply Chain Sample

Forked from https://github.com/IoTone/substrate-enterprise-sample-v3

Overview

This sample project demonstrates how the Substrate framework for building blockchains and its standard FRAME library for runtime development can be used to quickly build an ergonomic, end-to-end, blockchain-based application. This sample includes a custom front-end that was created from the helpful Substrate Front-End Template, which itself makes use of the powerful Polkadot{JS} API. The chain in this sample is a fork of the official Substrate Node Template - a supported starting point that decreases the time it takes to implement a custom next-generation blockchain.

The use case that this sample demonstrates is a decentralized supply-chain consortium. In order to accomplish this, FRAME is used to implement custom business logic as well as existing standards, such as decentralized identifiers (DIDs).

The capabilities demonstrated by this project include:

The sample demonstrates many features and capabilities of the Substrate framework, including:

Run

The provided cargo run command will launch a temporary node and its state will be discarded after you terminate the process. After the project has been built, there are other ways to launch the node.

Single-Node Development Chain This command will start the single-node development chain with non-persistent state:

./target/release/node-template --dev Purge the development chain's state:

./target/release/node-template purge-chain --dev Start the development chain with detailed logging:

RUST_BACKTRACE=1 ./target/release/node-template -ldebug --dev Development chain means that the state of our chain will be in a tmp folder while the nodes are running. Also, alice account will be authority and sudo account as declared in the genesis state. At the same time the following accounts will be prefunded:

Alice Bob Alice//stash Bob//stash In case of being interested in maintaining the chain' state between runs a base path must be added so the db can be stored in the provided folder instead of a temporal one. We could use this folder to store different chain databases, as a different folder will be created per different chain that is ran. The following commands shows how to use a newly created folder as our db base path.

// Create a folder to use as the db base path
$ mkdir my-chain-state

// Use of that folder to store the chain state
$ ./target/release/node-template --dev --base-path ./my-chain-state/

// Check the folder structure created inside the base path after running the chain
$ ls ./my-chain-state
chains
$ ls ./my-chain-state/chains/
dev
$ ls ./my-chain-state/chains/dev
db keystore network

Running the Demo

Follow the [installation instructions](https://substrate.dev/docs/en/knowledgebase/getting-started

This demo also uses Node.js and Yarn, so ensure that those dependencies are installed before continuing.

Run multiple nodes

please read the official documentation of substrate (https://docs.substrate.io/tutorials/v3/private-network/)

Guided Demo

This guided demo will walk through a simplified version of the steps performed by the initialization script. The demo makes use of a number of well-known development accounts. In order to understand the demo's steps, it's necessary to understand the runtime modules (pallets) that inform the supply chain application and how they relate to each other.

Project Components

The supply chain consortium application is comprised of a number of a modules, many of which are configured in the chain specification's development_config function:

Demo Steps

  1. Navigate to the locally deployed instance of the demo UI, which should be running at http://localhost:8000/demo. Notice that the UI has an account selector that default to the Alice account. This is important due to the special permissions that were configured for Alice in the chain specification file.

    account selector

  2. Use the Members tab to create the Execute permission for three pallets: registrar, productRegistry, and productTracking.

    create roles

  3. Assign the three newly created roles to Bob, whose address is 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty. This will allow Bob to create an organization, products, shipments, and shipment events.

    assign roles

    Note: use this link to navigate to the Polkadot{JS} Apps UI and configure it to connect to the local supply chain network: https://polkadot.js.org/apps/#/explorer?rpc=ws://127.0.0.1:9944. Use the block hash provided by the supply chain UI to inspect the block that contained a transaction.

    Polkadot{JS} Apps UI

  4. Use the account selector to switch to Bob's account, and then go back to the Organizations tab to create an organization.

    create org

  5. Navigate to the Raw material tab and create raw material.

    create rawMaterial

  6. Use the Process tab to create register a new process whit the raw material that were created in the previous step, the input amount is how much of the raw material you want to use, and the produced is the material created for in process (then you can use that produced amount to retail packaging or to create a new raw material for another process)

    create process

  7. Navigate to the raw material tab and use the previous step created, this will create a new raw material for another step

    pickup shipment

  8. Navigate to the Process tab and you will can continue with another process with the input of the previously raw material scan shipment

    1. Navigate to the retail Packaging tab when you want to create the products for sale, you will have to select the process where the material comes from, and the amount of product that you want to create, as well you will have to introduce a unique SKU and all the others requeriodes fields scan shipment

    2. And if you go to sale tab, you can create a new sale, where you will select the sku of the product to sale, the amount of product and the buyer scan shipment

    IN EVERY STEP YOU CAN TRACK ALL THE MATERIALS, PROCESS, PACKAGINGS AND SALES

    Toolchain

    • Use rustup: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    • Configure your rust: source ~/.cargo/env
    • rustup update
    • rustup update nightly
    • rustup target add wasm32-unknown-unknown --toolchain nightly

    Cross Compiling

    To use the software on other platforms, you will need to set up a cross compiler. See instructions below.

    • install the cross compile of the target on your system, add the new target to the toolchain and compile with the target flag, all the explication here (https://rust-lang.github.io/rustup/cross-compilation.html) the target of arm for the rust toolchain are armv7-unknown-linux-gnueabihf or armv7-unknown-linux-musleabihf

    Espressobin Ultra

    From the Mac, install:

    • brew tap messense/macos-cross-toolchains
    • brew install aarch64-unknown-linux-gnu
    • rustup target add aarch64-unknown-linux-gnu
    • in the chain/.cargo/config file, uncomment both lines

    From Windows, install:

    Raspi 4

    TODO

    See: https://chacin.dev/blog/cross-compiling-rust-for-the-raspberry-pi/

    Performance, storage and ram usage

    1. Some tests were done with 1 cpu to know the build time and the final space
  9. whit this specs of the host pc specs

  10. a virtual machine was created with 1 cpu and two different configurations

  11. the first is with the cpu limit at 100% cpu limit 100

  12. the other one is limiting the cpu to 50% of his power cpu limit 50

  13. and the result was cpu limit 50 result

  14. the total space is space

  15. The amount of ram usage when the node is runing is about 79 MB

  16. Amount whit 1gb of ram space

  17. Amount whit 2gb of ram space

Related Github Repositories

Disclaimer

This project is intended for demonstration purposes and is not audited or ready for production use and was based on (https://github.com/IoTone/substrate-enterprise-sample-v3)

also some of the documentation is based in the node template example' readme of substrate(https://github.com/substrate-developer-hub/substrate-node-template#readme)