Beispiel #1
0
def _send_transaction(session, details):
    details = gdk_resolve(
        gdk.create_transaction(session.session_obj, json.dumps(details)))
    details = gdk_resolve(
        gdk.sign_transaction(session.session_obj, json.dumps(details)))
    details = gdk_resolve(
        gdk.send_transaction(session.session_obj, json.dumps(details)))
    return details['txhash']
Beispiel #2
0
def getsystemmessages(session):
    """Get unread system messages."""
    while True:
        message = gdk.get_system_message(session.session_obj)
        if not message:
            break

        click.echo("--- MESSAGE STARTS ---")
        click.echo(message)
        click.echo("--- MESSAGE ENDS ---")
        if not click.confirm("Mark message as read (sign and send acknowledgement to the server)?"):
            break

        gdk_resolve(gdk.ack_system_message(session.session_obj, message))
Beispiel #3
0
    def inner(session, *args, **kwargs):
        if not context.logged_in:
            logging.info("Logging in")
            result = context.authenticator.login(session.session_obj)
            gdk_resolve(result)
            context.logged_in = True

            if not context.no_warn_sysmsg:
                # Show the user a prompt to read and acknowledge outstanding system messages
                system_message = gdk.get_system_message(session.session_obj)
                if system_message:
                    click.echo(
                        "You have unread system messages, please call getsystemmessages"
                    )

        return fn(session, *args, **kwargs)
Beispiel #4
0
def send(session):
    """Send/broadcast the current transaction."""
    with Tx(allow_errors=False, recreate=False) as tx:
        sent = gdk_resolve(gdk.send_transaction(session.session_obj, json.dumps(tx)))
        tx.clear()
        tx.update(sent)
        click.echo(f"{tx['txhash']}")
Beispiel #5
0
def sign(session):
    """Sign the current transaction."""
    with Tx(allow_errors=False, recreate=False) as tx:
        signed = gdk_resolve(
            gdk.sign_transaction(session.session_obj, json.dumps(tx)))
        tx.clear()
        tx.update(signed)
Beispiel #6
0
    def inner(session, *args, **kwargs):
        if not context.logged_in:
            logging.info("Logging in")
            result = context.authenticator.login(session.session_obj)
            # authenticator.login attempts to abstract the actual login method, it may call
            # GA_login, GA_login_with_pin or GA_login_watch_only
            # Unfortunately only GA_login returns an auth_handler, so both cases must be handled
            if result:
                gdk_resolve(result)
            context.logged_in = True

            if not context.no_warn_sysmsg:
                # Show the user a prompt to read and acknowledge outstanding system messages
                system_message = gdk.get_system_message(session.session_obj)
                if system_message:
                    click.echo(
                        "You have unread system messages, please call getsystemmessages"
                    )

        return fn(session, *args, **kwargs)
Beispiel #7
0
def _get_transaction(session, txid):
    # TODO: Iterate all pages
    # 900 is slightly arbitrary but currently the backend is limited to 30 pages of 30
    details = {'subaccount': 0, 'first': 0, 'count': 900}
    transactions = gdk_resolve(
        gdk.get_transactions(session.session_obj, json.dumps(details)))
    transactions = transactions['transactions']
    for transaction in transactions:
        if transaction['txhash'] == txid:
            return transaction
    raise click.ClickException("Previous transaction not found")
Beispiel #8
0
def add_utxos_to_transaction(session, details):
    """Add UTXOs to transaction details JSON for create_transaction"""
    # Note: We check 'private_key' here for manually built txs/future sweeping support
    if 'utxos' not in details and 'private_key' not in details:
        num_confs = 1 if 'previous_transaction' in details else 0
        utxo_details = {
            'subaccount': details['subaccount'],
            'num_confs': num_confs
        }
        utxos = gdk_resolve(
            gdk.get_unspent_outputs(session.session_obj,
                                    json.dumps(utxo_details)))
        details['utxos'] = utxos['unspent_outputs']
Beispiel #9
0
 def inner(*args, **kwargs):
     result = fn(*args, **kwargs)
     return gdk_resolve(result)
Beispiel #10
0
def createtransaction(session, details):
    """Create an outgoing transaction."""
    return gdk_resolve(
        gdk.create_transaction(session.session_obj, json.dumps(details)))
Beispiel #11
0
def gettransactions(session, summary, details):
    """Get transactions associated with the wallet."""
    result = gdk.get_transactions(session.session_obj, json.dumps(details))
    result = gdk_resolve(result)
    result = _txlist_summary(result) if summary else format_output(result)
    click.echo(result)
Beispiel #12
0
def getnewaddress(session, details):
    """Get a new receive address."""
    auth_handler = gdk.get_receive_address(session.session_obj,
                                           json.dumps(details))
    return gdk_resolve(auth_handler)["address"]
Beispiel #13
0
def _create_tx(tx):
    return gdk_resolve(gdk.create_transaction(context.session.session_obj, json.dumps(tx)))
Beispiel #14
0
def gettransactions(session, summary, details):
    result = gdk.get_transactions(session.session_obj, json.dumps(details))
    result = gdk_resolve(result)
    result = _txlist_summary(result) if summary else format_output(result)
    click.echo(result)
Beispiel #15
0
def _create_tx(tx):
    add_utxos_to_transaction(context.session, tx)
    tx = gdk_resolve(
        gdk.create_transaction(context.session.session_obj, json.dumps(tx)))
    return tx