diff --git a/Cargo.lock b/Cargo.lock index f99fe4c..b9f3b5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "alloy-rlp" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b155716bab55763c95ba212806cf43d05bcc70e5f35b02bad20cf5ec7fe11fed" +checksum = "a43b18702501396fa9bcdeecd533bc85fac75150d308fc0f6800a01e6234a003" dependencies = [ "arrayvec", "bytes", @@ -504,9 +504,9 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitvec" @@ -617,9 +617,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.100" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c891175c3fb232128f48de6590095e59198bbeb8620c310be349bfc3afd12c7b" +checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490" dependencies = [ "jobserver", "libc", @@ -837,9 +837,9 @@ dependencies = [ [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" @@ -1245,9 +1245,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +checksum = "c4fe55fb7a772d59a5ff1dfbff4fe0258d19b89fec4b233e75d35d5d2316badc" dependencies = [ "bytes", "futures-channel", @@ -1282,9 +1282,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" +checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956" dependencies = [ "bytes", "futures-channel", @@ -1302,7 +1302,7 @@ dependencies = [ [[package]] name = "hypersync" -version = "0.7.7" +version = "0.7.8" dependencies = [ "alloy-dyn-abi", "alloy-json-abi", @@ -1545,9 +1545,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lz4" @@ -1640,9 +1640,9 @@ checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", @@ -1679,9 +1679,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" dependencies = [ "memchr", ] @@ -1765,9 +1765,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.10" +version = "2.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560131c633294438da9f7c4b08189194b20946c8274c6b9e38881a7874dc8ee8" +checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" dependencies = [ "memchr", "thiserror", @@ -2473,9 +2473,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" -version = "0.102.4" +version = "0.102.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78" dependencies = [ "ring", "rustls-pki-types", @@ -2572,9 +2572,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -2730,9 +2730,9 @@ checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82" [[package]] name = "subtle" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d0208408ba0c3df17ed26eb06992cb1a1268d41b2c0e12e65203fbe3972cee5" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -2835,9 +2835,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" dependencies = [ "tinyvec_macros", ] @@ -3384,24 +3384,24 @@ dependencies = [ [[package]] name = "xxhash-rust" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927da81e25be1e1a2901d59b81b37dd2efd1fc9c9345a55007f09bf5a2d3ee03" +checksum = "63658493314859b4dfdf3fb8c1defd61587839def09582db50b8a4e93afca6bb" [[package]] name = "zerocopy" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.34" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index e980f33..a07bc6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hypersync" -version = "0.7.7" +version = "0.7.8" edition = "2021" [lib] diff --git a/examples/all-erc20.py b/examples/all-erc20.py index 5eb29ad..ce0b865 100644 --- a/examples/all-erc20.py +++ b/examples/all-erc20.py @@ -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 diff --git a/examples/block-data.py b/examples/block-data.py new file mode 100644 index 0000000..b7c8cb4 --- /dev/null +++ b/examples/block-data.py @@ -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()) \ No newline at end of file diff --git a/hypersync/__init__.py b/hypersync/__init__.py index 3c567cb..2ee75a0 100644 --- a/hypersync/__init__.py +++ b/hypersync/__init__.py @@ -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 @@ -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: diff --git a/src/query.rs b/src/query.rs index ebcb728..c7c02a1 100644 --- a/src/query.rs +++ b/src/query.rs @@ -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, + /// 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, } impl Query {