Skip to content

Commit 157ca93

Browse files
author
f321x
committed
make try except more concise, add verbose param to package_broadcast
1 parent c8ce23a commit 157ca93

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

electrumx/server/session.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ async def transaction_broadcast(self, raw_tx):
14741474
self.logger.info(f'sent tx: {hex_hash}')
14751475
return hex_hash
14761476

1477-
async def package_broadcast(self, tx_package: List[str]):
1477+
async def package_broadcast(self, tx_package: List[str], verbose: bool = False) -> dict:
14781478
"""Broadcast a package of raw transactions to the network (submitpackage).
14791479
The package must consist of a child with its parents,
14801480
and none of the parents may depend on one another.
@@ -1483,12 +1483,13 @@ async def package_broadcast(self, tx_package: List[str]):
14831483
self.bump_cost(0.25 + sum(len(tx) / 5000 for tx in tx_package))
14841484
try:
14851485
txids = [sha256(bytes.fromhex(tx)).hex() for tx in tx_package]
1486-
result = await self.session_mgr.broadcast_package(tx_package)
14871486
except ValueError:
14881487
self.logger.info(f"error calculating txids: {traceback.format_exc()}")
14891488
raise RPCError(
14901489
BAD_REQUEST,
14911490
f'not a valid hex encoded transaction package: {tx_package}')
1491+
try:
1492+
result = await self.session_mgr.broadcast_package(tx_package)
14921493
except DaemonError as e:
14931494
error, = e.args
14941495
message = error['message']
@@ -1497,16 +1498,11 @@ async def package_broadcast(self, tx_package: List[str]):
14971498
f'network rules.\n\n{message}. Package txids: {txids}')
14981499
else:
14991500
self.txs_sent += len(tx_package)
1500-
client_ver = util.protocol_tuple(self.client)
1501-
if client_ver != (0, ):
1502-
msg = self.coin.warn_old_client_on_tx_broadcast(client_ver)
1503-
if msg:
1504-
self.logger.info(f'sent package: {txids}. and warned user to upgrade their '
1505-
f'client from {self.client}')
1506-
return msg
1507-
15081501
self.logger.info(f'broadcasted package: {txids}')
1509-
return result
1502+
if verbose:
1503+
return result
1504+
return {'package_msg': result.get('package_msg', ''),
1505+
'replaced_txs': result.get('replaced_txs', [])}
15101506

15111507
async def transaction_get(self, tx_hash, verbose=False):
15121508
'''Return the serialized raw transaction given its hash

0 commit comments

Comments
 (0)