URLs for transactions and operations
I've pretty much arrived at some working code for getting a direct link on HiveHub to any operation.
I would love it if we could unify and have even radically different block explorers use the same URL schema. At the moment they diverge.
https://hivescan.info/transaction/9b21c4345492472dbb33cfb51a8e4cd03a5df2e2
https://hivehub.dev/tx/9b21c4345492472dbb33cfb51a8e4cd03a5df2e2
Where it gets a bit more fiddly is trying to deep link in to some virtual ops. That does appear to be possible mostly on HiveHub and the following python works for everything I've thrown at it. I would love to see Hivescan honor the same urls:
Right now there is no way to deep link to a producer_reward
here but there is on HiveHub. Also the links to virtual operations associated with a real one don't work here. op_in_trx
is a counter of the operations in each trx_id
counting from 1 (not 0).
class HiveExp(StrEnum):
HiveHub = "https://hivehub.dev/{prefix_path}"
HiveScanInfo = "https://hivescan.info/{prefix_path}"
# HiveBlockExplorer = "https://hiveblockexplorer.com/{prefix_path}"
# HiveExplorer = "https://hivexplorer.com/{prefix_path}"
def get_hive_block_explorer_link(
trx_id: str,
block_explorer: HiveExp = HiveExp.HiveHub,
markdown: bool = False,
block_num: int = 0,
op_in_trx: int = 0,
realm: OpRealm = OpRealm.REAL,
# any_op: OpBase | None = None,
) -> str:
"""
Generate a Hive blockchain explorer URL for a given transaction ID.
Args:
trx_id (str): The transaction ID to include in the URL
block_explorer (HiveExp): The blockchain explorer to use (defaults to HiveHub)
Returns:
str: The complete URL with the transaction ID inserted
"""
if trx_id and not (block_num and op_in_trx):
path = f"{trx_id}"
prefix = "tx/"
elif trx_id == "0000000000000000000000000000000000000000" and block_num:
op_in_trx = op_in_trx if op_in_trx else 1
prefix = f"{block_num}/"
path = f"{trx_id}/{op_in_trx}"
elif trx_id and block_num and op_in_trx and realm == OpRealm.VIRTUAL:
path = f"{block_num}/{trx_id}/{op_in_trx}"
prefix = "tx/"
elif trx_id and op_in_trx and realm == OpRealm.REAL:
if op_in_trx > 1:
path = f"{trx_id}/{op_in_trx}"
else:
path = f"{trx_id}"
prefix = "tx/"
elif not trx_id and block_num:
path = f"{block_num}"
prefix = "b/"
if block_explorer == HiveExp.HiveScanInfo:
if prefix == "tx/":
prefix = "transaction/"
elif prefix == "b/":
prefix = "block/"
prefix_path = f"{prefix}{path}"
link_html = block_explorer.value.format(prefix_path=prefix_path)