cosme12 / SimpleCoin

Just a really simple, insecure and incomplete implementation of a blockchain for a cryptocurrency made in Python as educational material. In other words, a simple Bitcoin clone.
http://copitosystem.com
MIT License
1.78k stars 397 forks source link

Transactions are not validated for balance amount #42

Open HourGlss opened 5 years ago

HourGlss commented 5 years ago

a user can give any number of "coins" because a balance is never checked. This is a core feature of any currency. Due to the fact that this is education, it is pivotal.

HourGlss commented 5 years ago
@node.route('/balances', methods=['GET'])
def get_balance():
    global BLOCKCHAIN
    working = BLOCKCHAIN
    balances = {}
    balances_json = []

    for block in working:
        if block.data['transactions'] is not None:
            for transaction in block.data['transactions']:
                to = transaction['to']
                source = transaction['from']
                amount = transaction['amount']

                if type(amount) == type("string"):
                    amount = eval(amount)

                if to in balances:
                    balances[to] += amount
                else:
                    balances[to] = amount
                if source != "network":
                    balances[source] -= amount

    for k,v in balances.items():
        account = {
            "address": str(k),
            "amount": str(v)
        }
        balances_json.append(account)

    return json.dumps(balances_json)

This can be used to check all balances for accounts

Jolosin4 commented 5 years ago

How to implent it in the code? Can you copy the entire code with balance amount? Or how do I get this in the wallet file?

HourGlss commented 5 years ago

I’m working on it. Check my repo, I pulled apart this code and I’m trying to make something that actually works.

This code doesn’t actually work for getting a chain from someone else. Nor are transactions logically evaluated or verifiable from other users. Not only is it not secure, it’s not a cryptocurrency.