-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deps(python): Python 2 -> 3 by hand #27
Open
Et7f3
wants to merge
2
commits into
daxeel:master
Choose a base branch
from
Et7f3:python2to3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,23 +39,23 @@ def calculateHash(self): | |
Method to calculate hash from metadata | ||
""" | ||
hashData = str(self.index) + str(self.data) + self.timestamp + self.previousHash + str(self.nonce) | ||
return hashlib.sha256(hashData).hexdigest() | ||
return hashlib.sha256(bytes(ord(x) for x in hashData)).hexdigest() | ||
|
||
def mineBlock(self, difficulty): | ||
""" | ||
Method for Proof of Work | ||
""" | ||
print Back.RED + "\n[Status] Mining block (" + str(self.index) + ") with PoW ..." | ||
print(Back.RED + "\n[Status] Mining block (" + str(self.index) + ") with PoW ...") | ||
startTime = time.time() | ||
|
||
while self.hash[:difficulty] != "0"*difficulty: | ||
self.nonce += 1 | ||
self.hash = self.calculateHash() | ||
|
||
endTime = time.time() | ||
print Back.BLUE + "[ Info ] Time Elapsed : " + str(endTime - startTime) + " seconds." | ||
print Back.BLUE + "[ Info ] Mined Hash : " + self.hash | ||
print Style.RESET_ALL | ||
print(Back.BLUE + "[ Info ] Time Elapsed : " + str(endTime - startTime) + " seconds.") | ||
print(Back.BLUE + "[ Info ] Mined Hash : " + self.hash) | ||
print(Style.RESET_ALL) | ||
|
||
# ================================================== | ||
# ================ BLOCKCHAIN CLASS ================ | ||
|
@@ -88,7 +88,7 @@ def writeBlocks(self): | |
""" | ||
Method to write new mined block to blockchain | ||
""" | ||
dataFile = file("chain.txt", "w") | ||
dataFile = open("chain.txt", "w") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
chainData = [] | ||
for eachBlock in self.chain: | ||
chainData.append(eachBlock.__dict__) | ||
|
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 |
---|---|---|
|
@@ -45,7 +45,7 @@ def cli(): | |
@click.option("--difficulty", default=3, help="Define difficulty level of blockchain.") | ||
def init(difficulty): | ||
"""Initialize local blockchain""" | ||
print """ | ||
print(""" | ||
____ _ _ _____ _ _ _ | ||
| _ \ | | | | / ____| | | | | | | | ||
| |_) | | | ___ ___ | | __ | (___ | |__ ___ | | | | | ||
|
@@ -57,14 +57,14 @@ def init(difficulty): | |
> Type 'help' to see supported commands. | ||
> Project by Daxeel Soni - https://daxeel.github.io | ||
|
||
""" | ||
""") | ||
|
||
# Set difficulty of blockchain | ||
coin.difficulty = difficulty | ||
|
||
# Start blockshell shell | ||
while True: | ||
cmd = raw_input("[BlockShell] $ ") | ||
cmd = input("[BlockShell] $ ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
processInput(cmd) | ||
|
||
# Process input from Blockshell shell | ||
|
@@ -92,17 +92,17 @@ def dotx(cmd): | |
txData = cmd.split("dotx ")[-1] | ||
if "{" in txData: | ||
txData = json.loads(txData) | ||
print "Doing transaction..." | ||
print("Doing transaction...") | ||
coin.addBlock(Block(data=txData)) | ||
|
||
def allblocks(cmd): | ||
""" | ||
Method to list all mined blocks. | ||
""" | ||
print "" | ||
print("") | ||
for eachBlock in coin.chain: | ||
print eachBlock.hash | ||
print "" | ||
print(eachBlock.hash) | ||
print("") | ||
|
||
def getblock(cmd): | ||
""" | ||
|
@@ -111,21 +111,21 @@ def getblock(cmd): | |
blockHash = cmd.split(" ")[-1] | ||
for eachBlock in coin.chain: | ||
if eachBlock.hash == blockHash: | ||
print "" | ||
print eachBlock.__dict__ | ||
print "" | ||
print("") | ||
print(eachBlock.__dict__) | ||
print("") | ||
|
||
def help(cmd): | ||
""" | ||
Method to display supported commands in Blockshell | ||
""" | ||
print "Commands:" | ||
print " dotx <transaction data> Create new transaction" | ||
print " allblocks Fetch all mined blocks in blockchain" | ||
print " getblock <block hash> Fetch information about particular block" | ||
print("Commands:") | ||
print(" dotx <transaction data> Create new transaction") | ||
print(" allblocks Fetch all mined blocks in blockchain") | ||
print(" getblock <block hash> Fetch information about particular block") | ||
|
||
def throwError(msg): | ||
""" | ||
Method to throw an error from Blockshell. | ||
""" | ||
print "Error : " + msg | ||
print("Error : " + msg) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably use fstrings. Since this is cli we should use click and show messages with click.echo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted for minimal change. If we are ok about putting 3.6 as lower bound why not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I agree this doesn't block your PR