1 Commits
Author SHA1 Message Date
marc 9de5492201 shebang 2022-02-23 21:24:49 +01:00
4 changed files with 9 additions and 37 deletions
-5
View File
@@ -1,5 +0,0 @@
.git
docker-compose.yml
Dockerfile
README.md
test
+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env python
from time import time
from flask import Flask, request
import json
+4 -28
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env python
import hashlib
from time import time
import json
@@ -87,32 +89,6 @@ class Blockchain:
return True
def json_to_transactions(self, transactions_json):
transactions = [
Transaction(
transaction["sender"],
transaction["recipient"],
transaction["amount"],
)
for transaction in transactions_json
]
return transactions
def json_to_chain(self, chain_json):
chain = [
Block(
block["index"],
block["timestamp"],
self.json_to_transactions(block["transactions"]),
block["previous_hash"],
block["proof"],
)
for block in chain_json
]
return chain
def resolve_conflicts(self):
neighbours = self.nodes
new_chain = None
@@ -126,10 +102,10 @@ class Blockchain:
if length > max_lengh and self.valid_chain(chain):
max_lengh = length
new_chain = self.json_to_chain(chain)
new_chain = chain
if new_chain:
self.blocks = new_chain
self.chain = new_chain
return True
return False
+3 -4
View File
@@ -1,9 +1,8 @@
#!/bin/sh
curl "localhost:5001/register" -H "Content-Type: application/json" -d '{"nodes": ["http://127.0.0.1:5000"]}'
curl "localhost:5123/register" -H "Content-Type: application/json" -d '{"nodes": ["http://127.0.0.1:5000"]}'
curl "localhost:5000/transactions/new" -H "Content-Type: application/json" -d '{"sender": "marc", "recipient": "samy", "amount": 50}'
curl "localhost:5000/mine"
curl -s "localhost:5000/chain" | jq
curl -s "localhost:5001/chain" | jq
curl "localhost:5001/resolve"
curl -s "localhost:5001/chain" | jq
curl -s "localhost:5123/chain" | jq
curl "localhost:5123/resolve"