-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compliance: compliance-server: Define initial compliance api
- Loading branch information
Showing
22 changed files
with
176 additions
and
1,269 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "compliance-api" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
serde = { version = "1", features = ["derive"] } | ||
serde_json = { version = "1" } |
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,17 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The response type for a compliance check | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct ComplianceCheckResponse { | ||
/// The compliance status of the wallet | ||
pub compliance_status: ComplianceStatus, | ||
} | ||
|
||
/// The status on compliance for a wallet | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub enum ComplianceStatus { | ||
/// The wallet is compliant | ||
Compliant, | ||
/// The wallet is not compliant | ||
NotCompliant, | ||
} | ||
Check failure on line 17 in compliance/compliance-api/src/lib.rs GitHub Actions / clippymissing documentation for the crate
Check failure on line 17 in compliance/compliance-api/src/lib.rs GitHub Actions / clippymissing documentation for the crate
|
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,17 @@ | ||
[package] | ||
name = "compliance-server" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# === HTTP Server === # | ||
http-body-util = "0.1.0" | ||
warp = "0.3" | ||
compliance-api = { path = "../compliance-api" } | ||
|
||
# === Renegade Dependencies === # | ||
renegade-util = { workspace = true } | ||
|
||
# === Misc === # | ||
clap = { version = "4.5", features = ["derive"] } | ||
tokio = { version = "1.37", features = ["full"] } |
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,17 @@ | ||
//! Error types for the compliance server | ||
|
||
use std::{error::Error, fmt::Display}; | ||
|
||
use warp::reject::Reject; | ||
|
||
/// The error type emitted by the compliance server | ||
#[derive(Debug, Clone)] | ||
pub enum ComplianceServerError {} | ||
|
||
impl Display for ComplianceServerError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "ComplianceServerError") | ||
} | ||
} | ||
impl Error for ComplianceServerError {} | ||
impl Reject for ComplianceServerError {} |
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,68 @@ | ||
use clap::Parser; | ||
use compliance_api::{ComplianceCheckResponse, ComplianceStatus}; | ||
use error::ComplianceServerError; | ||
use renegade_util::telemetry::{setup_system_logger, LevelFilter}; | ||
use warp::{reply::Json, Filter}; | ||
|
||
pub mod error; | ||
|
||
/// The CLI for the compliance server | ||
#[derive(Debug, Clone, Parser)] | ||
#[command(about = "The CLI for the compliance server")] | ||
struct Cli { | ||
/// The port to listen on | ||
#[arg(short, long)] | ||
port: u16, | ||
/// The Chainalysis API key | ||
#[arg(long)] | ||
chainalysis_api_key: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
setup_system_logger(LevelFilter::INFO); | ||
let cli = Cli::parse(); | ||
|
||
// Get compliance information for a wallet | ||
let chainalysis_key = cli.chainalysis_api_key.clone(); | ||
let compliance_check = warp::get() | ||
.and(warp::path("v0")) | ||
.and(warp::path("compliance-check")) | ||
.and(warp::path::param::<String>()) // wallet_address | ||
.and_then(move |wallet_address| { | ||
let key = chainalysis_key.clone(); | ||
async move { | ||
handle_req(wallet_address, &key).await | ||
} | ||
}); | ||
|
||
// GET /ping | ||
let ping = warp::get() | ||
.and(warp::path("ping")) | ||
.map(|| warp::reply::with_status("PONG", warp::http::StatusCode::OK)); | ||
|
||
let routes = compliance_check.or(ping); | ||
warp::serve(routes).run(([0, 0, 0, 0], cli.port)).await | ||
} | ||
|
||
/// Handle a request for a compliance check | ||
async fn handle_req( | ||
wallet_address: String, | ||
chainalysis_api_key: &str, | ||
) -> Result<Json, warp::Rejection> { | ||
let compliance_status = check_wallet_compliance(wallet_address, chainalysis_api_key).await?; | ||
let resp = ComplianceCheckResponse { compliance_status }; | ||
Ok(warp::reply::json(&resp)) | ||
} | ||
|
||
/// Check the compliance of a wallet | ||
async fn check_wallet_compliance( | ||
wallet_address: String, | ||
chainalysis_api_key: &str, | ||
) -> Result<ComplianceStatus, ComplianceServerError> { | ||
// 1. Check the DB first | ||
|
||
// 2. If not present, check the chainalysis API | ||
|
||
todo!() | ||
} |
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
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.
Oops, something went wrong.