From 521ab1349526cc9abaceae51bd43f5b9ce7cfdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Roycourt?= Date: Thu, 7 Sep 2023 06:08:46 +0200 Subject: [PATCH] feat(core): insert into indexer table --- Cargo.lock | 39 ++++++++++++++++++++++++++++++--------- Cargo.toml | 1 + src/main.rs | 18 +++++++++++++++++- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ac472f05..d72b3330e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,6 +211,7 @@ dependencies = [ "aws-sdk-dynamodb", "aws-sdk-kinesis", "aws-types", + "chrono", "clap 4.4.1", "dotenv", "hex", @@ -428,7 +429,7 @@ dependencies = [ "http", "hyper", "ring", - "time", + "time 0.3.28", "tokio", "tower", "tracing", @@ -601,7 +602,7 @@ dependencies = [ "percent-encoding", "regex", "sha2", - "time", + "time 0.3.28", "tracing", ] @@ -746,7 +747,7 @@ dependencies = [ "num-integer", "ryu", "serde", - "time", + "time 0.3.28", ] [[package]] @@ -893,7 +894,7 @@ dependencies = [ "serde", "serde_bytes", "serde_json", - "time", + "time 0.3.28", "uuid 1.4.1", ] @@ -957,8 +958,11 @@ checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "time 0.1.45", + "wasm-bindgen", "winapi", ] @@ -1531,7 +1535,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -2034,7 +2038,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -2895,7 +2899,7 @@ dependencies = [ "serde", "serde_json", "serde_with_macros 2.3.3", - "time", + "time 0.3.28", ] [[package]] @@ -2912,7 +2916,7 @@ dependencies = [ "serde", "serde_json", "serde_with_macros 3.3.0", - "time", + "time 0.3.28", ] [[package]] @@ -3000,7 +3004,7 @@ checksum = "2230cd5c29b815c9b699fb610b49a5ed65588f3509d9f0108be3a885da629333" dependencies = [ "colored", "log", - "time", + "time 0.3.28", "windows-sys 0.42.0", ] @@ -3345,6 +3349,17 @@ dependencies = [ "syn 2.0.29", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "time" version = "0.3.28" @@ -3753,6 +3768,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 267323b4a..ac7872f5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ version = "0.1.0" edition = "2021" [dependencies] +chrono = "0.4.19" anyhow = "1.0" tokio = { version = "1", features = ["full"] } reqwest = { version = "0.11", features = ["json"] } diff --git a/src/main.rs b/src/main.rs index a313740f9..c6d3ad304 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,8 +7,9 @@ use crate::core::block::process_blocks_continuously; use anyhow::Result; use ark_starknet::{client2::StarknetClient, collection_manager::CollectionManager}; use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::Client as DynamoClient; +use aws_sdk_dynamodb::{types::AttributeValue, Client as DynamoClient}; use aws_sdk_kinesis::Client as KinesisClient; +use chrono::Utc; use dotenv::dotenv; use reqwest::{Client as ReqwestClient, Url}; use simple_logger::SimpleLogger; @@ -33,6 +34,21 @@ async fn main() -> Result<()> { let dynamo_client = DynamoClient::new(&config); let reqwest_client = ReqwestClient::new(); + let indexer_table_name = + env::var("ARK_INDEXER_TABLE_NAME").expect("ARK_INDEXER_TABLE_NAME must be set"); + + let indexer_version = env::var("ARK_INDEXER_VERSION").unwrap_or(String::from("undefined")); + let now = Utc::now(); + let unix_timestamp = now.timestamp(); + + dynamo_client + .put_item() + .table_name(indexer_table_name) + .item("PK", AttributeValue::S(String::from("ECS_"))) + .item("SK", AttributeValue::S(unix_timestamp.to_string())) + .item("status", AttributeValue::S(String::from("running"))) + .item("version", AttributeValue::S(String::from(indexer_version))); + process_blocks_continuously( &collection_manager, &rpc_client,