Skip to content

Instantly share code, notes, and snippets.

@IperGiove
Created June 13, 2024 12:50
Show Gist options
  • Save IperGiove/31bbec9d8c36c557d5f0080bfd6288ad to your computer and use it in GitHub Desktop.
Save IperGiove/31bbec9d8c36c557d5f0080bfd6288ad to your computer and use it in GitHub Desktop.
find a single address in Routescan and OSS label DB
from time import perf_counter
import numpy as np
DB = {
"oss": [
{
"name": "dapp1",
"blockchain": [
{
"address": "0x1",
"networks": [
"avalanche"
],
"tags": [
"erc20",
"bridge"
],
"name": "WBTC"
},
{
"address": "0x1",
"networks": [
"ethereum"
],
"tags": [
"erc20",
"bridge"
],
"name": "WBTC"
},
{
"address": "0x3",
"networks": [
"avalanche"
],
"tags": [
"erc20"
],
"name": "BTC.b"
}
]
}
],
"routescan": {
"blockchain": [
{
"name": "ethereum"
},
{
"name": "avalanche"
}
],
"dapps": [
{
"name": "dapp1"
}
],
"entities": {
"0x1-avalanche": {
"address": "0x1",
"name": "WBTC",
"tags": [
"erc20",
"bridge"
],
"dapps": "dapp1",
"blockchain": "avalanche",
"bridged_to": "0x1-ethereum",
"similar_entities": [
"0x3-avalanche"
]
},
"0x1-ethereum": {
"address": "0x1",
"name": "WBTC",
"tags": [
"erc20",
"bridge"
],
"dapps": "dapp1",
"blockchain": "ethereum",
"bridged_to": "0x1-avalanche"
},
"0x3-avalanche": {
"address": "0x3",
"name": "BTC.b",
"tags": [
"erc20"
],
"dapps": "dapp1",
"blockchain": "avalanche",
"similar_entities": [
"0x1-avalanche"
]
}
}
}
}
def find_address(blockchain: str, address: str, db_type: str) -> float:
if db_type == "oss":
start_time = perf_counter()
for dapp in DB[db_type]:
for blockchain_address in dapp["blockchain"]:
if blockchain_address["address"] == address and blockchain in blockchain_address["networks"]:
return perf_counter() - start_time
if db_type == "routescan":
start_time = perf_counter()
DB[db_type]["entities"].get(f"{address}-{blockchain}")
return perf_counter() - start_time
if __name__ == "__main__":
time_to_find_routescan = np.mean([
find_address(
blockchain="avalanche",
address="0x3",
db_type="routescan"
)
for _ in range(1000)
])
time_to_find_oss = np.mean([
find_address(
blockchain="avalanche",
address="0x3",
db_type="oss"
)
for _ in range(1000)
])
print(f"To find a single address OSS is slower than Routescan {
time_to_find_oss/time_to_find_routescan:.2f} times.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment