Code Monkey home page Code Monkey logo

offchain-metadata-server's Introduction

Cardano off-chain metadata API

A simple implementation of the offchain metadata server proposed in CIP-26 in Rust.

Abstract

The metadata registry is a github repository that holds a bunch of json files. See https://github.com/cardano-foundation/cardano-token-registry for more details.

The endpoint that servers these is located here https://tokens.cardano.org/. There are various implementations of this:

Motivation

Why another?

Existing implementations are complicated and/or implement features the CIP did not ask for. Also, they are somewhat difficult to operate because they are made up of different services.

My goal here is to have a super simple implementation that is easy to operate and scale. The metadata registry is a bunch of json files. These files are read into memory and served. The only external service there currently is, is something that automatically pulls the changes from the registry. In my current deployment i have a systemd timer running every X hours that runs a script roughly like this:

#!/bin/sh
readonly registry_path="/path/to/cardano-token-registry"
# If the repository does not exist, clone it and exit
if [ ! -d $registry_path ]; then
    mkdir -p $registry_path
    git clone --depth 1 https://github.com/cardano-foundation/cardano-token-registry.git $registry_path
    exit 0
fi
# If it does exist, pull the contents and trigger reread
if [ -d $registry_path ]; then
    cd $registry_path || exit 1
    git pull
    curl http://localhost:8080/reread
fi

Idealy this would be part of the api at some point.

Build & run

Build it using cargo. To run it you need to provide the path to the mappings folder of the registry via the MAPPINGS environment variable.

Implementation

Written in rust using the actix web framework. THe layout of the project is taken from the book Zero2Production in Rust. I had no idea of how to set this up so i took what others have said is a good idea. The main.rs offers the entry point for the app when run directly while lib.rs implements the actual "run" that is invoked from main. The reason to that is so that tests can actually run requests against a real instance of the app, see tests/health_check.rs.

The handlers for the various views are all implemented in api.rs.

offchain-metadata-server's People

Contributors

ktorz avatar oversize avatar

Stargazers

 avatar

Watchers

 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.