7 Commits
Author SHA1 Message Date
marc bec6a801bf dockerignore 2022-02-23 21:30:15 +01:00
Samy Haffoudhi 79965a8a46 tg marc, merci 2022-02-23 21:25:42 +01:00
Samy Haffoudhi 2e718c5924 Merge branch 'master' of https://github.com/samyhaff/Blockchain 2022-02-23 21:15:35 +01:00
Samy Haffoudhi f9cf1f31a5 maj script 2022-02-23 21:11:03 +01:00
Samy Haffoudhi 82cb74fb58 bug fix resolve conflicts, for real this time
git push origin master
2022-02-23 21:10:41 +01:00
Samy Haffoudhi c4f32d21dc Merge pull request #1 from MarcPartensky/dockercompose
docker-compose.yml
2022-02-23 20:27:54 +01:00
Samy Haffoudhi 6d0b596fea bug fix resolve conflicts 2022-02-23 20:24:34 +01:00
3 changed files with 37 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
.git
docker-compose.yml
Dockerfile
README.md
test
+28 -2
View File
@@ -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
+4 -3
View File
@@ -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