-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make json storage consistent so client works properly
- Loading branch information
Hirsh Agarwal
committed
Jun 16, 2023
1 parent
27696b5
commit 99efe64
Showing
8 changed files
with
68 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,34 @@ | ||
import json | ||
import uuid | ||
|
||
import requests as requests | ||
from requests import Response | ||
|
||
from blockchain import Block | ||
from records.userdata import UserData | ||
from clienthelper import ClientHelper | ||
from user import User | ||
|
||
|
||
class HealthChainClient: | ||
def __init__(self, host, port): | ||
self.host = host | ||
self.port = port | ||
self.helper = ClientHelper(host, port) | ||
|
||
def add_block(self, new_block: Block): | ||
pass | ||
|
||
def build_user_block(self, first_name, last_name, dob, user_object: User) -> Block: | ||
tail_block_json = requests.get("http://{}:{}/get_tail_block" | ||
.format(self.host, self.port)).json() | ||
tail_block = Block.from_json(tail_block_json) | ||
init_user_block = UserData( | ||
first_name, | ||
last_name, | ||
dob, | ||
user_object.public_key | ||
) | ||
user_block_serialized = init_user_block.json_serialize() | ||
return Block.new_block(tail_block, user.user_id, user_block_serialized) | ||
request_response = requests.post("http://{}:{}/add_block".format(self.host, self.port), | ||
data=new_block.get_json()) | ||
return request_response.json() | ||
|
||
def get_blockchain(self) -> Response: | ||
return requests.get("http://{}:{}/get_blockchain" | ||
.format(self.host, self.port)) | ||
.format(self.host, self.port)).json() | ||
|
||
|
||
if __name__ == '__main__': | ||
client = HealthChainClient('localhost', '8080') | ||
user = User(uuid.uuid4()) | ||
block = client.build_user_block('Hirsh', 'Agarwal', '16/08/1997', user) | ||
block_data = json.loads(block.data) | ||
print(block_data) | ||
decrypted_block = UserData.decrypt_user_data_block(block_data, user.private_key) | ||
print(decrypted_block) | ||
block = client.helper.build_user_block('Hirsh', 'Agarwal', '16/08/1997', user) | ||
response = client.add_block(block) | ||
print(response) | ||
# decrypted_block = UserData.decrypt_user_data_block(block.data, user.private_key) | ||
# print(client.get_blockchain()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import requests | ||
|
||
from blockchain import Block | ||
from records.userdata import UserData | ||
from user import User | ||
|
||
|
||
class ClientHelper: | ||
def __init__(self, host, port): | ||
self.host = host | ||
self.port = port | ||
|
||
def build_user_block(self, first_name, last_name, dob, user_object: User) -> Block: | ||
tail_block_json = requests.get("http://{}:{}/get_tail_block" | ||
.format(self.host, self.port)).json() | ||
tail_block = Block.from_json(tail_block_json) | ||
init_user_block = UserData( | ||
first_name, | ||
last_name, | ||
dob, | ||
user_object.public_key | ||
) | ||
return Block.new_block(tail_block, user_object.user_id, init_user_block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters