Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions bit/network/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,12 @@ def get_unspent_testnet(cls, address):

@classmethod
def broadcast_tx(cls, tx_hex): # pragma: no cover
r = requests.post(cls.MAIN_TX_PUSH_API, data={cls.TX_PUSH_PARAM: tx_hex}, timeout=DEFAULT_TIMEOUT)
r = requests.post(cls.MAIN_TX_PUSH_API, data=tx_hex, timeout=DEFAULT_TIMEOUT)
return True if r.status_code == 200 else False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ternary operator True if ... else False is redundant here. The comparison r.status_code == 200 already evaluates to a boolean, which can be returned directly. This simplifies the code and improves readability.

Suggested change
return True if r.status_code == 200 else False
return r.status_code == 200


@classmethod
def broadcast_tx_testnet(cls, tx_hex): # pragma: no cover
r = requests.post(cls.TEST_TX_PUSH_API, data={cls.TX_PUSH_PARAM: tx_hex}, timeout=DEFAULT_TIMEOUT)
r = requests.post(cls.TEST_TX_PUSH_API, data=tx_hex, timeout=DEFAULT_TIMEOUT)
return True if r.status_code == 200 else False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the broadcast_tx function, this conditional return can be simplified by returning the boolean result of the comparison directly.

Suggested change
return True if r.status_code == 200 else False
return r.status_code == 200



Expand Down Expand Up @@ -980,11 +980,7 @@ class NetworkAPI:
BitcoreAPI.get_unspent, # No limit
]
BROADCAST_TX_MAIN = [
BlockchairAPI.broadcast_tx,
BlockstreamAPI.broadcast_tx,
BitcoreAPI.broadcast_tx,
SmartbitAPI.broadcast_tx, # Limit 5/minute
BlockchainAPI.broadcast_tx,
]
Comment on lines 982 to 984

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This change correctly removes the defunct API providers, which is a necessary fix for the immediate issue. However, this makes blockstream.info the sole provider for broadcasting transactions, creating a single point of failure. If Blockstream's API becomes unavailable or rate-limits requests, transaction broadcasting will be completely broken.

While this is a significant improvement over the previous silently-failing state, for long-term resilience, it would be beneficial to either:

  • Investigate and add other reliable, public broadcast endpoints.
  • Implement a way for users to configure their own preferred broadcast endpoints or even connect to their own node for broadcasting.


GET_BALANCE_TEST = [
Expand All @@ -1010,10 +1006,7 @@ class NetworkAPI:
BitcoreAPI.get_unspent_testnet, # No limit
]
BROADCAST_TX_TEST = [
BlockchairAPI.broadcast_tx_testnet,
BlockstreamAPI.broadcast_tx_testnet,
BitcoreAPI.broadcast_tx_testnet,
SmartbitAPI.broadcast_tx_testnet, # Limit 5/minute
]

@classmethod
Expand Down