Skip to content

Commit

Permalink
make eth compatible with flat block transactions table
Browse files Browse the repository at this point in the history
  • Loading branch information
soad003 committed Feb 8, 2024
1 parent bb5203d commit 6ec7b79
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
42 changes: 28 additions & 14 deletions gsrest/db/cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,23 @@ def load_parameters(self, keyspace):
"token_config"] = self.load_token_configuration(keyspace)

# check schema for compatibility and set parameter flags
keyspace_name = self.get_keyspace_mapping(keyspace, "transformed")

if keyspace == "eth":
query = ("SELECT column_name FROM system_schema.columns "
"WHERE keyspace_name = %s AND "
"table_name = 'block_transactions';")
result = self.session.execute(query, (keyspace_name, ))
self.parameters[currency]["use_flat_block_txs"] = ("tx_id" in [
x["column_name"] for x in result
]) and keyspace == "eth"
else:
self.parameters[currency]["use_flat_block_txs"] = False

query = (
"SELECT column_name FROM system_schema.columns "
"WHERE keyspace_name = %s AND table_name = 'address_transactions';"
)
keyspace_name = self.get_keyspace_mapping(keyspace, "transformed")
result = self.session.execute(query, (keyspace_name, ))
self.parameters[currency]["use_legacy_log_index"] = ("log_index" in [
x["column_name"] for x in result
Expand Down Expand Up @@ -795,17 +807,20 @@ async def list_block_txs_ids(self, currency, height):
return [tx.tx_id for tx in result.one()['txs']]

async def list_block_txs_ids_eth(self, currency, height):
if height is None:
return None
height_group = self.get_id_group(currency, height)
query = ("SELECT txs FROM block_transactions "
"WHERE block_id_group=%s and block_id=%s")
result = await self.execute_async(
currency, 'transformed', query,
[height_group, int(height)])
if one(result) is None:
return None
return result.one()['txs']
if not self.parameters[currency]["use_flat_block_txs"]:
if height is None:
return None
height_group = self.get_id_group(currency, height)
query = ("SELECT txs FROM block_transactions "
"WHERE block_id_group=%s and block_id=%s")
result = await self.execute_async(
currency, 'transformed', query,
[height_group, int(height)])
if one(result) is None:
return None
return result.one()['txs']
else:
return await self.list_block_txs_ids_trx(currency, height)

async def list_block_txs_ids_trx(self, currency, height):
if height is None:
Expand Down Expand Up @@ -1808,8 +1823,7 @@ async def add_balance_eth(self, currency, row):
"and currency=%s"

results = {
c:
one(await self.execute_async(
c: one(await self.execute_async(
currency, 'transformed', query,
[row['address_id'], row['address_id_group'], c]))
for c in balance_currencies
Expand Down
16 changes: 11 additions & 5 deletions tests/cassandra/data/resttest_eth_transformed.block_transactions
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{"block_id_group": 0, "block_id": 1, "txs": [24000, 25000]}
{"block_id_group": 0, "block_id": 2, "txs": [26000, 50000]}
{"block_id_group": 0, "block_id": 3, "txs": [55000, 58000]}
{"block_id_group": 0, "block_id": 4, "txs": [59000, 60000]}
{"block_id_group": 92, "block_id": 2300001, "txs": [25000, 26000]}
{"block_id_group": 0, "block_id": 1, "tx_id": 24000}
{"block_id_group": 0, "block_id": 1, "tx_id": 25000}
{"block_id_group": 0, "block_id": 2, "tx_id": 26000}
{"block_id_group": 0, "block_id": 2, "tx_id": 50000}
{"block_id_group": 0, "block_id": 3, "tx_id": 55000}
{"block_id_group": 0, "block_id": 3, "tx_id": 58000}
{"block_id_group": 0, "block_id": 4, "tx_id": 59000}
{"block_id_group": 0, "block_id": 5, "tx_id": 60000}}
{"block_id_group": 92, "block_id": 2300001, "tx_id": 25000}}
{"block_id_group": 92, "block_id": 2300001, "tx_id": 26000}}

2 changes: 1 addition & 1 deletion tests/cassandra/ingest_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ schema "$SCHEMA_BASE_PATH/transformed_utxo_schema.sql" 0x8BADF00D "resttest_btc_
schema "$SCHEMA_BASE_PATH/raw_account_schema.sql" 0x8BADF00D "resttest_eth_raw"
schema "$SCHEMA_BASE_PATH/transformed_account_schema.sql" 0x8BADF00D "resttest_eth_transformed"
schema "$SCHEMA_BASE_PATH/raw_account_trx_schema.sql" 0x8BADF00D "resttest_trx_raw"
schema "$SCHEMA_BASE_PATH/transformed_account_trx_schema.sql" 0x8BADF00D "resttest_trx_transformed"
schema "$SCHEMA_BASE_PATH/transformed_account_schema.sql" 0x8BADF00D "resttest_trx_transformed"
# schema "$SCHEMA_BASE_PATH/transformed_delta_updater_account_schema.sql" "CREATE TABLE " "CREATE TABLE eth_transformed"
# schema "$SCHEMA_BASE_PATH/transformed_delta_updater_utxo_schema.sql" "CREATE TABLE " "btc_transformed ltc_transformed"
schema "`dirname $0`/schemas/schema.cql" btc "resttest_btc resttest_ltc"
Expand Down

0 comments on commit 6ec7b79

Please sign in to comment.