Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Lab 03 Add usage script or instructions how to interact with multi-node network #64

Open
jsolderitsch opened this issue Jan 15, 2022 · 2 comments

Comments

@jsolderitsch
Copy link

I figured our how to use postman to send post requests to the first node created by the setup-docker script. This causes a block to be mined if you add enough transactions.

But I am unsure of the process of building out a multi-node network where transactions posted to node 2 will cause node 1 and node 2 to have a common view of the blockchain. Seems like each node will have its own genesis block for example.

Also not clear on how peers are declared/detected. Maybe this should be obvious by reading the code, but it is not obvious to me.

I am teaching a blockchain course at Villanova University in the state of Pennsylvania.

@jsolderitsch
Copy link
Author

There is a test.py file in the project. I suggest that an assignment challenge might be to add an @app.route declaration for getBalance where the there is an argument for an address. Also a method to return just the size of the blockchain. I might take up the challenge myself to see if I know enough based on the current README and examining the code.

@jsolderitsch
Copy link
Author

I did implement getBalance and getLength app.route implementations and this was straight forward. I now believe that the simple lab 03 implementation does not support a multi-node network with each node having a common blockchain view of blocks mined by any of the nodes in the network.

@app.route('/length', methods=['GET'])
def get_length():
    response = {
        'length': len(blockchain.chain),
    }
    return json.dumps(response), 200

@app.route('/getBalance', methods=['GET'])
def get_balance():
    address = request.args.get('address')
    balance = blockchain.get_balance(address)
    response = {
        'address': address,
        'balance': balance
    }
    return json.dumps(response), 200

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant