Skip to content

Commit

Permalink
feat: update to new API (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgrakkurt authored May 27, 2024
1 parent 253e927 commit d6697e8
Show file tree
Hide file tree
Showing 22 changed files with 1,421 additions and 1,804 deletions.
437 changes: 227 additions & 210 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 8 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
[package]
name = "hypersync"
version = "0.6.2"
version = "0.7.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "hypersync"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.20", features = ["extension-module", "serde"] }
pyo3 = { version = "0.20", features = ["extension-module", "anyhow"] }
pyo3-asyncio = { version = "0.20", features = ["tokio-runtime"] }
tokio = "1.9"

dict_derive = "0.5.0"

tokio = "1"
dict_derive = "0.5"
serde_json = "1"
serde = { version = "1", features = ["derive"] }

alloy-json-abi = "0.7"
alloy-dyn-abi = "0.7"
alloy-primitives = "0.7"

skar-client = "0.18"
skar-net-types = "0.3"
skar-format = "0.3"

hypersync-client = "0.6"
anyhow = "1"
polars-arrow = { version = "0.39" }
prefix-hex = "0.7.1"
prefix-hex = "0.7"
env_logger = "0.11"
itertools = "0.12.1"
faster-hex = "0.9.0"

[profile.no_lto]
inherits = "release"
lto = "off"
faster-hex = "0.9"
ruint = "1"
222 changes: 0 additions & 222 deletions erc20.abi.json

This file was deleted.

31 changes: 12 additions & 19 deletions examples/all-erc20.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import hypersync
import asyncio
from hypersync import BlockField, TransactionField, LogField
from hypersync import BlockField, TransactionField, LogField, ClientConfig

async def main():
# Create hypersync client using the arbitrum hypersync endpoint
client = hypersync.HypersyncClient("https://arbitrum.hypersync.xyz")
client = hypersync.HypersyncClient(ClientConfig())

# The query to run
query = hypersync.Query(
Expand Down Expand Up @@ -38,32 +38,21 @@ async def main():
TransactionField.VALUE,
TransactionField.INPUT,
]
)
),
)

print("Running the query...")

# Run the query once, the query is automatically paginated so it will return when it reaches some limit (time, response size etc.)
# there is a next_block field on the response object so we can set the from_block of our query to this value and continue our query until
# res.next_block is equal to res.archive_height or query.to_block in case we specified an end block.
res = await client.send_req(query)
res = await client.get(query)

print(f"Ran the query once. Next block to query is {res.next_block}")

# read json abi file for erc20
with open('./erc20.abi.json', 'r') as json_file:
abi = json_file.read()

# Map of contract_address -> abi
abis = {}

# every log we get should be decodable by this abi but we don't know
# the specific contract addresses since we are indexing all erc20 transfers.
for log in res.data.logs:
abis[log.address] = abi

# Create a decoder with our mapping
decoder = hypersync.Decoder(abis)
decoder = hypersync.Decoder([
"Transfer(address indexed from, address indexed to, uint256 value)"
])

# Decode the log on a background thread so we don't block the event loop.
# Can also use decoder.decode_logs_sync if it is more convenient.
Expand All @@ -72,7 +61,11 @@ async def main():
# Let's count total volume, it is meaningless because of currency differences but good as an example.
total_volume = 0
for log in decoded_logs:
total_volume += log.body[0]
#skip invalid logs
if log is None:
continue

total_volume += log.body[0].val

total_blocks = res.next_block - query.from_block

Expand Down
6 changes: 3 additions & 3 deletions examples/simple-blocks-and-transaction-hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

async def main():
# Create hypersync client using the mainnet hypersync endpoint (default)
client = hypersync.HypersyncClient()
client = hypersync.HypersyncClient(hypersync.ClientConfig())

query = client.preset_query_blocks_and_transaction_hashes(17_000_000, 17_000_050)
query = hypersync.preset_query_blocks_and_transaction_hashes(17_000_000, 17_000_050)

print("Running the query...")

# Run the query once, the query is automatically paginated so it will return when it reaches some limit (time, response size etc.)
# there is a next_block field on the response object so we can set the from_block of our query to this value and continue our query until
# res.next_block is equal to res.archive_height or query.to_block in case we specified an end block.
res = await client.send_req(query)
res = await client.get(query)

print(f"Query returned {len(res.data.blocks)} blocks and {len(res.data.transactions)} transaction hashes")

Expand Down
6 changes: 3 additions & 3 deletions examples/simple-blocks-and-transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

async def main():
# Create hypersync client using the mainnet hypersync endpoint (default)
client = hypersync.HypersyncClient()
client = hypersync.HypersyncClient(hypersync.ClientConfig())

query = client.preset_query_blocks_and_transactions(17_000_000, 17_000_050)
query = hypersync.preset_query_blocks_and_transactions(17_000_000, 17_000_050)

print("Running the query...")

# Run the query once, the query is automatically paginated so it will return when it reaches some limit (time, response size etc.)
# there is a next_block field on the response object so we can set the from_block of our query to this value and continue our query until
# res.next_block is equal to res.archive_height or query.to_block in case we specified an end block.
res = await client.send_req(query)
res = await client.get(query)

print(f"Query returned {len(res.data.blocks)} blocks and {len(res.data.transactions)} transactions")

Expand Down
Loading

0 comments on commit d6697e8

Please sign in to comment.