Skip to content
Snippets Groups Projects
Commit 5a40e408 authored by Moul's avatar Moul
Browse files

[mod] #328: cert/tx: Import top-level Click module

parent 352bc49f
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>. ...@@ -16,7 +16,7 @@ along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
""" """
import sys import sys
from click import command, argument, echo, confirm import click
from time import time from time import time
from tabulate import tabulate from tabulate import tabulate
from duniterpy.api import bma from duniterpy.api import bma
...@@ -33,8 +33,8 @@ from silkaj.constants import SUCCESS_EXIT_STATUS ...@@ -33,8 +33,8 @@ from silkaj.constants import SUCCESS_EXIT_STATUS
from silkaj.crypto_tools import is_pubkey_and_check from silkaj.crypto_tools import is_pubkey_and_check
@command("cert", help="Send certification") @click.command("cert", help="Send certification")
@argument("uid_pubkey_to_certify") @click.argument("uid_pubkey_to_certify")
@coroutine @coroutine
async def send_certification(uid_pubkey_to_certify): async def send_certification(uid_pubkey_to_certify):
client = ClientInstance().client client = ClientInstance().client
...@@ -144,7 +144,7 @@ async def certification_confirmation( ...@@ -144,7 +144,7 @@ async def certification_confirmation(
cert_begins = convert_time(time(), "date") cert_begins = convert_time(time(), "date")
cert_ends = convert_time(time() + params["sigValidity"], "date") cert_ends = convert_time(time() + params["sigValidity"], "date")
cert.append(["Valid", cert_begins, "—>", cert_ends]) cert.append(["Valid", cert_begins, "—>", cert_ends])
echo(tabulate(cert, tablefmt="fancy_grid")) click.echo(tabulate(cert, tablefmt="fancy_grid"))
if not confirm("Do you confirm sending this certification?"): if not click.confirm("Do you confirm sending this certification?"):
await client.close() await client.close()
sys.exit(SUCCESS_EXIT_STATUS) sys.exit(SUCCESS_EXIT_STATUS)
...@@ -19,7 +19,7 @@ from re import compile, search ...@@ -19,7 +19,7 @@ from re import compile, search
import math import math
from asyncio import sleep from asyncio import sleep
from tabulate import tabulate from tabulate import tabulate
from click import command, option, FloatRange import click
from silkaj import cli_tools from silkaj import cli_tools
from silkaj import network_tools as nt from silkaj import network_tools as nt
...@@ -44,37 +44,37 @@ from duniterpy.documents.transaction import OutputSource, Unlock, SIGParameter ...@@ -44,37 +44,37 @@ from duniterpy.documents.transaction import OutputSource, Unlock, SIGParameter
MAX_COMMENT_LENGTH = 255 MAX_COMMENT_LENGTH = 255
@command("tx", help="Send transaction") @click.command("tx", help="Send transaction")
@option( @click.option(
"amounts", "amounts",
"--amount", "--amount",
"-a", "-a",
multiple=True, multiple=True,
type=FloatRange(MINIMAL_ABSOLUTE_TX_AMOUNT), type=click.FloatRange(MINIMAL_ABSOLUTE_TX_AMOUNT),
help="Quantitative amount(s):\n-a <amount>\nMinimum amount is {0}".format( help="Quantitative amount(s):\n-a <amount>\nMinimum amount is {0}".format(
MINIMAL_ABSOLUTE_TX_AMOUNT MINIMAL_ABSOLUTE_TX_AMOUNT
), ),
cls=cli_tools.MutuallyExclusiveOption, cls=cli_tools.MutuallyExclusiveOption,
mutually_exclusive=["amountsud", "allsources"], mutually_exclusive=["amountsud", "allsources"],
) )
@option( @click.option(
"amountsud", "amountsud",
"--amountUD", "--amountUD",
"-d", "-d",
multiple=True, multiple=True,
type=FloatRange(MINIMAL_RELATIVE_TX_AMOUNT), type=click.FloatRange(MINIMAL_RELATIVE_TX_AMOUNT),
help=f"Relative amount(s):\n-d <amount_UD>\nMinimum amount is {MINIMAL_RELATIVE_TX_AMOUNT}", help=f"Relative amount(s):\n-d <amount_UD>\nMinimum amount is {MINIMAL_RELATIVE_TX_AMOUNT}",
cls=cli_tools.MutuallyExclusiveOption, cls=cli_tools.MutuallyExclusiveOption,
mutually_exclusive=["amounts", "allsources"], mutually_exclusive=["amounts", "allsources"],
) )
@option( @click.option(
"--allSources", "--allSources",
is_flag=True, is_flag=True,
help="Send all sources to one recipient", help="Send all sources to one recipient",
cls=cli_tools.MutuallyExclusiveOption, cls=cli_tools.MutuallyExclusiveOption,
mutually_exclusive=["amounts", "amountsud"], mutually_exclusive=["amounts", "amountsud"],
) )
@option( @click.option(
"recipients", "recipients",
"--recipient", "--recipient",
"-r", "-r",
...@@ -85,15 +85,23 @@ Sending to many recipients is possible:\n\ ...@@ -85,15 +85,23 @@ Sending to many recipients is possible:\n\
* With one amount, all will receive the amount\n\ * With one amount, all will receive the amount\n\
* With many amounts (one per recipient)", * With many amounts (one per recipient)",
) )
@option("--comment", "-c", default="", help="Comment") @click.option("--comment", "-c", default="", help="Comment")
@option( @click.option(
"--outputBackChange", "--outputBackChange",
help="Pubkey recipient to send the rest of the transaction: <pubkey[:checksum]>", help="Pubkey recipient to send the rest of the transaction: <pubkey[:checksum]>",
) )
@option("--yes", "-y", is_flag=True, help="Assume yes. Do not prompt confirmation") @click.option(
"--yes", "-y", is_flag=True, help="Assume yes. Do not prompt confirmation"
)
@tools.coroutine @tools.coroutine
async def send_transaction( async def send_transaction(
amounts, amountsud, allsources, recipients, comment, outputbackchange, yes amounts,
amountsud,
allsources,
recipients,
comment,
outputbackchange,
yes,
): ):
""" """
Main function Main function
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment