-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fedimint-py and fedimint-go
- Loading branch information
Showing
33 changed files
with
1,519 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
fm_client_db | ||
.cargo | ||
.vscode | ||
.DS_Store |
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 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 @@ | ||
.env |
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,42 @@ | ||
<img src="assets/fedimint-gophers.png" width="400px" /> | ||
|
||
# Fedimint SDK for Go | ||
|
||
This is a Go 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 until we can get a proper Go client for Fedimint. All of the federation handling code happens in the fedimint-http-client, this just exposes a simple API for interacting with the client from Go (will be mirrored in Python and Go). | ||
|
||
Start the following in the fedimint-http-client .env environment variables: | ||
|
||
```bash | ||
FEDERATION_INVITE_CODE = 'fed1-some-invite-code' | ||
SECRET_KEY = 'some-secret-key' # generate this with `openssl rand -base64 32` | ||
FM_DB_PATH = '/absolute/path/to/fm.db' # just make this a new dir called `fm_db` in the root of the fedimint-http-client and use the absolute path to thatm it'll create the db file for you on startup | ||
PASSWORD = 'password' | ||
DOMAIN = 'localhost' | ||
PORT = 5000 | ||
BASE_URL = 'http://localhost:5000' | ||
``` | ||
|
||
Then start the fedimint-http-client server: | ||
|
||
```bash | ||
cargo run | ||
``` | ||
|
||
Then you're ready to run the go client, which will use the same base url and password as the fedimint-http-client: | ||
|
||
```bash | ||
BASE_URL = 'http://localhost:5000' | ||
PASSWORD = 'password' | ||
``` | ||
|
||
To install dependencies: | ||
```bash | ||
go get | ||
``` | ||
|
||
To run (this just runs an example that creates FedimintClient in go and creates an invoice): | ||
@TODO: make this actually export the client for go registry | ||
|
||
```bash | ||
go run cmd/main.go | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,69 @@ | ||
package main | ||
|
||
import ( | ||
"fedimint-go-client/pkg/fedimint" | ||
"fedimint-go-client/pkg/fedimint/types/modules" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/joho/godotenv" | ||
) | ||
|
||
func main() { | ||
err := godotenv.Load() | ||
if err != nil { | ||
fmt.Println("Error loading .env file") | ||
} | ||
|
||
baseUrl := os.Getenv("BASE_URL") | ||
if baseUrl == "" { | ||
baseUrl = "http://localhost:5000" | ||
} | ||
|
||
password := os.Getenv("PASSWORD") | ||
if password == "" { | ||
password = "password" | ||
} | ||
|
||
federationId := os.Getenv("FEDERATION_ID") | ||
if federationId == "" { | ||
federationId = "defaultId" | ||
} | ||
|
||
fedimintClient := fedimint.NewFedimintClient(baseUrl, password, federationId) | ||
|
||
info, err := fedimintClient.Info() | ||
if err != nil { | ||
fmt.Println("Error getting info: ", err) | ||
return | ||
} | ||
fmt.Println("Current Total Msats Ecash: ", info.TotalAmountMsat) | ||
|
||
invoiceRequest := modules.LnInvoiceRequest{ | ||
AmountMsat: 10000, | ||
Description: "test", | ||
} | ||
|
||
invoiceResponse, err := fedimintClient.Ln.CreateInvoice(invoiceRequest, &federationId) | ||
if err != nil { | ||
fmt.Println("Error creating invoice: ", err) | ||
return | ||
} | ||
|
||
fmt.Println("Created 10 sat Invoice: ", invoiceResponse.Invoice) | ||
|
||
fmt.Println("Waiting for payment...") | ||
|
||
awaitInvoiceRequest := modules.AwaitInvoiceRequest{ | ||
OperationID: invoiceResponse.OperationID, | ||
} | ||
|
||
_, err = fedimintClient.Ln.AwaitInvoice(awaitInvoiceRequest, &federationId) | ||
if err != nil { | ||
fmt.Println("Error awaiting invoice: ", err) | ||
return | ||
} | ||
|
||
fmt.Println("Payment Received!") | ||
// fmt.Println("New Total Msats Ecash: ", awaitInvoiceResponse.TotalAmountMsat) | ||
} |
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 @@ | ||
{ | ||
description = "Fedimint Go SDK"; | ||
|
||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let pkgs = import nixpkgs { inherit system; }; | ||
in { | ||
devShells = { | ||
default = pkgs.mkShell { | ||
nativeBuildInputs = [ pkgs.go_1_21 pkgs.starship ]; | ||
shellHook = '' | ||
eval "$(starship init bash)" | ||
''; | ||
}; | ||
}; | ||
}); | ||
} |
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,5 @@ | ||
module fedimint-go-client | ||
|
||
go 1.21.3 | ||
|
||
require github.com/joho/godotenv v1.5.1 // indirect |
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,2 @@ | ||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= | ||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= |
Oops, something went wrong.