-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use blockchain-node follower service to look up hotspots and follow tens * Ingest heartbeats and speed tests but not store them yet Co-authored-by: Marc Nijdam <[email protected]> Co-authored-by: jeffgrunewald <[email protected]> Co-authored-by: Rahul Garg <[email protected]>
- Loading branch information
1 parent
3d1abc8
commit 31de316
Showing
40 changed files
with
2,403 additions
and
749 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
create table follower_meta ( | ||
key text primary key not null, | ||
value text | ||
); | ||
|
||
insert into follower_meta (key, value) | ||
values ('last_height', '995041') |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
create table gateway ( | ||
address text primary key not null, | ||
owner text not null, | ||
location text, | ||
|
||
last_heartbeat timestamptz, | ||
last_speedtest timestamptz, | ||
last_attach timestamptz, | ||
|
||
created_at timestamptz default now() | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use crate::{api::api_error, Error, Imsi, PublicKey, Result}; | ||
use axum::{extract::Extension, http::StatusCode, Json}; | ||
use chrono::{DateTime, Utc}; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::{json, Value}; | ||
use sqlx::{PgPool, Row}; | ||
|
||
pub async fn create_cell_attach_event( | ||
Json(event): Json<CellAttachEvent>, | ||
Extension(pool): Extension<PgPool>, | ||
) -> std::result::Result<Json<Value>, (StatusCode, String)> { | ||
event | ||
.insert_into(&pool) | ||
.await | ||
.map(|pubkey: PublicKey| { | ||
json!({ | ||
"pubkey": pubkey, | ||
}) | ||
}) | ||
.map(Json) | ||
.map_err(api_error) | ||
} | ||
|
||
#[derive(sqlx::FromRow, Deserialize, Serialize)] | ||
pub struct CellAttachEvent { | ||
pub imsi: Imsi, | ||
#[serde(alias = "publicAddress")] | ||
pub pubkey: PublicKey, | ||
#[serde(alias = "iso_timestamp")] | ||
pub timestamp: DateTime<Utc>, | ||
} | ||
|
||
impl CellAttachEvent { | ||
pub async fn insert_into<'e, 'c, E>(&self, executor: E) -> Result<PublicKey> | ||
where | ||
E: 'e + sqlx::Executor<'c, Database = sqlx::Postgres>, | ||
{ | ||
sqlx::query( | ||
r#" | ||
insert into gateways (pubkey, owner, payer, height, txn_hash, block_timestamp, last_heartbeat, last_speedtest, last_attach) | ||
values ($1, NULL, NULL, 0, NULL, NULL, NULL, NULL, $2) | ||
on conflict (pubkey) do update set | ||
last_attach = EXCLUDED.last_attach | ||
returning pubkey | ||
"#, | ||
) | ||
.bind(&self.pubkey) | ||
.bind(&self.timestamp) | ||
.fetch_one(executor) | ||
.await | ||
.and_then(|row| row.try_get("pubkey")) | ||
.map_err(Error::from) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.