From 5221f6a883ae317128af15e3d8d7fc53b13edd61 Mon Sep 17 00:00:00 2001 From: f97ada87 <32196103+f97ada87@users.noreply.github.com> Date: Fri, 25 May 2018 06:13:01 +0000 Subject: [PATCH] adding docstring and integer typecast --- src/protocol.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/protocol.py b/src/protocol.py index 6869903c..5c143d2d 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -170,12 +170,23 @@ def isProofOfWorkSufficient(data, nonceTrialsPerByte=0, payloadLengthExtraBytes=0, recvTime=0): + """ + Validate an object's Proof of Work using method described in: + https://bitmessage.org/wiki/Proof_of_work + Arguments: + int nonceTrialsPerByte (default: from default.py) + int payloadLengthExtraBytes (default: from default.py) + float recvTime (optional) UNIX epoch time when object was + received from the network (default: current system time) + Returns: + True if PoW valid and sufficient, False in all other cases + """ if nonceTrialsPerByte < defaults.networkDefaultProofOfWorkNonceTrialsPerByte: nonceTrialsPerByte = defaults.networkDefaultProofOfWorkNonceTrialsPerByte if payloadLengthExtraBytes < defaults.networkDefaultPayloadLengthExtraBytes: payloadLengthExtraBytes = defaults.networkDefaultPayloadLengthExtraBytes endOfLifeTime, = unpack('>Q', data[8:16]) - TTL = endOfLifeTime - (recvTime if recvTime else int(time.time())) + TTL = endOfLifeTime - (int(recvTime) if recvTime else int(time.time())) if TTL < 300: TTL = 300 POW, = unpack('>Q', hashlib.sha512(hashlib.sha512(data[