Skip to content

Latest commit

 

History

History
171 lines (105 loc) · 4.97 KB

README.md

File metadata and controls

171 lines (105 loc) · 4.97 KB

casper-event-store-graphql

History

This repository contains the winner 🏆 project, submitted to Casper Hackathon and selected to earn the $10,000 reward of advanced category. Here is the work submition to GitCoin plataform: The Event Store Implementation. Here is the demo screencast: youtube Here is the interview for closing hackathon ceremony: link

Introduction

This is an Event Store Implementation for Casper Protocol.

An event can be emitted whenever a new block is minted, a transaction is executed, or a condition occurs in the smart contract. The storage stores these events in a database (MongoDB) and makes it available to applications via GraphQL. Then applications can query present and past events. In this way, it is easy to build a scalable architecture for many users, allowing new applications and uses of the Casper protocol.

Challenge Description:

Build an event store implementation using an SDK + MongoDB + GraphQL.

Detailed Technical Documentation

source: docs/images/Diagrams_plant_uml.md

Start Casper Network and MongoDB Containers

To improve my productivity I created a docker-compose file that runs two containers: one running a casper network using the nctl tool and other a MongoDB database.

So the first step is to enter the docker folder and run docker-compose as below.

cd docker/
docker-compose up

In another terminal we will start the casper network with the following commands:

docker exec -it nctl /bin/bash

cd ~/dev
source ~/.bashrc
source env/bin/activate
source casper-node/utils/nctl/activate

nctl-assets-setup
sleep 4
figlet "Starting"
nctl-start
sleep 1
nctl-status

Expected result: Casper Network

Testing MongoDB

Let's test if MongoDB is running correctly, open your MongoDB container:

docker exec -it mongo bash
mongo mongodb://admin:admin123@localhost:27017
show dbs

Expected result: MongoDB

Testing Casper Network

Let's test if Casper Network event stream server is accessible in your localhost.

curl -s  http://localhost:18102/events/main

Expected result: MongoDB

Start the Event Store

Run the following commands to use Maven to build and run the application:

mvn clean install
mvn spring-boot:run

In a few seconds the result of the processing of events from the Casper Network is expected to appear: evt

Execute some GraphQL requests

Using GraphQLi

Open your browser on the following address:

http://localhost:8080/graphiql evt

Using Curl

curl -g -X POST -H "Content-Type: application/json" -d '{"query":"query{allBlocks{hash}}"}' http://localhost:8080/graphql | jq

evt

curl -g -X POST -H "Content-Type: application/json" -d '{"query":"query{allBlocks {hash header{ parent_hash state_root_hash era_id } body{ proposer deploy_hashes transfer_hashes}proofs createdAt}}"}' http://localhost:8080/graphql | jq

evt

Throubleshooting

Check if Casper Network started event stream server:

docker exec -it nctl /bin/bash
grep -R --include=*.log "started event stream server" ~/dev/casper-node/utils/nctl

Check if Casper Network is running properly:

docker exec -it nctl /bin/bash

lsof | grep LISTEN | cut -d':' -f2 | sort | uniq

2. Other Tools

2.2 MongoDB Compass Gui

2.2.1 Install

Install MongoDB Compass in your localhost:

wget https://downloads.mongodb.com/compass/mongodb-compass_1.26.1_amd64.deb
sudo dpkg -i mongodb-compass_1.26.1_amd64.deb

source: https://docs.mongodb.com/compass/current/install/

2.2.2 Start

  1. Start MongoDB Compass in your localhost:
mongodb-compass
  1. Conect to your MondoDB with the following URI: mongodb://admin:admin123@localhost:27017

MongoDB Compass MongoDB Compass