Commit 3bb2350c authored by Moul's avatar Moul

[mod] code typo rework. remove '()' around return value.

parent 4f9cd414
......@@ -40,11 +40,11 @@ def match_pattern(pow, match = '', π = 1):
else:
match += "[0-" + hex(15 - pow)[2:].upper() + "]"
π *= pow; pow = 0
return (match + '*', π)
return match + '*', π
def power(nbr, pow = 0):
while nbr >= 10: nbr /= 10; pow += 1
return ("{0:.1f} × 10^{1}".format(nbr, pow))
return "{0:.1f} × 10^{1}".format(nbr, pow)
def difficulties(ep):
diffi = request(ep, "blockchain/difficulties")
......@@ -226,11 +226,11 @@ def show_amount_from_pubkey(ep, pubkey):
currency_name = str(current_blk["currency"])
if totalAmountInput-amount != 0:
if totalAmountInput - amount != 0:
print("Blockchain:")
print("-----------")
print("Relative =", round(amount / DUvalue, 2), "DU", currency_name)
print("Quantitative =", round(amount / 100, 2), currency_name+"\n")
print("Quantitative =", round(amount / 100, 2), currency_name + "\n")
print("Pending Transaction:")
print("--------------------")
......
......@@ -17,7 +17,7 @@ def discover_peers(ep, discover):
if discover: print("{0:.0f}%".format(i/len(endpoints) * 100)) #, ep) # debug
if best_node(ep, 0) is None: endpoints.remove(ep)
elif discover: endpoints = recursive_discovering(endpoints, ep)
return (endpoints)
return endpoints
def recursive_discovering(endpoints, ep):
"""
......@@ -30,7 +30,7 @@ def recursive_discovering(endpoints, ep):
if best_node(new, 0) is not None and new not in endpoints:
endpoints.append(new)
recursive_discovering(endpoints, new)
return (endpoints)
return endpoints
# Check why network discovering stayed stuck when checking some node without domain name: it happen sometimes
def parse_endpoints(rep):
......@@ -50,7 +50,7 @@ def parse_endpoints(rep):
ep["pubkey"] = rep[i]["pubkey"]
endpoints.append(ep)
i+=1; j = 0
return (endpoints)
return endpoints
def parse_endpoint(rep):
"""
......@@ -67,35 +67,35 @@ def parse_endpoint(rep):
ep = endpoint_type(sep[2], ep)
if len(sep) == 3:
ep = endpoint_type(sep[1], ep)
return (ep)
return ep
else:
return (None)
return None
def endpoint_type(sep, ep):
typ = check_ip(sep)
if typ == 0: ep["domain"] = sep
if typ == 4: ep["ip4"] = sep
if typ == 6: ep["ip6"] = sep
return (ep)
return ep
def check_ip(address):
try: return (ipaddress.ip_address(address).version)
except: return (0)
try: return ipaddress.ip_address(address).version
except: return 0
def request(ep, path):
address = best_node(ep, 0)
if address is None: return (address)
if address is None: return address
url = "http://" + ep[address] + ":" + ep["port"] + "/" + path
if ep["port"] == "443":
url = "https://" + ep[address] + "/" + path
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
encoding = response.info().get_content_charset('utf8')
return (json.loads(response.read().decode(encoding)))
return json.loads(response.read().decode(encoding))
def post_request(ep, path, postdata):
address = best_node(ep, 0)
if address is None: return (address)
if address is None: return address
url = "http://" + ep[address] + ":" + ep["port"] + "/" + path
if ep["port"] == "443":
url = "https://" + ep[address] + "/" + path
......@@ -106,7 +106,7 @@ def post_request(ep, path, postdata):
print(e)
exit()
encoding = response.info().get_content_charset('utf8')
return (json.loads(response.read().decode(encoding)))
return json.loads(response.read().decode(encoding))
def best_node(ep, main):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
......@@ -116,10 +116,10 @@ def best_node(ep, main):
try:
s.connect((ep[address], port))
s.close()
return (address)
return address
except: pass
if main: print("Wrong node gived as argument"); exit()
return (None)
return None
def check_port(port):
try:
......@@ -128,4 +128,4 @@ def check_port(port):
print("Port must be an integer"); exit()
if (port < 0 or port > 65536):
print("Wrong port number"); exit()
return (1)
return 1
......@@ -56,7 +56,7 @@ def cli():
print("Fallback to default node: <{}:{}>"
.format(ep["domain"], ep["port"]), file=sys.stderr)
if ep["domain"].startswith('[') and ep["domain"].endswith(']'): ep["domain"] = ep["domain"][1:-1]
return (ep, c)
return ep, c
def manage_cmd(ep, c):
......
......@@ -26,8 +26,7 @@ def get_uid_from_pubkey(ep, pubkey):
def get_current_block(ep):
current_blk = request(ep, "blockchain/current")
return current_blk
return request(ep, "blockchain/current")
def get_seed_from_scrypt(salt, password, N=4096, r=16, p=1):
......
......@@ -42,8 +42,8 @@ def generate_and_send_transaction(ep, seed, AmountTransfered, outputAddr, Commen
print(" - Amount: " + str(listinput_and_amount[1] / 100))
else:
print(" - Amount: " + str(AmountTransfered / 100))
transaction = generate_transaction_document(ep, issuers, AmountTransfered, listinput_and_amount,outputAddr, Comment, OutputbackChange)
transaction += sign_document_from_seed(transaction,seed) + "\n"
transaction = generate_transaction_document(ep, issuers, AmountTransfered, listinput_and_amount, outputAddr, Comment, OutputbackChange)
transaction += sign_document_from_seed(transaction, seed) + "\n"
retour = post_request(ep, "tx/process", "transaction=" + urllib.parse.quote_plus(transaction))
print("Transaction successfully sent.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment