Open HourGlss opened 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
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?
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.
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.