-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d66c51
commit 622bb6b
Showing
31 changed files
with
381 additions
and
12 deletions.
There are no files selected for viewing
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 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod balance; | |
pub mod crawler; | ||
pub mod gov; | ||
pub mod pos; | ||
pub mod revealed_pk; |
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,22 @@ | ||
use anyhow::Context; | ||
use diesel::{PgConnection, RunQueryDsl}; | ||
use orm::{revealed_pk::RevealedPkInsertDb, schema::revealed_pk}; | ||
use shared::{id::Id, public_key::PublicKey}; | ||
|
||
pub fn insert_revealed_pks( | ||
transaction_conn: &mut PgConnection, | ||
revealed_pks: Vec<(PublicKey, Id)>, | ||
) -> anyhow::Result<()> { | ||
diesel::insert_into(revealed_pk::table) | ||
.values::<&Vec<RevealedPkInsertDb>>( | ||
&revealed_pks | ||
.into_iter() | ||
.map(|(pk, address)| RevealedPkInsertDb::from(pk, address)) | ||
.collect::<Vec<_>>(), | ||
) | ||
.on_conflict_do_nothing() | ||
.execute(transaction_conn) | ||
.context("Failed to update balances in db")?; | ||
|
||
anyhow::Ok(()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- This file should undo anything in `up.sql` | ||
|
||
DROP TABLE IF EXISTS revealed_pk; |
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,9 @@ | ||
-- Your SQL goes here | ||
|
||
CREATE TABLE revealed_pk ( | ||
id SERIAL PRIMARY KEY, | ||
address VARCHAR NOT NULL, | ||
pk VARCHAR NOT NULL | ||
); | ||
|
||
ALTER TABLE revealed_pk ADD UNIQUE (address, pk); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use diesel::{Insertable, Queryable, Selectable}; | ||
use shared::{id::Id, public_key::PublicKey}; | ||
|
||
use crate::schema::revealed_pk; | ||
|
||
#[derive(Insertable, Clone, Queryable, Selectable)] | ||
#[diesel(table_name = revealed_pk)] | ||
#[diesel(check_for_backend(diesel::pg::Pg))] | ||
pub struct RevealedPkInsertDb { | ||
pub pk: String, | ||
pub address: String, | ||
} | ||
|
||
pub type RevealedPkDb = RevealedPkInsertDb; | ||
|
||
impl RevealedPkInsertDb { | ||
pub fn from(pk: PublicKey, address: Id) -> Self { | ||
Self { | ||
pk: pk.0, | ||
address: address.to_string(), | ||
} | ||
} | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use namada_sdk::key::common::PublicKey as NamadaPublicKey; | ||
|
||
pub struct PublicKey(pub String); | ||
|
||
impl From<NamadaPublicKey> for PublicKey { | ||
fn from(pk: NamadaPublicKey) -> Self { | ||
PublicKey(pk.to_string()) | ||
} | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
cargo run -- --database-url postgres://postgres:[email protected]:5435/namada-indexer --cache-url redis://[email protected]:6379 | ||
cargo run -- --database-url postgres://postgres:[email protected]:5435/namada-indexer --cache-url redis://[email protected]:6379 --tendermint-url http://127.0.0.1:27657 |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ pub mod api; | |
pub mod balance; | ||
pub mod governance; | ||
pub mod pos; | ||
pub mod revealed_pk; |
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,30 @@ | ||
use axum::http::StatusCode; | ||
use axum::response::{IntoResponse, Response}; | ||
use thiserror::Error; | ||
|
||
use crate::response::api::ApiErrorResponse; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum RevealedPkError { | ||
#[error("Revealed public key {0} not found")] | ||
NotFound(u64), | ||
#[error("Database error: {0}")] | ||
Database(String), | ||
#[error("Rpc error: {0}")] | ||
Rpc(String), | ||
#[error("Unknown error: {0}")] | ||
Unknown(String), | ||
} | ||
|
||
impl IntoResponse for RevealedPkError { | ||
fn into_response(self) -> Response { | ||
let status_code = match self { | ||
RevealedPkError::NotFound(_) => StatusCode::NOT_FOUND, | ||
RevealedPkError::Unknown(_) | ||
| RevealedPkError::Database(_) | ||
| RevealedPkError::Rpc(_) => StatusCode::INTERNAL_SERVER_ERROR, | ||
}; | ||
|
||
ApiErrorResponse::send(status_code.as_u16(), Some(self.to_string())) | ||
} | ||
} |
Oops, something went wrong.