Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bec6a801bf | ||
|
|
79965a8a46 | ||
|
|
2e718c5924 | ||
|
|
f9cf1f31a5 | ||
|
|
82cb74fb58 | ||
|
|
c4f32d21dc | ||
|
|
6d0b596fea |
@@ -0,0 +1,5 @@
|
||||
.git
|
||||
docker-compose.yml
|
||||
Dockerfile
|
||||
README.md
|
||||
test
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from time import time
|
||||
from flask import Flask, request
|
||||
import json
|
||||
|
||||
+28
-4
@@ -1,5 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import hashlib
|
||||
from time import time
|
||||
import json
|
||||
@@ -89,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
|
||||
@@ -102,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