Skip to content

Commit

Permalink
Align field names / remove struct type column
Browse files Browse the repository at this point in the history
- rename height to block_id
- remove tx_id_time struct column, just store tx id

See also: #3, graphsense/graphsense-transformation#41
  • Loading branch information
Rainer Stuetz committed Aug 18, 2021
1 parent 4d8acc7 commit 087a130
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 319 deletions.
50 changes: 46 additions & 4 deletions scripts/schema_raw.cql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ CREATE KEYSPACE IF NOT EXISTS eth_raw
USE eth_raw;

CREATE TABLE block (
block_group int,
block_number int,
block_id_group int,
block_id int,
block_hash blob,
parent_hash blob,
nonce blob,
Expand All @@ -22,15 +22,15 @@ CREATE TABLE block (
gas_used int,
timestamp int,
transaction_count smallint,
PRIMARY KEY (block_group, number)
PRIMARY KEY (block_id_group, block_id)
);

CREATE TABLE transaction (
hash_prefix text,
hash blob,
nonce int,
block_hash blob,
block_number int,
block_id int,
transaction_index smallint,
from_address blob,
to_address blob,
Expand All @@ -42,6 +42,48 @@ CREATE TABLE transaction (
PRIMARY KEY (hash_prefix, hash)
);

CREATE TABLE trace (
block_id_group int,
block_id int,
transaction_hash blob,
transaction_index smallint,
from_address blob,
to_address blob,
value varint,
input blob,
output blob,
trace_type text,
call_type text,
reward_type text,
gas int,
gas_used bigint,
subtraces smallint,
trace_address text,
error text,
status smallint,
trace_id text,
PRIMARY KEY (block_id_group, block_id, trace_id)
);

CREATE TABLE receipt (
transaction_hash_prefix text,
transaction_hash blob,
transaction_index smallint,
block_hash blob,
block_id int,
cumulative_gas_used int,
gas_used bigint,
contract_address blob,
root blob, // 32 bytes of post-transaction stateroot - pre Byzantium, before block 4_370_000
status smallint, // either 1 (success) or 0 (failure) - post Byzantium
PRIMARY KEY (transaction_hash_prefix, transaction_hash)
);

CREATE TABLE genesis_transfer (
address blob PRIMARY KEY,
value varint
);

CREATE TABLE exchange_rates (
date text PRIMARY KEY,
fiat_values map<text, float>
Expand Down
18 changes: 6 additions & 12 deletions scripts/schema_transformed.cql
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ CREATE TYPE currency (
fiat_values list<float>
);

CREATE TYPE tx_id_time (
height int,
transaction_id int,
block_timestamp int
);

CREATE TYPE address_summary (
total_received FROZEN <currency>,
total_spent FROZEN <currency>
Expand All @@ -24,7 +18,7 @@ CREATE TYPE address_summary (
// transformed schema

CREATE TABLE exchange_rates (
height int PRIMARY KEY,
block_id int PRIMARY KEY,
fiat_values list<float>
);

Expand Down Expand Up @@ -57,10 +51,10 @@ CREATE TABLE address_ids_by_address_prefix (
);

CREATE TABLE block_transactions(
height_group int,
height int,
block_id_group int,
block_id int,
txs list<int>,
PRIMARY KEY (height_group, height)
PRIMARY KEY (block_id_group, block_id)
);

CREATE TABLE address_transactions (
Expand All @@ -83,8 +77,8 @@ CREATE TABLE address (
address blob,
no_incoming_txs int,
no_outgoing_txs int,
first_tx FROZEN <tx_id_time>,
last_tx FROZEN <tx_id_time>,
first_tx_id int,
last_tx_id int,
total_received FROZEN <currency>,
total_spent FROZEN <currency>,
in_degree int,
Expand Down
37 changes: 20 additions & 17 deletions src/main/scala/info/graphsense/Model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ case class AddressIdByAddressPrefix(
// transformed schema data types

case class Currency(value: BigInt, fiatValues: Seq[Float])
case class TxIdTime(height: Int, transactionId: Int, blockTimestamp: Int)
case class AddressSummary(totalReceived: Currency, totalSpent: Currency)

// raw schema tables

case class Block(
blockGroup: Int,
blockNumber: Int,
blockIdGroup: Int,
blockId: Int,
blockHash: Array[Byte],
parentHash: Array[Byte],
nonce: Array[Byte],
Expand All @@ -67,7 +66,7 @@ case class Transaction(
hash: Array[Byte],
nonce: Int,
blockHash: Array[Byte],
blockNumber: Int,
blockId: Int,
transactionIndex: Short,
fromAddress: Array[Byte],
toAddress: Option[Array[Byte]],
Expand All @@ -78,13 +77,13 @@ case class Transaction(
blockTimestamp: Int
)

case class Receipt (
transactionHashPrefix: String,
transactionHash: Array[Byte],
gasUsed: Int
case class Receipt(
transactionHashPrefix: String,
transactionHash: Array[Byte],
gasUsed: Int
)

case class BalanceTrace(
case class Trace(
fromAddress: Option[Array[Byte]],
toAddress: Option[Array[Byte]],
value: BigInt,
Expand All @@ -110,23 +109,27 @@ case class AddressTagRaw(

// transformed schema tables

case class ExchangeRates(height: Int, fiatValues: Seq[Float])
case class ExchangeRates(blockId: Int, fiatValues: Seq[Float])

case class GenesisTransfer(
address: Array[Byte],
value: BigInt
)

case class Balances(address: Array[Byte], balance: BigInt)
case class Balance(address: Array[Byte], balance: BigInt)

case class BalancesWithPrefix(addressPrefix: String, address: Array[Byte], balance: BigInt)
case class BalanceWithPrefix(
addressPrefix: String,
address: Array[Byte],
balance: BigInt
)

case class BlockTransaction(heightGroup: Int, height: Int, txs: Seq[Int])
case class BlockTransaction(blockIdGroup: Int, blockId: Int, txs: Seq[Int])

case class EncodedTransaction(
transactionId: Int,
nonce: Int,
height: Int,
blockId: Int,
transactionIndex: Short,
srcAddressId: Int,
dstAddressId: Option[Int],
Expand All @@ -144,7 +147,7 @@ case class AddressTransaction(
addressId: Int,
transactionId: Int,
value: BigInt,
height: Int,
blockId: Int,
blockTimestamp: Int
)

Expand All @@ -159,8 +162,8 @@ case class Address(
address: Array[Byte],
noIncomingTxs: Int,
noOutgoingTxs: Int,
firstTx: TxIdTime,
lastTx: TxIdTime,
firstTxId: Int,
lastTxId: Int,
totalReceived: Currency,
totalSpent: Currency,
inDegree: Int,
Expand Down
Loading

0 comments on commit 087a130

Please sign in to comment.