Code Monkey home page Code Monkey logo

jbc's Introduction

jbc

Jack's Blockchain -- Simple blockchain to learn and talk about how blockchains work.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

As always, you'll need to install the Python libraries in requirements.txt

$ pip install -r requirements.txt

Running a node

To run the node on the command line, there are a few options.

-m tells the node to not only receive nodes, but also mine.

-p PORT_NUM will tell node.py which port to run on. This is important when running multiple nodes locally as described below.

Hard linking directory for multiple nodes

In order to run a different node, we want to hard link the main jbc directory into another directory. To do this, use the linknodes.sh script in the directory above jbc.

For example,

$ ./linknodes.sh 5001

will create a directory named jbc5001. Then in that directory, you'll be able to run a node on a different port to gather blocks or mine as well.

Contributing

Feel free to clone, run, and give feedback and pull requests. Finding bugs is a great help to the project, as well as a great way for everyone to learn. And feel free to help update this README file to better describe how to run this locally.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

jbc's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jbc's Issues

index error when running mine.py or node.py

Hello, i new to python and not 100% where this error is coming from. I am using python 2.7.14. Node.py works with out any issue util i try to enable mining. thank you this project is great and i hope it keeps going.

python mine.py
INFO:apscheduler.scheduler:Adding job tentatively -- it will be properly schedul
ed when the scheduler starts
INFO:apscheduler.scheduler:Added job "mine_for_block" to job store "default"
INFO:apscheduler.scheduler:Scheduler started
DEBUG:apscheduler.scheduler:Looking for jobs to run
INFO:apscheduler.executors.default:Running job "mine_for_block (trigger: date[20
18-03-23 15:28:18 MST], next run at: 2018-03-23 15:28:18 MST)" (scheduled at 201
8-03-23 15:28:18.538000-07:00)
INFO:apscheduler.scheduler:Removed job mining
DEBUG:apscheduler.scheduler:No jobs; waiting until a job is added
ERROR:apscheduler.executors.default:Job "mine_for_block (trigger: date[2018-03-2
3 15:28:18 MST], next run at: 2018-03-23 15:28:18 MST)" raised an exception
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\apscheduler\executors\base.py", line 125,
in run_job
retval = job.func(*job.args, **job.kwargs)
File "mine.py", line 30, in mine_for_block
prev_block = chain.most_recent_block()
File "C:\Users\jcrews-adm\jbc\chain.py", line 78, in most_recent_block
return self.blocks[-1]
IndexError: list index out of range

TypeError: Unicode-objects must be encoded before hashing

Changed from
def create_self_hash(self):
sha = hashlib.sha256()
sha.update(self.header_string().encode('utf-8'))
return sha.hexdigest()
to
def create_self_hash(self):
sha = hashlib.sha256()
sha.update(self.header_string().encode('utf-8'))
return sha.hexdigest()

test.py fails in a number of locations

The blockchain itself does appear to be running successfully on my system, but I've run into a number of problems when I run the tests.

  • The hashes in test.py all use 5 leading zeroes, but the default value in config.py is 6.
  • The with statements on lines 106, 110, 114, and 117 make use of the variables zt, ft, st, and tt, but these variables are not defined until lines 125-128
  • Calls to mine.mine_block and mine.mine_from_prev_block fail with ValueError: too many values to unpack, since both return 4 values and test.py tries to assign the results to only 3 variables

All of these are relatively simple fixes, but after I dealt with them I ran into a problem to which the solution was less obvious.

Traceback (most recent call last):  
  File "test.py", line 167, in <module>
    assert new_block == mine_test_block_one
  File "C:\Users\mgplante\blockchain\jbc2\block.py", line 67, in __eq__
    return (self.index == other.index and
AttributeError: 'NoneType' object has no attribute 'index'

It's failing to find a block when the tests assert that it should find a block.

The fact that I'm able to run nodes successfully implies to me that everything is working and that it's just the tests that are wrong, but it's not clear to me how one would go about fixing that.

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.