Skip to content

Commit

Permalink
Impl postgres getter setter into evm exporter (#15)
Browse files Browse the repository at this point in the history
* defined postgres tables

* impl postgres setter and getter

* make the image can be builed

* make redis and postgres dependencies within into evm-exporter only

* let the rocksdb-exporter using new evm-exporter getter and setter settings

* let getter and setter using &self instead of &mut self

* let web3-service can be compiled

* let rocksdb-exporter can be compiled
  • Loading branch information
tommady authored Jul 15, 2024
1 parent 468e310 commit 9dc1df0
Show file tree
Hide file tree
Showing 35 changed files with 1,563 additions and 955 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV OPENSSL_LIB_DIR="/usr/lib/x86_64-linux-gnu"
ENV OPENSSL_INCLUDE_DIR="/usr/include/openssl"
COPY . /enterprise-web3
WORKDIR /enterprise-web3
RUN cargo build --release
RUN cargo build --release --features "postgres"

RUN mkdir /enterprise-web3-binaries
RUN cp target/release/rocksdb-exporter /enterprise-web3-binaries
Expand Down
16 changes: 12 additions & 4 deletions evm-exporter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
primitive-types = "0.11.1"
primitive-types = "0.11"
thiserror = "1.0.34"
ethereum-types = { version = "0.13.1", default-features = false, features = ["serialize"] }
sqlx = { version = "0.7", default-features = false, features = ["postgres", "time", "bigdecimal"] }
redis = { version = "0.25", default-features = false }
redis-versioned-kv = { path = "../redis-versioned-kv" }
r2d2_postgres = { version = "0.18", optional = true }
r2d2 = { version = "0.8", optional = true }
redis = { version = "0.25", default-features = false, optional = true }
redis-versioned-kv = { path = "../redis-versioned-kv", optional = true }
hex = "0.4.3"
uint = "0.9.3"
sha3 = "0.8"
fixed-hash = "0.8"
libsecp256k1 = { version = "0.5", features = ["static-context", "hmac"] }
ethereum = { version = "0.12.0", default-features = false, features = ["with-serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[features]
default = ["postgres"]
redis = ["dep:redis", "dep:redis-versioned-kv"]
redis-cluster = ["redis/cluster", "dep:redis", "dep:redis-versioned-kv"]
postgres = ["dep:r2d2", "dep:r2d2_postgres"]
11 changes: 11 additions & 0 deletions evm-exporter/migrations/allowances.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS allowances (
id BIGSERIAL PRIMARY KEY,
owner CHARACTER VARYING(64) NOT NULL,
spender CHARACTER VARYING(64) NOT NULL,
value CHARACTER VARYING(128) NOT NULL,
height BIGSERIAL NOT NULL
);

CREATE INDEX IF NOT EXISTS allowances_owner_idx ON allowances(owner);
CREATE INDEX IF NOT EXISTS allowances_spender_idx ON allowances(spender);
CREATE INDEX IF NOT EXISTS allowances_height_idx ON allowances(height);
9 changes: 9 additions & 0 deletions evm-exporter/migrations/balance.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS balance (
id BIGSERIAL PRIMARY KEY,
balance CHARACTER VARYING(128) NOT NULL,
address CHARACTER VARYING(64) NOT NULL,
height BIGSERIAL NOT NULL
);

CREATE INDEX IF NOT EXISTS balance_address_idx ON balance(address);
CREATE INDEX IF NOT EXISTS balance_height_idx ON balance(height);
11 changes: 11 additions & 0 deletions evm-exporter/migrations/block_info.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS block_info (
id BIGSERIAL PRIMARY KEY,
block_hash CHARACTER VARYING(128) NOT NULL,
block_height CHARACTER VARYING(128) NOT NULL,
block JSONB NOT NULL,
receipt JSONB NOT NULL,
statuses JSONB NOT NULL,
);

CREATE INDEX IF NOT EXISTS block_info_block_hash_idx ON block_info(block_hash);
CREATE INDEX IF NOT EXISTS block_info_block_height_idx ON block_info(block_height);
9 changes: 9 additions & 0 deletions evm-exporter/migrations/byte_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS byte_code (
id BIGSERIAL PRIMARY KEY,
code TEXT NOT NULL,
address CHARACTER VARYING(64) NOT NULL,
height BIGSERIAL NOT NULL
);

CREATE INDEX IF NOT EXISTS byte_code_address_idx ON byte_code(address);
CREATE INDEX IF NOT EXISTS byte_code_height_idx ON byte_code(height);
9 changes: 9 additions & 0 deletions evm-exporter/migrations/common.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS common (
latest_height BIGSERIAL NOT NULL,
lowest_height BIGSERIAL NOT NULL
);

CREATE INDEX IF NOT EXISTS common_latest_height_idx ON common(latest_height);
CREATE INDEX IF NOT EXISTS common_lowest_height_idx ON common(lowest_height);

INSERT INTO common(latest_height, lowest_height) VALUES (0, 0);
7 changes: 7 additions & 0 deletions evm-exporter/migrations/issuance.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS issuance (
id BIGSERIAL PRIMARY KEY,
value CHARACTER VARYING(128) NOT NULL,
height BIGSERIAL NOT NULL
);

CREATE INDEX IF NOT EXISTS issuance_height_idx ON issuance(height);
9 changes: 9 additions & 0 deletions evm-exporter/migrations/nonce.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS nonce (
id BIGSERIAL PRIMARY KEY,
nonce CHARACTER VARYING(128) NOT NULL,
address CHARACTER VARYING(64) NOT NULL,
height BIGSERIAL NOT NULL
);

CREATE INDEX IF NOT EXISTS nonce_address_idx ON nonce(address);
CREATE INDEX IF NOT EXISTS nonce_height_idx ON nonce(height);
7 changes: 7 additions & 0 deletions evm-exporter/migrations/pending_byte_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS pending_byte_code (
id BIGSERIAL PRIMARY KEY,
code JSONB NOT NULL,
address CHARACTER VARYING(64) NOT NULL,
);

CREATE INDEX IF NOT EXISTS pending_byte_code_address_idx ON pending_byte_code(address);
9 changes: 9 additions & 0 deletions evm-exporter/migrations/pending_state.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS pending_state (
id BIGSERIAL PRIMARY KEY,
value CHARACTER VARYING(128) NOT NULL,
idx CHARACTER VARYING(128) NOT NULL,
address CHARACTER VARYING(64) NOT NULL,
);

CREATE INDEX IF NOT EXISTS pending_state_address_idx ON pending_state(address);
CREATE INDEX IF NOT EXISTS pending_state_idx_idx ON pending_state(idx);
8 changes: 8 additions & 0 deletions evm-exporter/migrations/pending_transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS pending_transactions (
id BIGSERIAL PRIMARY KEY,
sign_address CHARACTER VARYING(64) NOT NULL,
pending_balance CHARACTER VARYING(128) NOT NULL,
pending_nonce CHARACTER VARYING(128) NOT NULL,
);

CREATE INDEX IF NOT EXISTS pending_transactions_sign_address_idx ON pending_transactions(sign_address);
11 changes: 11 additions & 0 deletions evm-exporter/migrations/state.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS state (
id BIGSERIAL PRIMARY KEY,
value CHARACTER VARYING(128) NOT NULL,
idx CHARACTER VARYING(128) NOT NULL,
address CHARACTER VARYING(64) NOT NULL,
height BIGSERIAL NOT NULL
);

CREATE INDEX IF NOT EXISTS state_address_idx ON state(address);
CREATE INDEX IF NOT EXISTS state_height_idx ON state(height);
CREATE INDEX IF NOT EXISTS state_idx_idx ON state(idx);
7 changes: 7 additions & 0 deletions evm-exporter/migrations/transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS transactions (
id BIGSERIAL PRIMARY KEY,
transaction_hash CHARACTER VARYING(128) NOT NULL,
transaction_index JSONB NOT NULL,
);

CREATE INDEX IF NOT EXISTS transactions_transaction_hash_idx ON transactions(transaction_hash);
14 changes: 13 additions & 1 deletion evm-exporter/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[cfg(any(feature = "redis", feature = "redis-cluster"))]
#[error(transparent)]
RedisError(#[from] redis::RedisError),

#[cfg(feature = "postgres")]
#[error(transparent)]
PostgresError(#[from] sqlx::Error),
PostgresError(#[from] r2d2_postgres::postgres::Error),

#[cfg(feature = "postgres")]
#[error(transparent)]
R2D2PoolError(#[from] r2d2::Error),

#[error(transparent)]
FromHexError(#[from] hex::FromHexError),
Expand All @@ -28,6 +34,12 @@ pub enum Error {

#[error(transparent)]
Libsecp256k1Error(#[from] libsecp256k1::Error),

#[error(transparent)]
UTypeConvertError(#[from] uint::FromHexError),

#[error(transparent)]
HTypeConvertError(#[from] fixed_hash::rustc_hex::FromHexError),
}

pub type Result<T> = std::result::Result<T, Error>;
Loading

0 comments on commit 9dc1df0

Please sign in to comment.