massalabs / DeWeb

On-chain Decentralized Web Gateway
MIT License
2 stars 1 forks source link

Create SC for Decentralized lists #139

Open damip opened 1 month ago

damip commented 1 month ago

A simple decentralized list tool

A simple decentralized tool to make lists.

Smart contract

Datastore layout

In the datastore we simply have one entry per entry of the list list_name:

["dlist"][len(list_name)][list_name][key] -> [value]  // note that len(list_name) is a constant-size integer that prevents key collisions when we have list names of various lengths

Smart contract interface:

read_item(list: Vec<u8>, key: Vec<u8>) -> Vec<u8>
    reads the value of an item, fails if does not exist

item_exists(list: Vec<u8>, key: Vec<u8>) -> bool
    checks if an item exists

remove_item(list: Vec<u8>, key: Vec<u8>)
    owner only
    removes an item, fails if does not exist

insert_item(list: Vec<u8>, key: Vec<u8>, value: Vec<u8>)
    owner only
    overwrites if exists

Web interface

A simple two-step interface: