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']
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))
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)
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']}")
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)
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)
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")
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']
def inner(*args, **kwargs): result = fn(*args, **kwargs) return gdk_resolve(result)
def createtransaction(session, details): """Create an outgoing transaction.""" return gdk_resolve( gdk.create_transaction(session.session_obj, json.dumps(details)))
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)
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"]
def _create_tx(tx): return gdk_resolve(gdk.create_transaction(context.session.session_obj, json.dumps(tx)))
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)
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