Giter Club home page Giter Club logo

lab1-vdikan-canvas's Introduction

lab1-vdikan-canvas

Demo contract: Painting pixels on a Canvas with time lock.

Deployment

Run ./build.sh located in the project root. It compiles ./out/main.wasm.

The canvas width and height are contract initialization parameters and should be set upon initial deployment, e.g.:

near dev-deploy --initFunction new --initArgs '{"width":20, "height":20}'

Contract Views

get_pixel(x: usize, y: usize)

Return the status of the pixel at (x, y): current color and if it is booked or free based on release_timestamp.

Free method.

near call @dev-account  get_pixel --args '{"x": 20, "y": 20}' --accountId @account.testnet

set_pixel(x: usize, y: usize, color: [u8, 3])

Repaint pixel at (x, y) to a new color (vector of R,G,B u8 channels), if it is not held at the time of transaction.

Payable method. Minimal deposit locks pixel for 30 seconds. All the amount above buys extra time in proportion: 50 seconds for each 1 token above.

near call @dev-account set_pixel --args '{"x": 2, "y": 1, "color": [70, 90, 31]}' --accountId @account.testnet --amount=5.5

Possible Improvements

  • Storage optimization using near_sdk::collections.

    Not sure if it is worth it. Frontend will expect all the canvas data at once, therefore standard Vec<> of pixels required.

    At the same time, release_timestamps could be stored as separate array. Here Vector from near_sdk::collections may suit better.

  • JSON-serizalization of view call responses.

    That is what front-end would expect.

lab1-vdikan-canvas's People

Contributors

vdikan avatar

Watchers

 avatar Serge K Lebedev 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.