Skip to content

victorabarros/CS50chain

Repository files navigation

This is CS50chain

Blockchain POC to CS50 final project

Demo

content
  1. description
  2. entities
  3. api
  4. usage
  5. automated tests
  6. acknowledgments
  7. roadmap
  8. license

Here the course Certificate

Description

Blockchain is a decentralized way to save data. In our case, as bitcoin works, the data is financial transactions. First is necessary for the user to create their wallet that's is a pair of RSA256 keys. These will work as address to receive deposits and authenticate withdraws. The API in itself is an abstraction to a Node, it is a piece of the network that decentralize the blockchain, it is responsible for submitting transactions to block and mine them. Mine means doing a proof of work calculation and being responsible for sending the new block to the blockchain. More details in CS50 Readme.

Entities

classDiagram
class Wallet {
    public_key
    private_key
    financial_data
    created_at
}

class Transaction {
    sender_public_key
    recipient_public_key
    amount
    description
    sign
    created_at
    do_sign(sender_private_key)
}

class Node {
    transactions
    nodes
    submit_transaction(transaction)
    add_node_address(address)
    sync()
    mine_block()
}

class Block {
    id
    data
    hash
    nonce
    created_at
}
Loading

API

  • GET /api/node
    • get current node transactions and other node addresses
  • POST /api/node/address
    • add new node address
  • DELETE /api/node/transactions
    • clear node transactions
  • POST /api/node/mine
    • mine block, aka sync transaction with other nodes, calculate nonce (proof of work), and create a new block to the blockchain
  • GET /api/chain
    • get blockchain
  • POST /api/chain
    • sync current node with other blockchain and transactions
  • POST /api/wallet
    • create new wallet
  • POST /api/search/wallet
    • wallet search
  • POST /api/transaction
    • submit transaction to node

Usage

To run the node locally run make docker-run and then open on browser https://localhost:5000/ to interact with an interface. To run another node to mock transactions and sync between them, use make docker-run APP_NAME=cs50chain-clone PORT=5001 and open https://localhost:5001/ . Also can import the Postman Collection to request directly to the API.

Automated tests

To run tests make docker-test

Jun 14 2022
Name                 Stmts   Miss  Cover
----------------------------------------
app/__init__.py          0      0   100%
app/block.py            85     15    82%
app/config.py            8      0   100%
app/database.py         15      1    93%
app/node.py             79     18    77%
app/transaction.py      55      9    84%
app/wallet.py           58      1    98%
test/__init__.py         0      0   100%
test/test_app.py       107      0   100%
----------------------------------------
TOTAL                  407     44    89%

If you want to persist data, run make docker-migration and it'll create a local sqlite3 database. These commands can be used to run sql queries on the database.

Acknowledgments

Roadmap

  • infra
    • add Dockerfile, make docker-build and use build on make docker-run and make docker-test
  • frontend
    • add copy to clipboard button on table lines and copy object
    • clickable link to expand with complete object
  • documentation
    • add swagger
    • codeclimate
  • online
    • deploy app
    • save blockchain on heroku postgresql

License

MIT


Made in Brazil

About

Blockchain POC - Harvard's CS50 final project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published