def post(self): args = self.reqparse.parse_args() # analyze transaction try: analysis = hodl_api.analyze_tx(args['rawtx']) except Exception as e: error_msg = "couldn't analyze this transaction" return({'error': error_msg, 'exception': str(e)}) # check if it complies with minimum allowed locked amount if analysis['lockedSatoshis'] < MIN_AMOUNT_SAT: error_msg = 'minimum amount is ' + str(MIN_AMOUNT) return({'error': error_msg}) elif analysis['lockedSatoshis'] > MAX_AMOUNT_SAT: error_msg = 'maximum amount is ' + str(MAX_AMOUNT) return({'error': error_msg}) # check if tx is not trying to get rewards for less than # the minimum allowed vesting period, or more than maximum nLockTime = analysis['nLockTime'] now = int(time.time()) min_unlock_time = now + MIN_VEST_TIME_SEC max_unlock_time = now + MAX_VEST_TIME_SEC if nLockTime < (min_unlock_time - TOLERANCE_SEC): error_msg = 'Code expired or vesting period is too short.' return({'error': error_msg}) elif nLockTime > (max_unlock_time + MAX_VEST_TIME_SEC): error_msg = "You're hodling yourself out of existence!" return({'error': error_msg}) elif nLockTime > (max_unlock_time + TOLERANCE_SEC): error_msg = 'Vesting period too long.' return({'error': error_msg}) else: try: tx_broadcast_output = hodl_api.tx_broadcast(args['rawtx']) if 'error' in tx_broadcast_output: raise Exception("something wrong!") except Exception as e: print(e) error_msg = ("There was a problem " + "broadcasting this transaction.") return({'error': error_msg}) else: try: payee_data = {} payee_data['hodlFundTxId'] = tx_broadcast_output['txid'] payee_data['payeeAddress'] = analysis['hodlAddress'] payee_data['reward'] = int( analysis['lockedSatoshis'] * REWARD_RATIO(nLockTime - now)) to_queue(payee_data, 'transactions') except Exception as e: print(e) error_msg = ("There was a problem " + "scheduling reward payment, please report.") return({'error': error_msg}) return(tx_broadcast_output)
def requeue_txs(): q = 'unconfirmed' output = False method, header, body = channel.basic_get(queue=q) if body is not None: output = True msg_json = json.loads(body.decode()) txid = msg_json['hodlFundTxId'] print("Re-queuing " + txid + " for check out.") to_queue(msg_json, 'transactions') channel.basic_ack(delivery_tag=method.delivery_tag) return (output)
def filter_txs(): q = 'transactions' output = False method, header, body = channel.basic_get(queue=q) if body is not None: output = True msg_json = json.loads(body.decode()) txid = msg_json['hodlFundTxId'] addr = msg_json['payeeAddress'] try: confirmed = is_confirmed(addr, txid) if confirmed is True: print("Moving transaction " + txid + ' to "confirmed" queue.') to_queue(msg_json, 'confirmed') else: print(txid + " still unconfirmed.") to_queue(msg_json, 'unconfirmed') channel.basic_ack(delivery_tag=method.delivery_tag) except Exception as e: raise Exception(e) return (output)