-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
commandlines | ||
ipaddress | ||
tabulate | ||
pynacl | ||
scrypt |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from tools import * | ||
import getpass | ||
import os | ||
|
||
def auth_method(c): | ||
if c.contains_switches('auth-scrypt'): | ||
return auth_by_scrypt() | ||
if c.contains_switches('auth-seed'): | ||
return auth_by_seed() | ||
if c.contains_switches('auth-file'): | ||
return auth_by_auth_file(c) | ||
print("Error: no authentication method") | ||
exit() | ||
|
||
def generate_auth_file(c): | ||
if c.contains_definitions('file'): | ||
file = c.get_definition('file') | ||
else: | ||
file = "authfile" | ||
seed = auth_method(c) | ||
with open(file, "w") as f: | ||
f.write(seed) | ||
print("Authfile generated for the public key: ", get_publickey_from_seed(seed)) | ||
|
||
def auth_by_auth_file(c): | ||
if c.contains_definitions('file'): | ||
file = c.get_definition('file') | ||
else: | ||
file = "authfile" | ||
if not os.path.isfile(file): | ||
print("Error: the file \"" + file + "\" does not exist") | ||
exit() | ||
with open(file) as f: | ||
seed = f.read() | ||
regex = re.compile('^[0-9a-fA-F]{64}$') | ||
if not re.search(regex, seed): | ||
print("Error: the format of the file is invalid") | ||
exit() | ||
return seed | ||
|
||
def auth_by_seed(): | ||
seed = input("Please enter your seed on hex format: ") | ||
regex = re.compile('^[0-9a-fA-F]{64}$') | ||
if not re.search(regex, seed): | ||
print("Error: the format of the seed is invalid") | ||
exit() | ||
return seed | ||
|
||
|
||
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]") | ||
if not scrypt_param: | ||
scrypt_param = "4096,16,1" | ||
scrypt_param_splited= scrypt_param.split(",") | ||
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): | ||
print("Error: the values of Scrypt parameters are not good") | ||
|
||
seed = get_seed_from_scrypt(salt, password, n, r, p) | ||
return seed |
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
from operator import itemgetter | ||
|
||
from network_tools import * | ||
from tx import * | ||
from auth import * | ||
from tools import * | ||
|
||
def currency_info(ep): | ||
|
@@ -165,6 +167,82 @@ def list_issuers(ep, nbr, last): | |
print("from {0} issuers\n{1}".format(len(list_issued), | ||
tabulate(sorted_list, headers="keys", tablefmt="orgtbl", floatfmt=".1f", stralign="center"))) | ||
|
||
|
||
def cmd_amount(ep, c): | ||
if c.contains_definitions('pubkey'): | ||
pubkey = c.get_definition('pubkey') | ||
pubkey = check_public_key(pubkey) | ||
else: | ||
seed = auth_method(c) | ||
pubkey = get_publickey_from_seed(seed) | ||
|
||
show_amount_from_pubkey(ep, pubkey) | ||
|
||
|
||
def cmd_transaction(ep, c): | ||
seed = auth_method(c) | ||
|
||
if not (c.contains_definitions('amount') or c.contains_definitions('amountDU')): | ||
print("--amount or --amountDU is not set") | ||
exit() | ||
if not c.contains_definitions('output'): | ||
print("--output is not set") | ||
exit() | ||
|
||
if c.contains_definitions('amount'): | ||
amount = int(float(c.get_definition('amount')) * 100) | ||
if c.contains_definitions('amountDU'): | ||
du = get_last_du_value(ep) | ||
amount = int(float(c.get_definition('amountDU')) * du) | ||
|
||
output = c.get_definition('output') | ||
|
||
if c.contains_definitions('comment'): | ||
comment = c.get_definition('comment') | ||
else: | ||
comment = "" | ||
|
||
if c.contains_switches('allSources'): | ||
allSources = True | ||
else: | ||
allSources = False | ||
|
||
if c.contains_definitions('outputBackChange'): | ||
outputBackChange = c.get_definition('outputBackChange') | ||
else: | ||
outputBackChange = None | ||
|
||
generate_and_send_transaction(ep, seed, amount, output, comment, allSources, outputBackChange) | ||
|
||
|
||
def show_amount_from_pubkey(ep, pubkey): | ||
|
||
value = get_amount_from_pubkey(ep, pubkey) | ||
totalAmountInput = value[0] | ||
amount = value[1] | ||
#output | ||
DUvalue = get_last_du_value(ep) | ||
current_blk = get_current_block(ep) | ||
currency_name = str(current_blk["currency"]) | ||
|
||
|
||
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") | ||
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. spaces around |
||
|
||
print("Pending Transaction:") | ||
print("--------------------") | ||
print("Relative =", round((totalAmountInput - amount) / DUvalue, 2), "DU", currency_name) | ||
print("Quantitative =", round((totalAmountInput - amount) / 100, 2), currency_name + "\n") | ||
|
||
|
||
print("Total amount of: " + pubkey) | ||
print("----------------------------------------------------------------") | ||
print("Total Relative =", round(totalAmountInput / DUvalue, 2), "DU", currency_name) | ||
print("Total Quantitative =", round(totalAmountInput / 100, 2), currency_name + "\n") | ||
|
||
def argos_info(ep): | ||
info_type = ["newcomers", "certs", "actives", "leavers", "excluded", "ud", "tx"] | ||
pretty_names = {'g1': 'Ğ1', 'gtest': 'Ğtest'} | ||
|
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 |
---|---|---|
|
@@ -93,6 +93,21 @@ def request(ep, path): | |
encoding = response.info().get_content_charset('utf8') | ||
return (json.loads(response.read().decode(encoding))) | ||
|
||
def post_request(ep, path, postdata): | ||
address = best_node(ep, 0) | ||
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,bytes(postdata, 'utf-8')) | ||
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. space after |
||
try: | ||
response = urllib.request.urlopen(request) | ||
except urllib.error.URLError as e: | ||
print(e) | ||
exit() | ||
encoding = response.info().get_content_charset('utf8') | ||
return (json.loads(response.read().decode(encoding))) | ||
|
||
def best_node(ep, main): | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
addresses, port = {"ip6", "ip4", "domain"}, int(ep["port"]) | ||
|
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
Oops, something went wrong.
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.
spaces around
-
.