Skip to content

57op/python-simple-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Very simple blockchain (partial) implementation in Python (3.6)

It's nothing serious, I was just trying to understand better how the blockchain works. Transactions and blocks are stored in plain JSON on filesystem for visualization purposes. Source code needs to be tidied up, but whenever I'm in the mood I'll try adding more features before.

Explanation

A transaction has the following structure

{
    "vin": [
        {
            "tx": "093c101a53e43e25893f04631e70ea86a64628ba982e85bf59d8ebe3be38fd0f",
            "vout": 0,
            "signature": "d1601f5b669f36ec3f57ab01d3e7948bacef475be57bcd456684c960e1333e79cb34d81ceff9e2271c7b75eba8ffb3961315b66b21262f423e82347695714446",
            "pubkey": "021ea0ffb5a7fd37acd2dffcfeeff59f27214c592bc91a4da6bd92ac92a26912e7"
        }
    ],
    "vout": [
        {
            "value": 10,
            "address": "1GQeNtP9LjnYp3hepAfiXi2MhvVTp71aZM"
        },
        {
            "value": 15,
            "address": "1MmWbFY4dwsovy93zSjC2BkRZ43LU7cbhT"
        }
    ]
}

As you can see there's no locking script in the output, nor unlocking script in the input. The transaction verification is not dynamic like in bitcoin,it's static. So, basically, only a P2PKH is allowed. To unlock an output, it's verified that the public key generates the same public address and then it verifies that the signature was generated by that public key. The signature message is the hash of transaction containing the output you want to spend (093c101a53e43e25893f04631e70ea86a64628ba982e85bf59d8ebe3be38fd0f signed with Alice's privte key).

A block has the following structure

{
    "previous_block": "000e1dd82f4ec2a37c8f73c86bdeb0c898975aaf0f133948d96938c7250706b7",
    "checksum": "0004acc3d1204e2a2bd8e9951f65c8d2361488d25e9db42e66ac177c36bc6dbe",
    "nonce": 12245,
    "transactions": [
        "e4b0822fb23eb03b2f08568fc55fc5a41c9d81423fcd7601a06eb014d2def0bc",
        "985777eac46108b05259e54037efd996b6c052562f61ddc85acd9698763b499b"
    ]
}

Requirements

  • ecdsa
  • base58

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages