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
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.
Build an event store implementation using an SDK + MongoDB + GraphQL.
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
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
Let's test if Casper Network event stream server is accessible in your localhost.
curl -s http://localhost:18102/events/main
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:
Open your browser on the following address:
http://localhost:8080/graphiql
curl -g -X POST -H "Content-Type: application/json" -d '{"query":"query{allBlocks{hash}}"}' http://localhost:8080/graphql | jq
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
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
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/
- Start MongoDB Compass in your localhost:
mongodb-compass
- Conect to your MondoDB with the following URI:
mongodb://admin:admin123@localhost:27017