diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index b7f4916a..92e5c8e6 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -7,23 +7,26 @@ on: jobs: build: - runs-on: ${{ matrix.os }} + name: "Build: ${{ matrix.config.name }} / ${{ matrix.config.platform }}" + runs-on: ${{ matrix.config.os }} strategy: + fail-fast: true matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - rust: [stable] + config: + - { name: "Windows Latest", os: windows-latest, platform: x64 } + - { name: "Ubuntu Latest", os: ubuntu-latest, platform: x64 } + - { name: "macOS 11", os: macos-11, platform: x64 } + - { name: "macOS Latest", os: macos-latest, platform: arm64 } steps: - - name: Set up Rust - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - name: Set up OpenJDK 17 + uses: actions/setup-java@v3 with: - toolchain: ${{ matrix.rust }} + java-version: '17' + distribution: 'temurin' + cache: 'gradle' - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Build and test - run: | - cargo build --verbose - cargo test --verbose + - name: Assemble + run: ./gradlew assemble diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index 3eaa1915..7dd70bf2 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -4,23 +4,26 @@ on: pull_request jobs: build: - runs-on: ${{ matrix.os }} + name: "Build: ${{ matrix.config.name }} / ${{ matrix.config.platform }}" + runs-on: ${{ matrix.config.os }} strategy: + fail-fast: true matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - rust: [stable] + config: + - { name: "Windows Latest", os: windows-latest, platform: x64 } + - { name: "Ubuntu Latest", os: ubuntu-latest, platform: x64 } + - { name: "macOS 11", os: macos-11, platform: x64 } + - { name: "macOS Latest", os: macos-latest, platform: arm64 } steps: - - name: Set up Rust - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - name: Set up OpenJDK 17 + uses: actions/setup-java@v3 with: - toolchain: ${{ matrix.rust }} + java-version: '17' + distribution: 'temurin' + cache: 'gradle' - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Build and test - run: | - cargo build --verbose - cargo test --verbose + - name: Assemble + run: ./gradlew assemble diff --git a/.gitignore b/.gitignore index 319cdf71..7809bbca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,52 @@ -### Rust ### -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ +### Kotlin ### +# Compiled class file +*.class -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock +# Log file +*.log -# These are backup files generated by rustfmt -**/*.rs.bk +# BlueJ files +*.ctxt -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Gradle ### +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +### Gradle Patch ### +# Java heap dump +*.hprof diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/JetClient/state.xml b/.idea/JetClient/state.xml new file mode 100644 index 00000000..8a61d02c --- /dev/null +++ b/.idea/JetClient/state.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..b589d56e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..ba1ec5c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..fdc392fe --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 00000000..966d5f56 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..887acb10 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json deleted file mode 100644 index fec513c1..00000000 --- a/.vscode/extensions.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "recommendations": [ - "vadimcn.vscode-lldb", - "rust-lang.rust-analyzer" - ] -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 6c7c85b5..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'hugin-api'", - "cargo": { - "args": [ - "build", - "--bin=hugin-api", - "--package=hugin-api" - ], - "filter": { - "name": "hugin-api", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'hugin-api'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=hugin-api", - "--package=hugin-api" - ], - "filter": { - "name": "hugin-api", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 4d9636b5..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "rust-analyzer.showUnlinkedFileNotification": false -} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 69d4525e..00000000 --- a/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "hugin-api" -version = "0.1.0" -edition = "2021" -authors = ["Marcus Cvjeticanin"] -readme = "README.md" -repository = "https://github.com/kryptokrona/hugin-api" -license = "BSD-3 Clause" -rust-version = "1.69" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rocket = { version = "=0.5.0-rc.3", features = ["json"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -sqlite = "0.30.4" -log = "0.4.17" -env_logger = "0.10.0" -reqwest = "0.11.18" \ No newline at end of file diff --git a/README.md b/README.md index 44994718..c83cc554 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Hugin API [![build](https://img.shields.io/github/actions/workflow/status/kryptokrona/hugin-api/main-ci.yml?branch=main)](https://github.com/kryptokrona/hugin-api/actions/workflows/main-ci.yml) +[![kotlin](https://img.shields.io/badge/kotlin-1.8.10-blue.svg?logo=kotlin)](http://kotlinlang.org) [![release](https://img.shields.io/github/v/release/kryptokrona/hugin-api)](https://img.shields.io/github/v/release/kryptokrona/hugin-api) [![license](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) -![](https://img.shields.io/badge/Rust-1.69+-orange.svg) [![discord](https://img.shields.io/discord/562673808582901793?label=discord)](https://discord.gg/VTgsTGS9b7) Hugin is a messaging service where messages are stored on the Kryptokrona Blockchain. Messages are secured with industry leading encryption so that only you and your chat partner have the possibility to read them. The purpose is not to gather any personal information about the users, unlike most apps and social media. diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..6ac4896c --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,33 @@ +plugins { + kotlin("multiplatform") version "1.8.21" +} + +group = "org.kryptokrona.huginapi" +version = "0.4.0" + +repositories { + mavenCentral() +} + +kotlin { + val hostOs = System.getProperty("os.name") + val isMingwX64 = hostOs.startsWith("Windows") + val nativeTarget = when { + hostOs == "Mac OS X" -> macosX64("native") + hostOs == "Linux" -> linuxX64("native") + isMingwX64 -> mingwX64("native") + else -> throw GradleException("Host OS is not supported in Kotlin/Native.") + } + + nativeTarget.apply { + binaries { + executable { + entryPoint = "main" + } + } + } + sourceSets { + val nativeMain by getting + val nativeTest by getting + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..7fc6f1ff --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..2d2fd7c7 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..a601baf8 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } + +} +rootProject.name = "hugin-api" + diff --git a/src/db/mod.rs b/src/db/mod.rs deleted file mode 100644 index 6b1c1083..00000000 --- a/src/db/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod sqlite; diff --git a/src/db/sqlite.rs b/src/db/sqlite.rs deleted file mode 100644 index 6bdd5e4e..00000000 --- a/src/db/sqlite.rs +++ /dev/null @@ -1,28 +0,0 @@ -use sqlite::{Connection, State}; - -fn init_db() -> Result<(), sqlite::Error> { - let conn = Connection::open("hugin_api.db")?; - - conn.execute( - " - CREATE TABLE IF NOT EXISTS postencrypted ( - tx_hash TEXT, - tx_box TEXT, - tx_timestamp INTEGER, - created_at DATE NOT NULL, - updated_at DATE NOT NULL - ); - - CREATE TABLE IF NOT EXISTS postencryptedgroup ( - tx_hash TEXT, - tx_sb TEXT, - tx_timestamp INTEGER, - created_at DATE NOT NULL, - updated_at DATE NOT NULL - ); - - ", - )?; - - Ok(()) -} diff --git a/src/endpoints/mod.rs b/src/endpoints/mod.rs deleted file mode 100644 index 530120e6..00000000 --- a/src/endpoints/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod post_encrypted; -pub mod post_encrypted_group; diff --git a/src/endpoints/post_encrypted.rs b/src/endpoints/post_encrypted.rs deleted file mode 100644 index 37e39b7f..00000000 --- a/src/endpoints/post_encrypted.rs +++ /dev/null @@ -1,16 +0,0 @@ -use rocket::serde::json::Json; - -#[get("/post-encrypted", format = "json")] -pub fn get_all() -> Json> { - Json(vec!["Hello".to_string(), "World".to_string()]) -} - -#[post("/post-encrypted/", format = "json")] -pub fn get_by_id(id: usize) -> Json { - Json(format!("Hello, {:?}!", id)) -} - -#[post("/post-encrypted/", format = "json", rank = 2)] -pub fn get_by_tx_hash(tx_hash: &str) -> Json { - Json(format!("Hello, {:?}!", tx_hash)) -} diff --git a/src/endpoints/post_encrypted_group.rs b/src/endpoints/post_encrypted_group.rs deleted file mode 100644 index fbcfd51f..00000000 --- a/src/endpoints/post_encrypted_group.rs +++ /dev/null @@ -1,16 +0,0 @@ -use rocket::serde::json::Json; - -#[get("/post-encrypted-group", format = "json")] -pub fn get_all() -> Json> { - Json(vec!["Hello".to_string(), "World".to_string()]) -} - -#[post("/post-encrypted-group/", format = "json")] -pub fn get_by_id(id: usize) -> Json { - Json(format!("Hello, {:?}!", id)) -} - -#[post("/post-encrypted-group/", format = "json", rank = 2)] -pub fn get_by_tx_hash(tx_hash: &str) -> Json { - Json(format!("Hello, {:?}!", tx_hash)) -} diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 0a3bac4f..00000000 --- a/src/main.rs +++ /dev/null @@ -1,40 +0,0 @@ -mod db; -mod endpoints; -mod syncers; -mod types; - -use env_logger::Env; - -#[macro_use] -extern crate rocket; - -#[catch(404)] -fn not_found() -> &'static str { - "Page not found!" -} - -#[catch(500)] -fn internal_error() -> &'static str { - "Whoops! Looks like we messed up." -} - -#[launch] -fn rocket() -> _ { - // initialize logger - // env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); - - // launch the rocket server - rocket::build() - .mount( - "/api", - routes![ - endpoints::post_encrypted::get_all, - endpoints::post_encrypted::get_by_id, - endpoints::post_encrypted::get_by_tx_hash, - endpoints::post_encrypted_group::get_all, - endpoints::post_encrypted_group::get_by_id, - endpoints::post_encrypted_group::get_by_tx_hash, - ], - ) - .register("/", catchers![not_found, internal_error]) -} diff --git a/src/nativeMain/.DS_Store b/src/nativeMain/.DS_Store new file mode 100644 index 00000000..93d80516 Binary files /dev/null and b/src/nativeMain/.DS_Store differ diff --git a/src/nativeMain/kotlin/Main.kt b/src/nativeMain/kotlin/Main.kt new file mode 100644 index 00000000..1ea23888 --- /dev/null +++ b/src/nativeMain/kotlin/Main.kt @@ -0,0 +1,3 @@ +fun main() { + println("Hello, Kotlin/Native!") +} \ No newline at end of file diff --git a/src/nativeTest/.DS_Store b/src/nativeTest/.DS_Store new file mode 100644 index 00000000..39706262 Binary files /dev/null and b/src/nativeTest/.DS_Store differ diff --git a/src/syncers/hugin.rs b/src/syncers/hugin.rs deleted file mode 100644 index 0d3fc566..00000000 --- a/src/syncers/hugin.rs +++ /dev/null @@ -1,77 +0,0 @@ -use crate::types::PoolChangesLiteRequest; -use log::{info, warn}; -use reqwest::header::HeaderMap; -use rocket::tokio::task::{self, spawn}; -use serde_json::json; -use std::{sync::Arc, thread, time}; - -async fn get_info() -> Result<(), reqwest::Error> { - let client = reqwest::Client::new(); - let response = client - .get("http://privacymine.net:11898/info") - .send() - .await?; - - println!("response status: {:?}", response.status()); - - Ok(()) -} - -async fn get_pool_changes_lite() { - let known = vec![""]; - let body = serde_json::to_string(&json!({ "knownTxsIds": known })).unwrap(); - let body = body.to_string(); - - // set headers - let mut headers = HeaderMap::new(); - headers.insert("Content-Type", "application/json".parse().unwrap()); - - // set node and request endpoint - let ip = String::from("blocksum.org"); - let port = String::from("11898"); - let endpoint = String::from("get_pool_changes_lite"); - let url = format!("http://{}:{}/{}", ip, port, endpoint); - - // make the post request - let client = reqwest::Client::new(); - let response = client - .post(url) - .headers(headers) - .body(body) - .send() - .await - .expect("Failed to get response") - .text() - .await - .expect("Failed to get payload"); - - println!("response: {:?}", response); -} - -pub async fn hugin_syncer() { - info!(target: "sync_events", "Starting Hugin syncer..."); - - let delay = time::Duration::from_secs(5); - let known = vec!["37669a52df20daf42e74757d05547f9b151ec0383819b377be1c7df59d43e2f8"]; - let pool_changes_lite_req = PoolChangesLiteRequest { - knownTxsIds: &known, - }; - - // run the hugin syncer loop - loop { - info!("Hugin syncer loop..."); - - // convert the PoolChangesLiteRequest struct to a json string - // let json_body = serde_json::to_string(&pool_changes_lite_req); - - // println!("json_body: {:?}", body); - - if let Err(e) = get_info().await { - warn!("Error: {:?}", e); - } - - thread::sleep(delay); - } - - // get_info().await; -} diff --git a/src/syncers/mod.rs b/src/syncers/mod.rs deleted file mode 100644 index 0f9d241b..00000000 --- a/src/syncers/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod hugin; diff --git a/src/types.rs b/src/types.rs deleted file mode 100644 index 16b43a9c..00000000 --- a/src/types.rs +++ /dev/null @@ -1,14 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[derive(Serialize)] -#[serde(crate = "rocket::serde")] -pub struct PoolChangesLiteRequest<'r> { - pub knownTxsIds: &'r Vec<&'r str>, -} - -#[derive(Deserialize)] -#[serde(crate = "rocket::serde")] -pub struct PoolChangesLiteResponse { - pub added_txs: Vec, - pub removed_txs: Vec, -} diff --git a/tests/db/sqlite_test.rs b/tests/db/sqlite_test.rs deleted file mode 100644 index 8b137891..00000000 --- a/tests/db/sqlite_test.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/endpoints/post_encrypted_group_test.rs b/tests/endpoints/post_encrypted_group_test.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/endpoints/post_encrypted_test.rs b/tests/endpoints/post_encrypted_test.rs deleted file mode 100644 index 8b137891..00000000 --- a/tests/endpoints/post_encrypted_test.rs +++ /dev/null @@ -1 +0,0 @@ -