Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fedimint Kotlin Wrapper #35

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,37 @@ This project is intended to be an easy-to-use starting point for those intereste

## Getting Started

You can install the cli app with `cargo install fedimint-clientd` or by cloning the repo and running `cargo build --release` in the root directory.

`fedimint-clientd` runs from the command line and takes a few arguments, which are also available as environment variables. Fedimint uses rocksDB, an embedded key-value store, to store its state. The `--fm_db_path` argument is required and should be an absolute path to a directory where the database will be stored.

```
CLI USAGE:
fedimint-clientd \
--db-path=/absolute/path/to/dir/to/store/database \
--password="some-secure-password-that-becomes-the-bearer-token" \
--addr="127.0.0.1:8080"
--mode="rest"
--invite-code="fed1-fedimint-invite-code"

ENV USAGE:
FEDIMINT_CLIENTD_DB_PATH=/absolute/path/to/dir/to/store/database
FEDIMINT_CLIENTD_PASSWORD="some-secure-password-that-becomes-the-bearer-token"
FEDIMINT_CLIENTD_ADDR="127.0.0.1:8080"
FEDIMINT_CLIENTD_MODE="rest"
FEDIMINT_CLIENTD_INVITE_CODE="fed1-fedimint-invite-code"
```
1. You can install the cli app with `cargo install fedimint-clientd` or by cloning the repo and running `cargo build --release` in the root directory.

`fedimint-clientd` runs from the command line and takes a few arguments, which are also available as environment variables. Fedimint uses rocksDB, an embedded key-value store, to store its state. The `--fm_db_path` argument is required and should be an absolute path to a directory where the database will be stored.

```shell
CLI USAGE:
fedimint-clientd \
--db-path=/absolute/path/to/dir/to/store/database \
--password="some-secure-password-that-becomes-the-bearer-token" \
--addr="127.0.0.1:3333"
--mode="rest"
--invite-code="fed1-fedimint-invite-code"
```

2. With a Nix environment already setup:
- Clone the repo and run `nix develop` to install and build the dependencies.
- Run `just dev` to fire up the client app.

Make sure to configure your environment variables as shown below:

```shell
ENV USAGE:
FEDIMINT_CLIENTD_DB_PATH=/absolute/path/to/dir/to/store/database
FEDIMINT_CLIENTD_PASSWORD="some-secure-password-that-becomes-the-bearer-token"
FEDIMINT_CLIENTD_ADDR="127.0.0.1:3333"
FEDIMINT_CLIENTD_BASE_URL="127.0.0.1:3333"
FEDIMINT_CLIENTD_MODE="rest"
# this is the invite code to the Fedi Alpha federation mutinynet,
# you can replace it with another but its the most useful one for testing so good to at least have it
FEDIMINT_CLIENTD_INVITE_CODE="fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75"
```

## Fedimint Clientd Endpoints

Expand Down
4 changes: 4 additions & 0 deletions justfile.local.just
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ test-py-async:
test-go:
cd wrappers/fedimint-go && go run cmd/main.go

test-kotlin:
cd wrappers/fedimint-kotlin && ./gradlew build && ./gradlew run

test-all:
set -e
(just test-ts && echo "test-ts completed successfully") &
(just test-py && echo "test-py completed successfully") &
(just test-py-async && echo "test-py-async completed successfully") &
(just test-go && echo "test-go completed successfully") &
(just test-kotlin && echo "test-kotlin completed successfully") &
wait

wscat:
Expand Down
36 changes: 36 additions & 0 deletions wrappers/fedimint-kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
34 changes: 34 additions & 0 deletions wrappers/fedimint-kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

# Fedimint SDK for Kotlin

This is a Kotlin client that consumes the Fedimint Http Client (https://github.com/kodylow/fedimint-http-client)[https://github.com/kodylow/fedimint-http-client], communicating with it via HTTP and a password. It's a hacky prototype, but it works. All of the federation handling code happens in the fedimint-http-client, this just exposes a simple API for interacting with the client from Kotlin.

Start the following in the fedimint-http-client .env environment variables:

```bash
FEDIMINT_CLIENTD_DB_PATH="YOUR-DATABASE-PATH"
FEDIMINT_CLIENTD_PASSWORD="YOUR-PASSWORD"
FEDIMINT_CLIENTD_ADDR="127.0.0.1:3333"
FEDIMINT_CLIENTD_MODE="rest"
FEDIMINT_CLIENTD_INVITE_CODE="fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75"
FEDIMINT_CLIENTD_BASE_URL="127.0.0.1:3333"
```

Then start the fedimint-http-client server:

```bash
cargo run
```

Then you are ready to run the Kotlin client. You have 2 oprions to fire it up:

1. Use an Intellij IDE or Android Studio.

This is the simplest and best way to work with the Kotlin wrapper. Open the Kotlin project with any Gradle based IDE such as Intellij or Android Studio.

2. Run the following commands from the Kotlin project root folder.

```bash
./gradlew build
./gradlew run
```
43 changes: 43 additions & 0 deletions wrappers/fedimint-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

val ktor_version: String by project
val kotlin_version: String by project
val logback_version: String by project

plugins {
kotlin("jvm") version "1.9.24"
id("io.ktor.plugin") version "2.3.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.24"
}

group = "com.cashu"
version = "0.0.1"

application {
mainClass.set("com.cashu.ApplicationKt")

val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}

repositories {
mavenCentral()
}

dependencies {
implementation("io.ktor:ktor-server-content-negotiation-jvm")
implementation("io.ktor:ktor-server-core-jvm")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
implementation("io.ktor:ktor-server-netty-jvm")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version")
implementation("io.ktor:ktor-client-auth:$ktor_version")
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-serialization-gson:$ktor_version")
implementation(kotlin("script-runtime"))
implementation ("io.github.cdimascio:dotenv-kotlin:6.4.1")
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
4 changes: 4 additions & 0 deletions wrappers/fedimint-kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ktor_version=2.3.10
kotlin_version=1.9.24
logback_version=1.4.14
kotlin.code.style=official
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading