Skip to content
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

Merged
merged 3 commits into from
Mar 27, 2017
Merged

Add Transaction feature #21

merged 3 commits into from
Mar 27, 2017

Conversation

Tortue95
Copy link
Contributor

No description provided.

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):
Copy link
Contributor

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

Copy link
Contributor

@jytou jytou left a 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+")"):
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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'
Copy link
Contributor

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')):
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmuman PR have been removed.
It seems you manually merged changes from other PR.

src/tools.py Outdated
if c == b58_digits[0]: pad += 1
else: break
return b'\x00' * pad + res

Copy link
Member

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)



Copy link
Member

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


Copy link
Member

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


Copy link
Member

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"])


Copy link
Member

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)


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One surplus empty line.

Copy link
Contributor

@jytou jytou left a 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 = [];
Copy link
Contributor

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)):
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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 = [];
Copy link
Contributor

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")
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One space surplus.

@mmuman
Copy link
Member

mmuman commented Mar 23, 2017

root committed 2 days ago

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 ;-)

@M5oul
Copy link
Member

M5oul commented Mar 24, 2017

I have an issue installing scrypt. I will test transaction feature once it will be correct.

@Tortue95
Copy link
Contributor Author

Tortue95 commented Mar 24, 2017

pip-3.2 install scrypt fonctionne bien chez moi

src/commands.py Outdated
print("Quantitative =", round((totalAmountInput-amount)/100,2), currency_name +"\n")


print("Total Ammount of : " + pubkey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total amount of:

Copy link
Member

@M5oul M5oul left a 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)
Copy link
Member

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"]
Copy link
Member

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"]))
Copy link
Member

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"]
Copy link
Member

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:
Copy link
Member

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)
Copy link
Member

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]")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces after ,.

Copy link
Member

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")
Copy link
Member

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
Copy link
Member

@M5oul M5oul Mar 24, 2017

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.

Copy link
Contributor Author

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:
Copy link
Member

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])
Copy link
Member

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):
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

french

@M5oul M5oul modified the milestones: 0.2.0, 0.3.0 Mar 26, 2017
@M5oul
Copy link
Member

M5oul commented Mar 27, 2017

I modified the history.
I squashed your commits into one with explanations. I did the same for mine.
Now, there is two commits which erased previous commits on Tortue95/silkaj:transaction.

Transactions works fine.

@Tortue95, there is still two important remarks I let you answer. Then we could merge it.

Thanks for this awesome work.

Tortue95 and others added 3 commits March 27, 2017 14:08
- 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'))
Copy link
Member

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:
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces around +.

Copy link
Member

@M5oul M5oul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@M5oul M5oul merged commit 4f9cd41 into duniter:master Mar 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants