Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6696620ed4 | ||
|
|
79965a8a46 | ||
|
|
2e718c5924 | ||
|
|
f9cf1f31a5 | ||
|
|
82cb74fb58 | ||
|
|
c4f32d21dc | ||
|
|
6d0b596fea |
@@ -3,4 +3,5 @@ WORKDIR /app
|
||||
COPY . .
|
||||
RUN pip install -r requirements.txt
|
||||
EXPOSE 80
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD [ "curl", "-Sf" "localhost:80" ]
|
||||
ENTRYPOINT ["python", "app.py"]
|
||||
|
||||
+28
-2
@@ -87,6 +87,32 @@ 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
|
||||
@@ -100,10 +126,10 @@ class Blockchain:
|
||||
|
||||
if length > max_lengh and self.valid_chain(chain):
|
||||
max_lengh = length
|
||||
new_chain = chain
|
||||
new_chain = self.json_to_chain(chain)
|
||||
|
||||
if new_chain:
|
||||
self.chain = new_chain
|
||||
self.blocks = new_chain
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
curl "localhost:5123/register" -H "Content-Type: application/json" -d '{"nodes": ["http://127.0.0.1:5000"]}'
|
||||
curl "localhost:5001/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:5123/chain" | jq
|
||||
curl "localhost:5123/resolve"
|
||||
curl -s "localhost:5001/chain" | jq
|
||||
curl "localhost:5001/resolve"
|
||||
curl -s "localhost:5001/chain" | jq
|
||||
|
||||
Reference in New Issue
Block a user