def test_min_confirmation_invalid_2(self): with self.assertRaises(InvalidMinConfirmations): PaymentTxRequest( MAINNET_P2PKH, {MAINNET_P2PKH: val}, "1000", min_confirmations=-1, )
def payment_transactions(): """ This endpoint will be used to create a raw transaction that spends from a P2PKH address and that supports paying to multiple addresses (either P2PKH or P2SH). The endpoint should return a transaction that spends from the source address and that pays to the output addresses. An extra output for change should be included in the resulting transaction if the change is > 5430 SAT. URL: /payment_transactions Method: POST Request body (dictionary): source_address (string): The address to spend from outputs (dictionary): A dictionary that maps addresses to amounts (in SAT) fee_kb (int): The fee per kb in SAT strategy (str): One of [greedy_max_secure|greedy_max_coins|greedy_min_coins|greedy_random] min_confirmations (int): Min number of confirmations required to use UTXO as input (default 6) testnet (int): Is this a testnet transaction (default False) Response body (dictionary): raw (string): The unsigned raw transaction inputs (array of dicts): The inputs used txid (string): The transaction id vout (int): The output number script_pub_key (string): The script pub key amount (int): The amount in SAT """ if not request.is_json: raise InvalidUsage( "Check if the mimetype indicates JSON data, either application/json or application/*+json.", BAD_REQUEST, ) data_json = request.get_json() data = PaymentTxRequest( data_json.get("source_address", ""), data_json.get("outputs", ""), data_json.get("fee_kb", MIN_RELAY_FEE), data_json.get("strategy", "greedy_random"), data_json.get("min_confirmations", MIN_CONFIRMATIONS), data_json.get("testnet", False), ) response = process_payment_tx_request(data) return jsonify(response.to_dict())
def test_output_invalid_2(self): with self.assertRaises(InvalidOutputAddress): PaymentTxRequest(MAINNET_P2PKH, {"1Po1oWkD": val}, 0)
def test_output_invalid(self): with self.assertRaises(InvalidOutputAddress): PaymentTxRequest(TESTNET_P2PKH, {"mipcBbFg": val}, 0, testnet=True)
def test_output_empty__2(self): with self.assertRaises(EmptyOutputs): PaymentTxRequest(MAINNET_P2PKH, {}, 0)
def test_output_empty(self): with self.assertRaises(EmptyOutputs): PaymentTxRequest(TESTNET_P2PKH, {}, 0, testnet=True)
def test_source_address_not_supported_2(self): with self.assertRaises(NotSupportedSourceAddress): PaymentTxRequest(TESTNET_P2SH, {}, 0, testnet=True)
def test_output_amount_invalid_3(self): with self.assertRaises(InvalidOutputAmount): PaymentTxRequest(MAINNET_P2PKH, {MAINNET_P2PKH: val - 10}, 0)
def test_output_net_mismatch(self): with self.assertRaises(NetworkMismatchOutputAddress): PaymentTxRequest(TESTNET_P2PKH, {MAINNET_P2PKH: val}, 0, testnet=True)
def test_source_address_net_mismatch(self): with self.assertRaises(NetworkMismatchSourceAddress): PaymentTxRequest(TESTNET_P2PKH, {}, 0)
def test_source_address_invalid_2(self): with self.assertRaises(InvalidSourceAddress): PaymentTxRequest("abc", {}, 0)
def test_source_address_empty(self): with self.assertRaises(EmptySourceAddress): PaymentTxRequest("", {}, 0)
def test_strategy_invalid_2(self): with self.assertRaises(InvalidStrategy): PaymentTxRequest(MAINNET_P2PKH, {MAINNET_P2PKH: val}, "1000", strategy="greedy")
def test_strategy_invalid(self): with self.assertRaises(InvalidStrategy): PaymentTxRequest(MAINNET_P2PKH, {MAINNET_P2PKH: val}, 1000, strategy="aaa")
def test_fee_kb_invalid_4(self): with self.assertRaises(InvalidFee): PaymentTxRequest(MAINNET_P2PKH, {MAINNET_P2PKH: val}, 50)
def test_output_not_supported(self): with self.assertRaises(NotSupportedOutputAddress): PaymentTxRequest(TESTNET_P2PKH, {TESTNET_BECH32: val}, 0, testnet=True)
def test_output_not_supported_2(self): with self.assertRaises(NotSupportedOutputAddress): PaymentTxRequest(MAINNET_P2PKH, {MAINNET_BECH32: val}, 0)
def test_source_address_net_mismatch_2(self): with self.assertRaises(NetworkMismatchSourceAddress): PaymentTxRequest(MAINNET_P2PKH, {}, 0, testnet=True)
def test_source_address_not_supported(self): with self.assertRaises(NotSupportedSourceAddress): PaymentTxRequest(MAINNET_P2SH, {}, 0)
True, ), ( TESTNET_P2PKH, multi_output_test, 1024, strategy, 6, True, ), ] ] for n, data in enumerate(cases, 1): with self.subTest(n=n): r = PaymentTxRequest(*data) self.assertIsNotNone(r) self.assertEqual(r.source_address, data[0]) self.assertEqual(r.outputs, data[1]) self.assertEqual( r.fee_kb, int(data[2]) if len(data) > 2 and data[2] is not None else MIN_RELAY_FEE, ) self.assertEqual( r.strategy, data[3] if len(data) > 3 and data[3] is not None else DEFAULT_STRATEGY, ) self.assertEqual( r.min_confirmations,