Rust Engineer

Antonio

yanganto@Github

2021/11/03 Hackthon @OnAir

Key Value Storage

with SewUp

Hackathon

Intro

SewUp

  • Rust crate
  • Open source at Github
  • Utilize Ethereum WebAssembly
  • Contract Dev as Backend (CDAB)
  • Rusty api
  • Learn more with previous slides

Key Value Storage

Let's SewUp

Hangman

  • A game for learning phrase
  • Sample code
  • Use Sewup kv feature

Hangman picture is licensed under CC BY-NC-SA 3.0

Rules

  1. Every account can set only a word as the puzzle, a sentence as the reward for people solve the puzzle, and a hint for people
  2. Everyone can get the information of the puzzle (the length of words and the hint).
  3. Everyone guess one char, for example p, and he will get a partial string like -pp--.
  4. Everyone can guess the word, if correct, he will see the sentence.

Init project

  1. Install Rust
    curl --proto '=https' --tlsv1.2 -sSf \ https://sh.rustup.rs | sh
  2. Install cargo sewup
    cargo install cargo-sewup
  3. Initialize project
    cargo sewup init -m rusty
  4. Add kv feature
    features = [ "kv" ]

Check out Commit f82cceb

Check out Commit 90ee3a3

Hangman picture is licensed under CC BY-NC-SA 3.0

Setup constructor

Check out Commit 52832e4

Objective

  1. Define datastructure
  2. Initialize storage when deploy
  1. Every account can set only a word as the puzzle, a sentence as the reward for people solve the puzzle, and a hint for people

Hangman picture is licensed under CC BY-NC-SA 3.0

Setup constructor

Check out Commit 52832e4

  1. Use cargo test to validate you code
  2. If _compile_runtime_test fail,
    run cargo build --target=wasm32-unknown-unknown
  3. If _compile_constructor_test fail,
    run cargo build --features=constructor --target=wasm32-unknown-unknown

Tips for developing constructor

Hangman picture is licensed under CC BY-NC-SA 3.0

Setup Puzzle

Check out Commit 11bf360

Objective

  1. Handle the data from client ewasm_input_from!
  2. Storage data on chain, commit
  3. Test with specific caller, by

Hangman picture is licensed under CC BY-NC-SA 3.0

Get Puzzle Info

Check out Commit 8726c45

Objective

  1. Use EwasmAny for return different
  2. Initial Input structure, just like form in HTTP

Hangman picture is licensed under CC BY-NC-SA 3.0

Guess Char

Check out Commit 5b8cd22

Objective

  1. Modify the Input structure
  2. Initial Input structure, just like form in HTTP
  3. Update testcase

Hangman picture is licensed under CC BY-NC-SA 3.0

Guess Word

Check out Commit 12a6ad4

Objective

  1. Modify the Input structure
  2. Initial Input structure, just like form in HTTP
  3. Update testcase

Hangman picture is licensed under CC BY-NC-SA 3.0

Well Done

Really Easy with SewUp

It's Your Turn

Validate Puzzle

  • Prevent a puzzle with phrase or sentence
  • Issue #1
  • O Apple
  • X An apple a day

Introduce thiserror

  • Try to introduce thiserror crate
  • Issue #2
  • X anyhow::anyhow!("message")
  • X panic!("message")

Summary

Blockchain bring TRUST to the world

Rust is the stem of TRUST

SewUp base on Rust and Ewasm helps you build great blockchain applications

Thanks for listening

Star the project if you like it

There are also help want issues and good first issues

Interested in VM?

WasmEdge is welcom to contribute

Q&A

Sewup sew your ethereum project up to the world

Writing Ethereum WebAssembly in Rust II - Key Value Storage with SewUp

By Antonio Yang

Writing Ethereum WebAssembly in Rust II - Key Value Storage with SewUp

Secondstate EWasm Utility Program, a library to help you to write Ethereum WebAssmbly in Rust

  • 1,143