-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add Transaction feature #21
Conversation
src/tools.py
Outdated
blockstamp = pending["blockstamp"] | ||
block_number = int(blockstamp.split("-")[0]) | ||
#if it's not an old transaction (bug in mirror node) | ||
if(block_number >= last_block_number-3): |
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.
Pas de parenthèses en python
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.
J'ai été chiant, et j'ai commenté absolument tout ce que j'aurais fait différemment:
-pas de parenthèses autour des conditions (à moins de spécifier des priorités, ce qui est autre chose),
-pas de parenthèses dans les retours de fonction (à moins de vouloir créer des tuples),
-conditions plus concises.
Bref, tu corriges… ou pas, à toi de voir. :) En tout cas tu le sauras pour la prochaine fois (je te rassure quand j'ai démarré le python je me suis fait engueulé un nombre de fois à cause de la syntaxe, il m'arrivait même de mettre des ; à la fin des instructions, ça ne génère pas d'erreur mais c'est complètement inutile :p ).
Super boulot en tout cas, j'ai hâte de tester tout ça quand j'aurai le temps un de ces 4…
src/tools.py
Outdated
i = 0 | ||
for output in pending["outputs"]: | ||
outputsplited = output.split(":") | ||
if(outputsplited[2] == "SIG("+pubkey+")"): |
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.
Pas de parenthèses en python
src/tools.py
Outdated
outputsplited = output.split(":") | ||
if(outputsplited[2] == "SIG("+pubkey+")"): | ||
inputgenerated=str(outputsplited[0])+":"+str(outputsplited[1])+":T:"+identifier+":"+str(i) | ||
if(inputgenerated not in listinput): |
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.
idem
src/tools.py
Outdated
blockstamp = pending["blockstamp"] | ||
block_number = int(blockstamp.split("-")[0]) | ||
#if it's not an old transaction (bug in mirror node) | ||
if(block_number >= last_block_number-3): |
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.
idem
src/tools.py
Outdated
#if it's not an old transaction (bug in mirror node) | ||
if(block_number >= last_block_number-3): | ||
for input in pending["inputs"]: | ||
if(input in listinput): |
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.
idem
src/tools.py
Outdated
|
||
|
||
def b58_encode(b): | ||
b58_digits = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' |
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.
tu aurais pu le sortir pour le partager avec le decode, mais pas forcément bien grave :)
src/commands.py
Outdated
else: | ||
allSources = False | ||
|
||
if(c.contains_definitions('outputBackChange')): |
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.
idem
src/commands.py
Outdated
currency_name = str(current_blk["currency"]) | ||
|
||
|
||
if(totalAmountInput-amount != 0): |
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.
parenthèses
src/tools.py
Outdated
def check_public_key(pubkey): | ||
regex = re.compile('^[1-9A-HJ-NP-Za-km-z]{43,44}$') | ||
regex_checksum = re.compile('^[1-9A-HJ-NP-Za-km-z]{43,44}:[1-9A-HJ-NP-Za-km-z]{3}$') | ||
if (re.search(regex, pubkey) is not None): |
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.
if re.search(regex, pubkey):
src/tools.py
Outdated
regex_checksum = re.compile('^[1-9A-HJ-NP-Za-km-z]{43,44}:[1-9A-HJ-NP-Za-km-z]{3}$') | ||
if (re.search(regex, pubkey) is not None): | ||
return(pubkey) | ||
if(re.search(regex_checksum, pubkey) is not None): |
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.
if re.search(regex_checksum, pubkey):
src/tools.py
Outdated
pubkey, checksum = pubkey.split(":") | ||
pubkey_byte=b58_decode(pubkey) | ||
checksum_calculed = b58_encode(nacl.hash.sha256(nacl.hash.sha256(pubkey_byte,nacl.encoding.RawEncoder),nacl.encoding.RawEncoder))[:3] | ||
if(checksum_calculed == checksum): |
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.
parenthèses
src/silkaj.py
Outdated
if c.is_help_request() or c.is_usage_request() or c.subcmd not in subcmd: usage(); exit() | ||
if c.is_version_request(): print("silkaj 0.1.0"); exit() | ||
ep["domain"], ep["port"] = "duniter.org", "10901" | ||
try: ep["domain"], ep["port"] = c.get_definition('p').rsplit(':', 1) | ||
except: | ||
print("Fallback to default node {}:{}\nCause: no specifed node, node not reachable or parsing issue." | ||
.format(ep["domain"], ep["port"]), file=sys.stderr) |
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.
src/tools.py
Outdated
if c == b58_digits[0]: pad += 1 | ||
else: break | ||
return b'\x00' * pad + res | ||
|
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.
Five empty lines
src/tx.py
Outdated
return(transaction_document) | ||
|
||
|
||
|
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.
spaces
src/tx.py
Outdated
print("Successful Transaction") | ||
break | ||
|
||
|
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.
spaces
src/tx.py
Outdated
import math | ||
import time | ||
|
||
|
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.
One surplus space.
src/tools.py
Outdated
lastDUblock = request(ep, "blockchain/block/" + str(NBlastDUblock)) | ||
return(lastDUblock["dividend"]*10**lastDUblock["unitbase"]) | ||
|
||
|
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.
Two surplus lines.
src/tools.py
Outdated
if(input in listinput): | ||
listinput.remove(input) | ||
|
||
|
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.
One surplus empty line.
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.
J'avais laissé passer des points virgule, ah lala! :D
src/tools.py
Outdated
@@ -72,7 +72,7 @@ def check_public_key(pubkey): | |||
|
|||
def get_amount_from_pubkey(ep, pubkey): | |||
sources = request(ep, "tx/sources/" + pubkey)["sources"] | |||
if sources == None: return(None) | |||
if sources == None: return None | |||
|
|||
listinput = []; |
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.
ah le point-virgule! :D
src/tools.py
Outdated
|
||
|
||
def get_uid_from_pubkey(ep, pubkey): | ||
i, results = 0, request(ep, "wot/lookup/" + pubkey)["results"] | ||
if results == None: return(None) | ||
if results == None: return None | ||
while (i < len(results)): |
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.
raté celui-là
src/tools.py
Outdated
|
||
|
||
def get_uid_from_pubkey(ep, pubkey): | ||
i, results = 0, request(ep, "wot/lookup/" + pubkey)["results"] | ||
if results == None: return(None) | ||
if results == None: return None |
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.
if not results: return None
:)
src/tools.py
Outdated
i+=1 | ||
|
||
|
||
def get_current_block(ep): | ||
current_blk = request(ep, "blockchain/current") | ||
if current_blk is None: return (None) | ||
else: return (current_blk) | ||
if current_blk is None: return None |
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.
En fait, le test ne sert à rien, tu pourrais te contenter de simplement renvoyer current_blk
src/tools.py
Outdated
@@ -72,7 +72,7 @@ def check_public_key(pubkey): | |||
|
|||
def get_amount_from_pubkey(ep, pubkey): | |||
sources = request(ep, "tx/sources/" + pubkey)["sources"] | |||
if sources == None: return(None) | |||
if sources == None: return None |
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.
if not sources: return None
src/tools.py
Outdated
|
||
|
||
def get_last_du_value(ep): | ||
blockswithud = request(ep, "blockchain/with/ud")["result"] | ||
if blockswithud == None: return(None) | ||
if blockswithud == None: return None |
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.
if not blockswithud: return None
src/tx.py
Outdated
transaction = generate_transaction_document(ep,issuers,totalAmountInput,listinput_and_amount,issuers,"Change operation") | ||
transaction += sign_document_from_seed(transaction,seed)+"\n" | ||
retour = post_request(ep, "tx/process", "transaction="+urllib.parse.quote_plus(transaction) ) | ||
print("Successful Change Transaction") | ||
time.sleep(1) | ||
time.sleep(1) #wait 1 seconde before send a new transaction |
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.
wait 1 second before sending a new transaction
src/tx.py
Outdated
@@ -139,7 +139,7 @@ def generate_transaction_document(ep,issuers,AmountTransfered,listinput_and_amou | |||
def get_list_input_for_transaction(ep,pubkey,TXamount,allinput = False): | |||
#real source in blockchain | |||
sources = request(ep, "tx/sources/" + pubkey)["sources"] | |||
if sources == None: return(None) | |||
if sources == None: return None |
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.
if not sources: return None
src/tx.py
Outdated
@@ -139,7 +139,7 @@ def generate_transaction_document(ep,issuers,AmountTransfered,listinput_and_amou | |||
def get_list_input_for_transaction(ep,pubkey,TXamount,allinput = False): | |||
#real source in blockchain | |||
sources = request(ep, "tx/sources/" + pubkey)["sources"] | |||
if sources == None: return(None) | |||
if sources == None: return None | |||
listinput = []; |
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.
le ; qui tue :p
src/tx.py
Outdated
transaction += sign_document_from_seed(transaction,seed)+"\n" | ||
|
||
retour = post_request(ep, "tx/process", "transaction="+urllib.parse.quote_plus(transaction)) | ||
print("Successful Transaction") |
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.
Transaction successfully sent.
src/tx.py
Outdated
if input in listinput: | ||
listinput.remove(input) | ||
|
||
#generate final liste source |
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.
list
src/tx.py
Outdated
if not OutputbackChange: | ||
OutputbackChange = issuers | ||
|
||
#si c'est pas une transaction de change, on retire les unité à + de 2 chiffres apres la virgule. |
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.
french comment.
src/tools.py
Outdated
res = ''.join(res[::-1]) | ||
|
||
# Encode leading zeros as base58 zeros | ||
import sys |
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.
import at file beginning
src/silkaj.py
Outdated
|
||
elif c.subcmd == "generate_auth_file": | ||
generate_auth_file(c) | ||
|
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.
One space surplus.
You really don't want to commit things as root. Because first, it will use the git config of the root account which obviously is not configured at all, second because it will create files in your tree that are root-owned that you later on won't be able to edit as user, and finally because it obviously confuses github which doesn't know who root is because the commit log doesn't have your email. You should really fix this commit. First, make sure all files are owned by your user: ~/silkaj $ id # as user, will tell you your own user ID and groups, like:
uid=1000(tortue) gid=1000(tortue) groupes=1000(tortue),20(dialout)
~/silkaj $ sudo chown -R 1000:1000 * .git Then, still as user, redo the bad commit (on the transaction branch): ~/silkaj $ git stash # this stashes away all non-committed changes
~/silkaj $ git rebase -i master # this rebases all commits onto the master branch
# Now change in the first line "pick" to "edit", should look like:
edit 3865029 add transaction feature
pick 423f38b re add argos
pick bab1d27 remove comment
pick 2c6c0db Typo correction (thanks Jytou)
pick 3bcea48 Remove useless spaces and back lines
pick a216bb1 remove useless test
pick 3708358 correct my bad english (thanks jytou)
pick 2dfbfa4 remove useless back line
# save the file...
# Now it says you can amend the first commit, so let's force it to have the correct author:
git commit --amend --author='Tortue95 <github@tednet.fr>'
# save the commit log
# continue the rebase
git rebase --continue Then you'll have to force push on github (git push -f), but it will overwrite the commits, and also the review others made on them... So make sure you address them first. Next time you really want to do only one thing by branch instead of putting unrelated stuff ;-) |
I have an issue installing |
|
src/commands.py
Outdated
print("Quantitative =", round((totalAmountInput-amount)/100,2), currency_name +"\n") | ||
|
||
|
||
print("Total Ammount of : " + pubkey) |
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.
Total amount of:
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.
Big typography review.
You could use pep8 python formating on the futur.
src/tools.py
Outdated
|
||
|
||
def get_seed_from_scrypt(salt,password, N=4096, r=16, p=1): | ||
seed = scrypt.hash(password,salt,N,r,p,32) |
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.
spaces (password, salt, N, r, p, 32)
src/tools.py
Outdated
listinput = [] | ||
amount = 0 | ||
for source in sources: | ||
amount += source["amount"]*10**source["base"] |
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.
spaces between operators: source["amount"] * 10 ** source["base"]
src/tools.py
Outdated
amount = 0 | ||
for source in sources: | ||
amount += source["amount"]*10**source["base"] | ||
listinput.append(str(source["amount"])+":"+str(source["base"])+":"+str(source["type"])+":"+str(source["identifier"])+":"+str(source["noffset"])) |
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.
spaces around +
.
src/tools.py
Outdated
|
||
|
||
#pending source | ||
history = request(ep, "tx/history/"+ pubkey+"/pending")["history"] |
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.
spaces around +
.
src/tools.py
Outdated
blockstamp = pending["blockstamp"] | ||
block_number = int(blockstamp.split("-")[0]) | ||
#if it's not an old transaction (bug in mirror node) | ||
if block_number >= last_block_number-3: |
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.
spaces around -
operator.
src/commands.py
Outdated
exit() | ||
|
||
if c.contains_definitions('amount'): | ||
amount = int(float(c.get_definition('amount'))*100) |
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.
spaces around *
.
Same two lines below.
src/auth.py
Outdated
def auth_by_scrypt(): | ||
salt = input("Please enter your Scrypt Salt (Secret identifier):") | ||
password = getpass.getpass("Please enter your Scrypt password (masked):") | ||
scrypt_param = input("Please enter your Scrypt parameters (N,r,p): [4096,16,1]") |
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.
spaces after ,
.
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.
Nah, it's ok.
It will be harder to split for below lines.
src/auth.py
Outdated
else: | ||
file = "authfile" | ||
if not os.path.isfile(file): | ||
print("Error: the file \""+file+"\" does not exist") |
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.
spaces around +
.
src/auth.py
Outdated
return auth_by_scrypt() | ||
if c.contains_switches('auth-seed'): | ||
return auth_by_seed() | ||
#if c.contains_switches('auth-wif'): ### for the future |
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.
Could be kept on your side for futur contribution.
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.
can be remove i you want
README.md
Outdated
@@ -28,7 +30,7 @@ sudo (apt-get or dnf) install python-tabulate python-ipaddress | |||
``` | |||
|
|||
### Integrate it on a dropdown menu to the panel | |||
Under GNOME Shell, with [Argos](https://github.com/p-e-w/argos) extension: | |||
Under GNOME Shell, with [Argos](https://github.com/p-e-w/argos) extension: |
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.
My unbreakable space 😄
src/auth.py
Outdated
if not scrypt_param: | ||
scrypt_param = "4096,16,1" | ||
scrypt_param_splited= scrypt_param.split(",") | ||
n=int(scrypt_param_splited[0]) |
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.
spaces around =
.
For two following lines.
src/auth.py
Outdated
n=int(scrypt_param_splited[0]) | ||
r=int(scrypt_param_splited[1]) | ||
p=int(scrypt_param_splited[2]) | ||
if(n <= 0 or n > 65536 or r <= 0 or r > 512 or p <= 0 or p > 32): |
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.
if (
.
src/auth.py
Outdated
if(n <= 0 or n > 65536 or r <= 0 or r > 512 or p <= 0 or p > 32): | ||
print("Error: the values of Scrypt parameters are not good") | ||
|
||
seed = get_seed_from_scrypt(salt,password, n, r, p) |
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.
space after salt,
.
src/tools.py
Outdated
inputsplit = input.split(":") | ||
totalAmountInput += int(inputsplit[0])*10**int(inputsplit[1]) | ||
|
||
return int(totalAmountInput),int(amount) |
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.
space after ,
.
src/tools.py
Outdated
# Convert big-endian bytes to integer | ||
n = int('0x0' + nacl.encoding.HexEncoder.encode(b).decode('utf8'), 16) | ||
|
||
# Divide that integer into bas58 |
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.
base58
src/tx.py
Outdated
listinput_and_amount = get_list_input_for_transaction(ep,issuers,AmountTransfered,all_input) | ||
transactionintermediaire = listinput_and_amount[2] | ||
|
||
if transactionintermediaire: |
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.
intermediary
src/tx.py
Outdated
TXamount -= int(inputsplit[0])*10**int(inputsplit[1]) | ||
#if more 40 sources, it's an intermediate transaction | ||
if len(listinputfinal) >= 40: | ||
transactionintermediaire = True |
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.
french
I modified the history. Transactions works fine. @Tortue95, there is still two important remarks I let you answer. Then we could merge it. Thanks for this awesome work. |
- authentication feature: - scrypt - seed - authfile - pubkey money amount
- add space after imput prompt.
url = "http://" + ep[address] + ":" + ep["port"] + "/" + path | ||
if ep["port"] == "443": | ||
url = "https://" + ep[address] + "/" + path | ||
request = urllib.request.Request(url,bytes(postdata, 'utf-8')) |
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.
space after ,
.
currency_name = str(current_blk["currency"]) | ||
|
||
|
||
if totalAmountInput-amount != 0: |
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.
spaces around -
.
print("Blockchain:") | ||
print("-----------") | ||
print("Relative =", round(amount / DUvalue, 2), "DU", currency_name) | ||
print("Quantitative =", round(amount / 100, 2), currency_name+"\n") |
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.
spaces around +
.
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.
Nice!
No description provided.