From 2e35da8ef39075fae74516a8c2de2df687023115 Mon Sep 17 00:00:00 2001
From: Renato Dinhani <101204870+dinhani-cw@users.noreply.github.com>
Date: Wed, 28 Feb 2024 12:45:21 -0300
Subject: [PATCH] refactor: move postgres functions to _postgres.rs module to
have reuse between importer jobs (#289)
---
...2c321c80d3e77c1b364e101ae96f4d42e2f9.json} | 4 +-
src/bin/importer/_postgres.rs | 208 ++++++++++++++++++
src/bin/importer/importer-download.rs | 110 +--------
src/bin/importer/importer-import.rs | 132 +----------
.../sql/select_downloaded_blocks_in_range.sql | 3 +
.../select_downloaded_receipts_in_range.sql | 4 +-
6 files changed, 233 insertions(+), 228 deletions(-)
rename .sqlx/{query-86a8b3ca23e91ea82eab7f3902355523ee2b91f53da6a36c6fd8851f0f214975.json => query-730e617474d8bb7970702970ba162c321c80d3e77c1b364e101ae96f4d42e2f9.json} (66%)
create mode 100644 src/bin/importer/_postgres.rs
create mode 100644 src/bin/importer/sql/select_downloaded_blocks_in_range.sql
diff --git a/.sqlx/query-86a8b3ca23e91ea82eab7f3902355523ee2b91f53da6a36c6fd8851f0f214975.json b/.sqlx/query-730e617474d8bb7970702970ba162c321c80d3e77c1b364e101ae96f4d42e2f9.json
similarity index 66%
rename from .sqlx/query-86a8b3ca23e91ea82eab7f3902355523ee2b91f53da6a36c6fd8851f0f214975.json
rename to .sqlx/query-730e617474d8bb7970702970ba162c321c80d3e77c1b364e101ae96f4d42e2f9.json
index 6889ba1a6..6ab05b5fb 100644
--- a/.sqlx/query-86a8b3ca23e91ea82eab7f3902355523ee2b91f53da6a36c6fd8851f0f214975.json
+++ b/.sqlx/query-730e617474d8bb7970702970ba162c321c80d3e77c1b364e101ae96f4d42e2f9.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "select block_number, payload\nfrom external_receipts\nwhere block_number >= $1 and block_number <= $2;",
+ "query": "select\n block_number,\n payload\nfrom external_receipts\nwhere block_number >= $1 and block_number <= $2;",
"describe": {
"columns": [
{
@@ -25,5 +25,5 @@
false
]
},
- "hash": "86a8b3ca23e91ea82eab7f3902355523ee2b91f53da6a36c6fd8851f0f214975"
+ "hash": "730e617474d8bb7970702970ba162c321c80d3e77c1b364e101ae96f4d42e2f9"
}
diff --git a/src/bin/importer/_postgres.rs b/src/bin/importer/_postgres.rs
new file mode 100644
index 000000000..bd4403849
--- /dev/null
+++ b/src/bin/importer/_postgres.rs
@@ -0,0 +1,208 @@
+#![allow(dead_code)]
+
+use serde_json::Value as JsonValue;
+use sqlx::types::BigDecimal;
+use sqlx::Row;
+use stratus::eth::primitives::Address;
+use stratus::eth::primitives::BlockNumber;
+use stratus::eth::primitives::ExternalBlock;
+use stratus::eth::primitives::ExternalReceipt;
+use stratus::eth::primitives::Hash;
+use stratus::eth::primitives::Wei;
+use stratus::infra::postgres::Postgres;
+use stratus::log_and_err;
+
+// -----------------------------------------------------------------------------
+// Queries
+// -----------------------------------------------------------------------------
+
+// Blocks
+
+pub async fn pg_retrieve_max_downloaded_block(pg: &Postgres, start: BlockNumber, end: BlockNumber) -> anyhow::Result