Skip to content

Commit bd36842

Browse files
authored
[Indexer] Migrate to grpc processors (aptos-labs#8841)
* add from old indexer * fix end version * tweak comments on crash * strip out coin type in a different way * fix side effect cause by rust upgrade * cargo lock update
1 parent 75a3a9a commit bd36842

File tree

58 files changed

+5536
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5536
-266
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/indexer/src/models/stake_models/delegator_balances.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,12 @@ impl CurrentDelegatorBalance {
6868
if let Some(pool_balance) = active_pool_to_staking_pool.get(&table_handle) {
6969
let pool_address = pool_balance.staking_pool_address.clone();
7070
let delegator_address = standardize_address(&write_table_item.key.to_string());
71-
let data: &aptos_api_types::transaction::DecodedTableData =
72-
write_table_item.data.as_ref().unwrap_or_else(|| {
73-
panic!(
71+
let data = write_table_item.data.as_ref().unwrap_or_else(|| {
72+
panic!(
7473
"This table item should be an active share item, table_item {:?}, version {}",
7574
write_table_item, txn_version
7675
)
77-
});
76+
});
7877
let shares = data
7978
.value
8079
.as_str()
@@ -130,13 +129,12 @@ impl CurrentDelegatorBalance {
130129
},
131130
};
132131
let delegator_address = standardize_address(&write_table_item.key.to_string());
133-
let data: &aptos_api_types::transaction::DecodedTableData =
134-
write_table_item.data.as_ref().unwrap_or_else(|| {
135-
panic!(
136-
"This table item should be an active share item, table_item {:?}, version {}",
137-
write_table_item, txn_version
138-
)
139-
});
132+
let data = write_table_item.data.as_ref().unwrap_or_else(|| {
133+
panic!(
134+
"This table item should be an active share item, table_item {:?}, version {}",
135+
write_table_item, txn_version
136+
)
137+
});
140138
let shares = data
141139
.value
142140
.as_str()

crates/indexer/src/models/stake_models/delegator_pools.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ impl DelegatorPool {
126126
if let Some(StakeResource::DelegationPool(inner)) =
127127
StakeResource::from_write_resource(write_resource, txn_version)?
128128
{
129-
let staking_pool_address: String =
130-
standardize_address(&write_resource.address.to_string());
129+
let staking_pool_address = standardize_address(&write_resource.address.to_string());
131130
let total_coins = inner.active_shares.total_coins;
132131
let total_shares =
133132
&inner.active_shares.total_shares / &inner.active_shares.scaling_factor;

crates/indexer/src/util.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ pub fn ensure_not_negative(val: BigDecimal) -> BigDecimal {
4343
}
4444

4545
pub fn parse_timestamp(ts: u64, version: i64) -> chrono::NaiveDateTime {
46-
chrono::NaiveDateTime::from_timestamp_opt((ts / 1000000) as i64, 0)
46+
let seconds = ts / 1000000;
47+
let ns = (ts % 1000000 * 1000).try_into().unwrap_or_else(|_| {
48+
panic!(
49+
"Could not get nanoseconds for timestamp {:?} for version {}",
50+
ts, version
51+
)
52+
});
53+
chrono::NaiveDateTime::from_timestamp_opt(seconds as i64, ns)
4754
.unwrap_or_else(|| panic!("Could not parse timestamp {:?} for version {}", ts, version))
4855
}
4956

@@ -189,7 +196,7 @@ pub fn convert_hex(val: String) -> Option<String> {
189196
#[cfg(test)]
190197
mod tests {
191198
use super::*;
192-
use chrono::Datelike;
199+
use chrono::{Datelike, Timelike};
193200
use serde::Serialize;
194201

195202
#[derive(Serialize, Deserialize, Debug)]
@@ -216,6 +223,7 @@ mod tests {
216223
fn test_parse_timestamp() {
217224
let ts = parse_timestamp(1649560602763949, 1);
218225
assert_eq!(ts.timestamp(), 1649560602);
226+
assert_eq!(ts.nanosecond(), 763949000);
219227
assert_eq!(ts.year(), 2022);
220228

221229
let ts2 = parse_timestamp_secs(600000000000000, 2);

ecosystem/indexer-grpc/indexer-grpc-parser/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ futures = { workspace = true }
3333
hex = { workspace = true }
3434
once_cell = { workspace = true }
3535
prost = { workspace = true }
36+
regex = { workspace = true }
3637
serde = { workspace = true }
3738
serde_json = { workspace = true }
3839
sha2 = { workspace = true }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file should undo anything in `up.sql`\
2+
DROP TABLE IF EXISTS nft_points;
3+
DROP INDEX IF EXISTS np_oa_idx;
4+
DROP INDEX IF EXISTS np_tt_oa_idx;
5+
DROP INDEX IF EXISTS np_insat_idx;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Your SQL goes here
2+
CREATE TABLE nft_points (
3+
transaction_version BIGINT UNIQUE PRIMARY KEY NOT NULL,
4+
owner_address VARCHAR(66) NOT NULL,
5+
token_name TEXT NOT NULL,
6+
point_type TEXT NOT NULL,
7+
amount NUMERIC NOT NULL,
8+
transaction_timestamp TIMESTAMP NOT NULL,
9+
inserted_at TIMESTAMP NOT NULL DEFAULT NOW()
10+
);
11+
CREATE INDEX np_oa_idx ON nft_points (owner_address);
12+
CREATE INDEX np_tt_oa_idx ON nft_points (transaction_timestamp, owner_address);
13+
CREATE INDEX np_insat_idx ON nft_points (inserted_at);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- This file should undo anything in `up.sql`
2+
DROP TABLE IF EXISTS delegated_staking_pools;
3+
DROP INDEX IF EXISTS dsp_oa_index;
4+
DROP INDEX IF EXISTS dsp_insat_index;
5+
ALTER TABLE current_staking_pool_voter
6+
DROP COLUMN IF EXISTS operator_address;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Your SQL goes here
2+
CREATE TABLE IF NOT EXISTS delegated_staking_pools (
3+
staking_pool_address VARCHAR(66) UNIQUE PRIMARY KEY NOT NULL,
4+
first_transaction_version BIGINT NOT NULL,
5+
inserted_at TIMESTAMP NOT NULL DEFAULT NOW()
6+
);
7+
CREATE INDEX dsp_insat_index ON delegated_staking_pools (inserted_at);
8+
ALTER TABLE current_staking_pool_voter
9+
ADD COLUMN IF NOT EXISTS operator_address VARCHAR(66) NOT NULL;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- This file should undo anything in `up.sql`
2+
DROP VIEW IF EXISTS address_version_from_events;
3+
DROP VIEW IF EXISTS address_version_from_move_resources;
4+
DROP VIEW IF EXISTS current_collection_ownership_view;
5+
DROP VIEW IF EXISTS num_active_delegator_per_pool;
6+
DROP INDEX IF EXISTS curr_to_collection_hash_owner_index;

0 commit comments

Comments
 (0)