Skip to content

Commit

Permalink
Merge branch 'feat/docs'
Browse files Browse the repository at this point in the history
  • Loading branch information
kokal33 committed Aug 31, 2023
2 parents 5232f3a + d976537 commit c022080
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
target
.env
.vscode
.vscode
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "fp-core"
name = "filplus-core"
version = "0.1.0"
edition = "2021"

Expand Down
28 changes: 16 additions & 12 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
pub mod application;
use std::{
fmt::Display,
pin::Pin,
task::{Context, Poll},
};

use actix_web::{
body::{BodySize, MessageBody},
web::Bytes,
};
use chrono::Utc;
use octocrab::models::{pulls::PullRequest, repos::ContentItems};
use std::{
fmt::Display,
pin::Pin,
task::{Context, Poll},
};

use self::application::{
allocations::{AllocationRequest, ApplicationAllocationTypes, ApplicationAllocationsSigner},
Expand Down Expand Up @@ -127,6 +128,8 @@ impl MessageBody for LDNApplicationError {
}

impl LDNApplication {
/// Get Active Applications
/// Returns a list of all active applications
pub async fn get_all_active_applications() -> Result<Vec<ApplicationFile>, LDNApplicationError>
{
let gh: GithubWrapper = GithubWrapper::new();
Expand All @@ -144,7 +147,6 @@ impl LDNApplication {
return (id, owner_name);
})
.collect::<Vec<_>>();
dbg!(&pull_requests);
let app_futures: Vec<_> = pull_requests
.into_iter()
.map(|i| tokio::spawn(LDNApplication::app_file_without_load(i.0)))
Expand All @@ -169,6 +171,7 @@ impl LDNApplication {
Ok(apps)
}

/// Load Application By ID
pub async fn load(application_id: String) -> Result<Self, LDNApplicationError> {
let gh: GithubWrapper = GithubWrapper::new();
let app_path = LDNPullRequest::application_path(&application_id);
Expand Down Expand Up @@ -201,6 +204,7 @@ impl LDNApplication {
}
}

/// Create New Application
pub async fn new(info: CreateApplicationInfo) -> Result<Self, LDNApplicationError> {
let application_id = info.application_id;
let gh: GithubWrapper = GithubWrapper::new();
Expand Down Expand Up @@ -317,7 +321,7 @@ impl LDNApplication {
}
}

/// Move application from Governance Review to Proposal
/// Move application from Proposal to Approved
pub async fn complete_new_application_proposal(
&self,
info: CompleteNewApplicationProposalInfo,
Expand Down Expand Up @@ -370,7 +374,7 @@ impl LDNApplication {
}
}

/// Move application from Governance Review to Proposal
/// Merge Application Pull Request
pub async fn merge_new_application_pr(&self) -> Result<ApplicationFile, LDNApplicationError> {
match self.app_state().await {
Ok(s) => match s {
Expand Down Expand Up @@ -488,6 +492,7 @@ impl LDNApplication {
Ok((parse_ldn_app_body(&issue_body), issue_creator))
}

/// Return Application state
async fn app_state(&self) -> Result<ApplicationFileState, LDNApplicationError> {
let f = self.app_file().await?;
Ok(f.info.application_lifecycle.get_state())
Expand Down Expand Up @@ -530,7 +535,7 @@ impl LDNApplication {
}
}

async fn _app_file_from_main(&self) -> Result<ApplicationFile, LDNApplicationError> {
async fn app_file_from_main(&self) -> Result<ApplicationFile, LDNApplicationError> {
let app_path = LDNPullRequest::application_path(&self.application_id);
let app_branch_name = "main";
match self.github.get_file(&app_path, &app_branch_name).await {
Expand Down Expand Up @@ -815,7 +820,6 @@ impl LDNPullRequest {
}
}

#[cfg(test)]
mod tests {
use octocrab::models::issues::Issue;
use tokio::time::{sleep, Duration};
Expand All @@ -825,10 +829,10 @@ mod tests {
#[tokio::test]
async fn end_to_end() {
// Test Creating an application
let gh = GithubWrapper::new();
let gh: GithubWrapper = GithubWrapper::new();

// let branches = gh.list_branches().await.unwrap();
let issue = gh.list_issue(14).await.unwrap();
let issue = gh.list_issue(63).await.unwrap();
let test_issue: Issue = gh
.create_issue("from test", &issue.body.unwrap())
.await
Expand Down
6 changes: 6 additions & 0 deletions src/external_services/blockchain.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const BASE_URL: &str = "https://api.filplus.d.interplanetary.one/public/api";

/// BlockchainData is a client for the Fil+ blockchain data API.
pub struct BlockchainData {
client: reqwest::Client,
base_url: String,
}

/// BlockchainDataError is an error type for BlockchainData.
#[derive(Debug)]
pub enum BlockchainDataError {
ReqwestError(reqwest::Error),
}

impl BlockchainData {
/// Setup new BlockchainData client.
pub fn new() -> Self {
use reqwest::header;
let mut headers = header::HeaderMap::new();
Expand All @@ -31,6 +34,7 @@ impl BlockchainData {
}
}

/// Get Verified Clients
pub async fn get_verified_clients(&self) -> Result<String, BlockchainDataError> {
let query = "getVerifiedClients";
let url = self.build_url(query);
Expand All @@ -51,6 +55,7 @@ impl BlockchainData {
return Ok(body);
}

/// Get Allowance For Address
pub async fn get_allowance_for_address(
&self,
address: &str,
Expand All @@ -68,6 +73,7 @@ impl BlockchainData {
return Ok(body);
}

/// Build URL
fn build_url(&self, path: &str) -> String {
format!("{}/{}", self.base_url, path)
}
Expand Down
19 changes: 14 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
extern crate markdown;

use actix_web::middleware::Logger;
use actix_web::{web, App, HttpServer};
use actix_web::{App, HttpServer};
use env_logger;
use std::sync::Mutex;

pub(crate) mod b64;
pub(crate) mod core;
pub(crate) mod external_services;
pub(crate) mod parsers;
pub(crate) mod router;

/// Http Server Setup
/// Exposes Application and Blockchain endpoints
/// Application endpoints:
/// - Create Application
/// - Trigger Application
/// - Propose Application
/// - Approve Application
/// - Merge Application
/// - Get Application
/// - Get All Applications
/// Blockchain endpoints:
/// - Address Allowance
/// - Verified Clients
#[tokio::main]
async fn main() -> std::io::Result<()> {
let gh = external_services::github::GithubWrapper::new();
let state = web::Data::new(Mutex::new(gh));
env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug"));

HttpServer::new(move || {
Expand All @@ -25,7 +35,6 @@ async fn main() -> std::io::Result<()> {
App::new()
.wrap(Logger::default())
.wrap(cors)
.app_data(state.clone())
.service(router::health)
.service(router::application::create_application)
.service(router::application::trigger_application)
Expand Down
Loading

0 comments on commit c022080

Please sign in to comment.