Giter Club home page Giter Club logo

blockchain-book's Introduction

Learn Blockchain by Building One

This is the full source code for my book, Learn Blockchain by Building One (Apress / Amazon).

Please submit any issues found in the code here: https://github.com/dvf/blockchain-book/issues

And if I haven't responded to them, please get my attention at [email protected] and I'll do my best to help you out.

The Code

The finalized blockchain is located in /chapters/chapter_7.

Please ensure all dependencies are installed:

cd chapters/chapter_7
poetry install
Creating virtualenv chapter-7-uY9ygsE2-py3.8 in /home/dan3x/.cache/pypoetry/virtualenvs
Installing dependencies from lock file

Package operations: 50 installs, 0 updates, 0 removals

  • Installing pyparsing (2.4.7)
  • Installing six (1.15.0)
  • Installing attrs (20.2.0)
  • Installing colorama (0.4.3)
  • Installing idna (2.10)
  • Installing iniconfig (1.0.1)
...

Then you can run the node:

$ poetry shell
(chapter-7-py3.8) $ python node.py

2021-02-16 11:37.35 Creating genesis block
2021-02-16 11:37.35 Server listening on 0.0.0.0:8888
2021-02-16 11:37.35 Found external IP: XXX.XXX.XXX.XXX

blockchain-book's People

Contributors

dvf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockchain-book's Issues

error on windows "No module named:structLog"

This is the error i get when I put: python node.py:
Traceback (most recent call last):
File "C:\Users\marce\blockchain-book\chapters\chapter_7\node.py", line 3, in
from funcoin.blockchain import Blockchain
File "C:\Users\marce\blockchain-book\chapters\chapter_7\funcoin\blockchain.py", line 8, in
import structlog
ModuleNotFoundError: No module named 'structlog'

Hashes - Random?

I realize I'm being a bit picky here, but hashes are not random; they are absolutely deterministic. On page 17 (and other places), the author states that a hash provides a "unique, random value." "Unique" is mostly true (except in the very unlikely event of a collision), but "random" is not. It may look random, but it isn't; as the author states in the very same paragraph, "the output is always predictable for the same input." That is the very opposite of random.

In future editions, I would suggest dropping "random" and simply staying with "unique." It gets your point across without adding any "confusion factors."

node.py api layer

Hi, is agreat resource the code in this repo, I would like to ask you if is a good aproach to create an api.py file to handle the comunication from a frontend app with the node, I see the method handle_connection->handle_message, so I think i will use handle_message()method to send a message (ping or transaction messages for test this project) in an docker network for see the P2P working and have the nice functionallity from your project https://github.com/dvf/blockchain/blob/68066d648244ce2b7e2d1cbd16f9255363f94712/blockchain.py#L232, im junior using python, but thanks for this repo and some advice for enable functionalities as API

"Messaging Protocol" sent incorrectly

handler = message_handlers.get(message["name"])

In this piece of code above, the struct for var "message' doesn't have "name"
because in server.py, it pass different with "meta" and "message"

async def handle_connection(self, reader: StreamReader, writer: StreamWriter):

i'm fix it with:

message = message['message']
handler = message_handlers.get(message["name"]) 

added this above in line 38 in peers.py

Telnet (or the lack thereof)

The echo server example in the Network section uses a telnet client for testing. However, because of security issues, telnet is locked down by most commercial security policies. SSH (with its associated handshaking, complexity, and overhead) is the closest thing available. Would it be possible to have an automated "driver" program that could do this testing that would take up only a few lines of code?

nonce definition, chapter 4 page 48

Not sure if you are also using this for general book issues and not just code. Very minor issue. I’m pretty sure “nonce” means “number used once” and not “nonsense string”.

Chapter 7: no mining happening?

Going through the chapter 7's code in order to understand how the whole app works, I've been surprised to find out that no mining is actually happening anywhere in the code. There's a method Blockchain.mine_new_block() but it doesn't seem to be called from anywhere.

The node can:

  • Receive a block from another node;
  • Receive a transaction and add it to pending transactions list.

But nowhere in the code do we create a new block, apart from the genesis. That's confusing.

Return no module name "Funcoin"

When I execute messages.py, the funcoin.schema return error. Is this a typo or what dependencies or package I should install?

Error in server.py

When starting the node and loading the interface it shows this error.

Task exception was never retrieved
future: <Task finished name='Task-7' coro=<Server.handle_connection() done, defined at C:\Users\de56002\Py\Proyectos\Block\server.py:30> exception=JSONDecodeError('Expecting value: line 1 column 1 (char 0)')>
Traceback (most recent call last):
File "C:\Users\de56002\Py\Proyectos\Block\server.py", line 40, in handle_connection
message = BaseSchema().loads(decoded_data) # <5>
File "C:\Users\de56002\Py\lib\site-packages\marshmallow\schema.py", line 756, in loads
data = self.opts.render_module.loads(json_data, **kwargs)
File "C:\Users\de56002\Py\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\de56002\Py\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\de56002\Py\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

As far as I could tell, it is receiving a String instead of being in JSON format.
Any way to fix it?

Information about connection node

node_start
Dear Daniel val Flymen,
i read you book and is fantastic, i buyed in paper and in kindle version. I had make all step in your book, i'm blocking to comunicate node by node. The first node is start and is in listening, my ask is: how do i get more nodes to communicate? i start the genesis block, but how do i hook the miners to the pool? how can i continue the started project? I would like to store the blocks locally in order to create the decentralized blockchain, how do I do it? could you help me with this? i'll wait than your kind reply, I offer you my best regards.

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.