Skip to content

Commit

Permalink
feat: add query.join_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgrakkurt committed Jul 3, 2024
1 parent 9bb040e commit 17db013
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 37 deletions.
70 changes: 35 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hypersync"
version = "0.7.7"
version = "0.7.8"
edition = "2021"

[lib]
Expand Down
1 change: 0 additions & 1 deletion examples/all-erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from hypersync import BlockField, TransactionField, LogField, ClientConfig

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

# The query to run
Expand Down
54 changes: 54 additions & 0 deletions examples/block-data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import hypersync
import asyncio
from hypersync import BlockField, JoinMode, TransactionField, LogField, ClientConfig

async def main():
client = hypersync.HypersyncClient(ClientConfig(url="http://167.235.0.227:2104"))

# The query to run
query = hypersync.Query(
# only get block 20224332
from_block=20224332,
to_block=20224333,
include_all_blocks=True,
join_mode=JoinMode.JOIN_ALL,
field_selection=hypersync.FieldSelection(
block=[BlockField.NUMBER, BlockField.TIMESTAMP, BlockField.HASH],
log=[
LogField.LOG_INDEX,
LogField.TRANSACTION_INDEX,
LogField.TRANSACTION_HASH,
LogField.DATA,
LogField.ADDRESS,
LogField.TOPIC0,
LogField.TOPIC1,
LogField.TOPIC2,
LogField.TOPIC3,
],
transaction=[
TransactionField.BLOCK_NUMBER,
TransactionField.TRANSACTION_INDEX,
TransactionField.HASH,
TransactionField.FROM,
TransactionField.TO,
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.get(query)

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

print(len(res.data.blocks))
print(len(res.data.transactions))
print(len(res.data.logs))

asyncio.run(main())
12 changes: 12 additions & 0 deletions hypersync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ class FieldSelection:
log: Optional[list[LogField]] = None
trace: Optional[list[TraceField]] = None

class JoinMode(StrEnum):
DEFAULT = 'Default'
JOIN_ALL = 'JoinAll'
JOIN_NOTHING = 'JoinNothing'

@dataclass
class Query:
# The block to start the query from
Expand Down Expand Up @@ -378,6 +383,13 @@ class Query:
# Maximum number of traces that should be returned, the server might return more traces than this number but
# it won't overshoot by too much.
max_num_traces: Optional[int] = None
# Selects join mode for the query,
# Default: join in this order logs -> transactions -> traces -> blocks
# JoinAll: join everything to everything. For example if logSelection matches log0, we get the
# associated transaction of log0 and then we get associated logs of that transaction as well. Applites similarly
# to blocks, traces.
# JoinNothing: join nothing.
join_mode: Optional[JoinMode] = None

@dataclass
class ColumnMapping:
Expand Down
8 changes: 8 additions & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ pub struct Query {
/// it won't overshoot by too much.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_num_traces: Option<u64>,
/// Selects join mode for the query,
/// Default: join in this order logs -> transactions -> traces -> blocks
/// JoinAll: join everything to everything. For example if logSelection matches log0, we get the
/// associated transaction of log0 and then we get associated logs of that transaction as well. Applites similarly
/// to blocks, traces.
/// JoinNothing: join nothing.
#[serde(skip_serializing_if = "Option::is_none")]
pub join_mode: Option<String>,
}

impl Query {
Expand Down

0 comments on commit 17db013

Please sign in to comment.