GithubHelp home page GithubHelp logo

md_kernel_todo's Introduction

Example: Todo Item

In our second kernel, we will demonstrate how to write and read data in durable state of the rollup.

Running the example

First, compile the kernel to WASM with Cargo:

$ cargo build --release --target wasm32-unknown-unknown

Then you can execute the kernel locally against the provided inputs (empty in this example) and commands:

$ octez-smart-rollup-wasm-debugger ./target/wasm32-unknown-unknown/release/md_dev_kernel.wasm --inputs ./inputs.json <<< $(cat commands.txt)

Additionally, you can omit the <<< $(cat ./commands.txt) to enter a REPL mode and explore the execution of the kernel interactively.

In input.json

We need to provide payload of user input. You can take a look into input.json:

[
  [
    {
      "external": "0000000000000001000000000552617965720000000554657374310000000000000000000000000000000000000000055261796572"
    },
    {
      "external": "00000000000000010100000005526179657200000000000000000000000000000000000000000000000000"
    },
    {
      "external": "00000000000000010300000005526179657200000000000000000000000000000000000000000000000000"
    },
    {
      "external": "00000000000000010100000005526179657200000000000000000000000000000000000000000000000000"
    }
  ]
]

This payload can be generated from test_ta_into() in todo.rs. This 4 payloads means:

  1. Create a todo with title "Test" and author "Rayer" in key /todo/1
  2. Read this todo
  3. Mark complete of this todo
  4. Read this todo again.

Base concept is

  • Provide TodoAction and encode in external field
  • TodoAction will be decoded and execute these actions:
    • Create : Encrypt TodoAction::todo into Todo and store in key /todo/{id}
    • Read : Decrypt Todo in key /todo/{id} into TodoAction::todo, it is for debug propose only
    • MarkComplete : Decrypt Todo in key /todo/{id} into TodoAction::todo, and update TodoAction::todo.completed = true, then encrypt TodoAction::todo into Todo and store in key /todo/{id}
    • Delete : Delete key /todo/{id}

You can refer to test_ta_into() in todo.rs to see how to generate this payload.

Authentication and Authorization

You need to provide correct user in TodoAction.User in order to access Todo Item. If user is not matched, transaction will be failed for failed to decrypt Todo payload into Todo.

image

md_kernel_todo's People

Contributors

rayer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.