Exemple #1
0
 def get(self, id, fields=None):
     global database
     #database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify({ 'message': 'Not authorized to access data for other users' })
         response.status_code = 403
         return response
     debug and LOGGER.warn("WorkerAPI_utxo get id:{} fields:{}".format(id, fields))
     fields = lib.fields_to_list(fields)
     utxo = Pool_utxo.get_by_userid(id)
     if utxo is None:
         return None
     return utxo.to_json(fields)
Exemple #2
0
 def post(self, id, function, address=None):
     global database
     LOGGER = lib.get_logger(PROCESS)
     debug = True
     debug and LOGGER.warn("PoolAPI_paymentrequest POST: {} - {}".format(id, function))
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify({ 'message': 'Not authorized to access data for other users' })
         response.status_code = 403
         return response
     # XXX TODO: Get from config
     payment_req_url = "http://grinwallet:13425"
     # Get the users balance then call the internal payment request api to
     # generate a payment tx slate.  Return that slate to the caller
     if function == "get_tx_slate":
         # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
         #LOGGER.warn("SLATE payment requests are disabled")
         #response = jsonify({ 'message': 'File-Based payouts are temporarily disabled' })
         #response.status_code = 400
         #return response
         # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
         ##
         # Offline Phase 1) issue_send_tx
         # Generate the send transaction slate
         utxo = Pool_utxo.get_by_userid(id)
         amount = utxo.amount
         user_id = str(utxo.user_id)
         # XXX TODO: Check if greater than minimum payout
         get_tx_slate_url = payment_req_url + "/pool/payment/get_tx_slate/"+user_id
         debug and LOGGER.warn("Requesting Payment slate: {}".format(get_tx_slate_url))
         r = requests.post(
                 url=get_tx_slate_url,
                 auth=(admin_user, admin_pass)
             )
         debug and LOGGER.warn("get_tx_slate call: {} - {}".format(r.status_code, r.reason))
         if r.status_code != 200:
             LOGGER.warn("Failed to get a payment slate: {} - {} - {}".format(r.status_code, r.reason, r.json()["message"]))
             response = jsonify({ 'message': 'Failed to get a payment slate: {}'.format(r.json()["message"])})
             response.status_code = 400
             return response
         return(json.loads(r.text))
     elif function == "submit_tx_slate":
         ##
         # Offline Phase 2) finalize_tx
         # Submit the signed slate to be finalized
         debug and LOGGER.warn("submit_slate: {}".format(id))
         try:
             requestdata = request.data
             rdjson = json.loads(requestdata.decode('utf-8'))
             debug and LOGGER.warn("PoolAPI_paymentrequest POST: requestdata:{}".format(rdjson))
         except AttributeError as e:
             LOGGER.warn("Missing tx_slate data - {}".format(request.data))
             response = jsonify({ 'message': 'Missing signed slate data' })
             response.status_code = 400
             return response
         except json.decoder.JSONDecodeError:
             LOGGER.warn("Invalid tx_slate data - {}".format(request.data))
             response = jsonify({ 'message': 'Invalid signed slate data was submitted' })
             response.status_code = 400
             return response
         debug and LOGGER.warn("submit_slate: {}".format(requestdata))
         submit_tx_slate_url = payment_req_url + "/pool/payment/submit_tx_slate/"+str(id)
         r = requests.post(
                 url=submit_tx_slate_url, 
                 data=requestdata,
                 auth=(admin_user, admin_pass)
             )
         if r.status_code != 200:
             #LOGGER.warn("Failed to submit payment slate: {} - {} - {}".format(r.status_code, r.reason, r.json()["message"]))
             #response = jsonify({ 'message': 'Failed to submit payment slate: {}'.format(r.json()["message"]) })
             LOGGER.warn("Failed to submit payment slate: {} - {}".format(r.status_code, r.reason))
             response = jsonify({ 'message': 'Failed to submit payment slate: {}'.format(r.reason) })
             response.status_code = 500
             return response
         debug and LOGGER.warn("submit_tx_slate result: {} - {}".format(r.status_code, r.text))
         return "ok"
     elif function == "http":
         ##
         # Online Wallet-To-Wallet
         debug and LOGGER.warn("Send HTTP transaction: {}".format(id))
         LOGGER.warn("request.args: {}".format(request.args))
         if address is None:
             LOGGER.warn("HTTP payment request missing address")
             response = jsonify({ 'message': 'Error, must specify a wallet address:port' })
             response.status_code = 400
             return response
         debug and LOGGER.warn("Initiate HTTP payment: {} - {}  - {}".format(id, address, request.args))
         LOGGER.warn("Args in json: {}".format(json.dumps(request.args)))
         http_payment_url = payment_req_url + "/pool/payment/http/{}/{}".format(id, address)
         r = requests.post(
                 url=http_payment_url,
                 data=json.dumps(request.args),
                 headers={'content-type': 'application/json'},
                 auth=(admin_user, admin_pass)
             )
         if r.status_code != 200:
             LOGGER.warn("Failed to complete HTTP payment: {} - {}".format(r.status_code, r.reason))
             response = jsonify({ 'message': 'Failed to complete HTTP payment: {}'.format(r.json()["message"]) })
             response.status_code = 400
             return response
         debug and LOGGER.warn("http payment result: {} - {}".format(r.status_code, r.text))
         return "ok"
     elif function == "keybase":
         ##
         # Online Wallet-To-Keybase-To-Keybase-To-Wallet
         debug and LOGGER.warn("Send keybase transaction: {}".format(id))
         if address is None:
             LOGGER.warn("keybase payment request missing address")
             response = jsonify({ 'message': 'Error, must specify a keybase username to send to' })
             response.status_code = 400
             return response
         debug and LOGGER.warn("Initiate keybase payment: {} - {}".format(id, address))
         keybase_payment_url = payment_req_url + "/pool/payment/keybase/{}/{}".format(id, address)
         r = requests.post(
                 url=keybase_payment_url, 
                 auth=(admin_user, admin_pass)
             )
         if r.status_code != 200:
             LOGGER.warn("Failed to complete keybase payment: {} - {}".format(r.status_code, r.reason))
             response = jsonify({ 'message': 'Failed to complete keybase payment: {}'.format(r.json()["message"]) })
             response.status_code = 400
             return response
         debug and LOGGER.warn("keybase payment result: {} - {}".format(r.status_code, r.text))
         return "ok"
     elif function == "payout_script":
         ##
         # Not really a payout request, rather, a request for payout automation script code
         debug and LOGGER.warn("Get Payout Script: {}".format(id))
         #file = open("/content/BGP_payout.py", "r")
         #payout_script = file.read() 
         #return payout_script
         return send_from_directory('/content', 'BGP_payout.py')
     else:
         LOGGER.warn("Invalid Payment Type requested")
         response = jsonify({ 'message': 'Error, must specify valid payment request method.  Method {} is not valid.'.format(function) })
         response.status_code = 400
         return response
Exemple #3
0
    print("Invalid state choice")
    sys.exit(1)

# Get the payout record
payout_record = Pool_payment.get_by_id(payout_id)
print("{}".format(payout_record))
amount = payout_record.amount / float(NANOGRIN)

# Get the user id
user_id = payout_record.user_id
user_record = Users.get_by_id(user_id)
username = user_record.username
print("User: {}".format(username))

# Get the users UTXO record
user_utxo = Pool_utxo.get_by_userid(user_id)

# Print a report
print("Will update account for {} on {}".format(username, poolname))
print(
    "Will cancel payout {} and add {} to users current balance of {} for a new balance of {}"
    .format(payout_id, amount,
            float(user_utxo.amount) / NANOGRIN,
            float(user_utxo.amount) / NANOGRIN + amount))

# Confirm action
print("")
proceed_or_exit()

# Do it
payout_record.state = new_state
Exemple #4
0
debit_pool = "x"
while debit_pool != "n" and debit_pool != "y":
    debit_pool = input("Debit the pools account? (y/n): ")
    if debit_pool != "n" and debit_pool != "y":
        print("Invalid input")

# Get the user id
user_id = Users.get_id_by_username(username)
if user_id == 0:
    print("Could not find user: {} in the database".format(username))
    sys.exit(1)
#user_record = Users.get_by_id(user_id)
#print(user_record)

# Get the users UTXO record
user_utxo = Pool_utxo.get_by_userid(user_id)
# Get the pools UTXO if needed
if debit_pool == "y":
    pooladmin_utxo = Pool_utxo.get_by_userid(1)

# Print a report
print("Will update account for {} on {}".format(username, poolname))
print("Will add {} to users current balance of {} for a new balance of {}".
      format(amount,
             float(user_utxo.amount) / NANOGRIN,
             float(user_utxo.amount) / NANOGRIN + amount))
if debit_pool == "y":
    print(
        "Will subtract {} from pool admin current balance of {} for a new balance of {}"
        .format(amount,
                float(pooladmin_utxo.amount) / NANOGRIN,