From 0119256bb393fe20efa0620cd87df62d1406d6b8 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Sat, 23 Mar 2024 17:17:48 -0700 Subject: [PATCH] feat: continue fedimint-go 0.3 updates --- JUSTFILE | 3 + wrappers/fedimint-go/cmd/main.go | 139 ++++++++++++--- wrappers/fedimint-go/go.mod | 6 +- wrappers/fedimint-go/go.sum | 4 + wrappers/fedimint-go/pkg/fedimint/client.go | 163 ++++++++++++------ .../fedimint-go/pkg/fedimint/types/common.go | 26 ++- wrappers/fedimint-ts/FedimintClient.ts | 4 + wrappers/fedimint-ts/test.ts | 14 +- 8 files changed, 264 insertions(+), 95 deletions(-) diff --git a/JUSTFILE b/JUSTFILE index 1209903..0ab0e28 100644 --- a/JUSTFILE +++ b/JUSTFILE @@ -10,6 +10,9 @@ mprocs: test-ts: bun run wrappers/fedimint-ts/test.ts +test-go: + cd wrappers/fedimint-go && go run cmd/main.go + alias b := build alias c := check alias t := test diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 4753806..73ac4c8 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -1,69 +1,158 @@ package main import ( + "encoding/hex" "fedimint-go-client/pkg/fedimint" - "fedimint-go-client/pkg/fedimint/types/modules" "fmt" "os" + "github.com/btcsuite/btcd/btcec/v2" "github.com/joho/godotenv" ) -func main() { - err := godotenv.Load() +func logMethod(method string) { + fmt.Println("--------------------") + fmt.Printf("Method: %s\n", method) +} + +func logInputAndOutput(input interface{}, output interface{}) { + fmt.Println("Input: ", input) + fmt.Println("Output: ", output) + fmt.Println("--------------------") +} + +type KeyPair struct { + PrivateKey string + PublicKey string +} + +func newKeyPair() KeyPair { + privateKey, err := btcec.NewPrivateKey() + if err != nil { + panic("failed to generate a private key") + } + + pubKey := privateKey.PubKey() + return KeyPair{ + PrivateKey: hex.EncodeToString(privateKey.Serialize()), + PublicKey: hex.EncodeToString(pubKey.SerializeCompressed()), + } +} + +func buildTestClient() *fedimint.FedimintClient { + err := godotenv.Load(".env") if err != nil { fmt.Println("Error loading .env file") } - baseUrl := os.Getenv("BASE_URL") + baseUrl := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") if baseUrl == "" { - baseUrl = "http://localhost:5000" + baseUrl = "http://127.0.0.1:3333" } - password := os.Getenv("PASSWORD") + password := os.Getenv("FEDIMINT_CLIENTD_PASSWORD") if password == "" { password = "password" } - federationId := os.Getenv("FEDERATION_ID") + federationId := os.Getenv("FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID") if federationId == "" { - federationId = "defaultId" + federationId = "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" } - fedimintClient := fedimint.NewFedimintClient(baseUrl, password, federationId) + return fedimint.NewFedimintClient(baseUrl, password, federationId) +} - info, err := fedimintClient.Info() +func main() { + client := buildTestClient() + keyPair := newKeyPair() + fmt.Println("Generated key pair: ", keyPair) + + // ADMIN METHODS + // `/v2/admin/config` + logMethod("/v2/admin/config") + data, err := client.Config() if err != nil { - fmt.Println("Error getting info: ", err) + fmt.Println("Error calling config: ", err) return } - fmt.Println("Current Total Msats Ecash: ", info.TotalAmountMsat) + logInputAndOutput(nil, data) - invoiceRequest := modules.LnInvoiceRequest{ - AmountMsat: 10000, - Description: "test", + // `/v2/admin/discover-version` + logMethod("/v2/admin/discover-version") + data, err = client.DiscoverVersion(1) + if err != nil { + fmt.Println("Error calling discoverVersion: ", err) + return } + logInputAndOutput(nil, data) - invoiceResponse, err := fedimintClient.Ln.CreateInvoice(invoiceRequest, &federationId) + // `/v2/admin/federation-ids` + logMethod("/v2/admin/federation-ids") + federationIds, err := client.FederationIds() if err != nil { - fmt.Println("Error creating invoice: ", err) + fmt.Println("Error calling federationIds: ", err) return } + logInputAndOutput(nil, federationIds) - fmt.Println("Created 10 sat Invoice: ", invoiceResponse.Invoice) + // `/v2/admin/info` + logMethod("/v2/admin/info") + infoData, err := client.Info() + if err != nil { + fmt.Println("Error calling info: ", err) + return + } + logInputAndOutput(nil, infoData) - fmt.Println("Waiting for payment...") + // `/v2/admin/join` + inviteCode := os.Getenv("FEDIMINT_CLIENTD_INVITE_CODE") + if inviteCode == "" { + inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" + } + logMethod("/v2/admin/join") + joinData, err := client.Join(inviteCode, true, true, false) + if err != nil { + fmt.Println("Error calling join: ", err) + return + } + logInputAndOutput(map[string]interface{}{"inviteCode": inviteCode}, joinData) - awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ - OperationID: invoiceResponse.OperationID, + // `/v2/admin/list-operations` + logMethod("/v2/admin/list-operations") + listOperationsData, err := client.ListOperations(10, nil) + if err != nil { + fmt.Println("Error calling listOperations: ", err) + return + } + logInputAndOutput(map[string]interface{}{"limit": 10}, listOperationsData) + + // LIGHTNING METHODS + // `/v2/ln/list-gateways` + logMethod("/v2/ln/list-gateways") + listGatewaysData, err := client.Ln.ListGateways() + if err != nil { + fmt.Println("Error calling listGateways: ", err) + return + } + logInputAndOutput(nil, listGatewaysData) + + // `/v2/ln/invoice` + logMethod("/v2/ln/invoice") + invoiceData, err := client.Ln.CreateInvoice(10000, "test") + if err != nil { + fmt.Println("Error calling createInvoice: ", err) + return } + logInputAndOutput(map[string]interface{}{"amountMsat": 10000, "description": "test"}, invoiceData) - _, err = fedimintClient.Ln.AwaitInvoice(awaitInvoiceRequest, &federationId) + // `/v2/ln/pay` + logMethod("/v2/ln/pay") + payData, err := client.Ln.Pay(invoiceData.Invoice, nil) if err != nil { - fmt.Println("Error awaiting invoice: ", err) + fmt.Println("Error calling pay: ", err) return } + logInputAndOutput(map[string]interface{}{"paymentInfo": invoiceData.Invoice}, payData) - fmt.Println("Payment Received!") - // fmt.Println("New Total Msats Ecash: ", awaitInvoiceResponse.TotalAmountMsat) } diff --git a/wrappers/fedimint-go/go.mod b/wrappers/fedimint-go/go.mod index 96da908..015fe7f 100644 --- a/wrappers/fedimint-go/go.mod +++ b/wrappers/fedimint-go/go.mod @@ -2,4 +2,8 @@ module fedimint-go-client go 1.21.3 -require github.com/joho/godotenv v1.5.1 // indirect +require ( + github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect +) diff --git a/wrappers/fedimint-go/go.sum b/wrappers/fedimint-go/go.sum index d61b19e..ca953b9 100644 --- a/wrappers/fedimint-go/go.sum +++ b/wrappers/fedimint-go/go.sum @@ -1,2 +1,6 @@ +github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= +github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 1f15d1a..9fc153a 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -6,7 +6,7 @@ import ( "fedimint-go-client/pkg/fedimint/types" "fedimint-go-client/pkg/fedimint/types/modules" "fmt" - "io/ioutil" + "io" "net/http" ) @@ -34,7 +34,7 @@ type OnchainModule struct { func NewFedimintClient(baseURL, password string, activeFederationId string) *FedimintClient { fc := &FedimintClient{ - BaseURL: baseURL + "/fedimint/v2", + BaseURL: baseURL + "/v2", Password: password, ActiveFederationId: activeFederationId, } @@ -58,32 +58,38 @@ func (fc *FedimintClient) fetchWithAuth(endpoint string, method string, body []b return nil, err } defer resp.Body.Close() + + responseBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } + if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("HTTP error! status: %d", resp.StatusCode) + return nil, fmt.Errorf("HTTP error! status: %d, message: %s", resp.StatusCode, string(responseBody)) } - return ioutil.ReadAll(resp.Body) + return responseBody, nil } -func (fc *FedimintClient) getActiveFederationId() string { +func (fc *FedimintClient) GetActiveFederationId() string { return fc.ActiveFederationId } -func (fc *FedimintClient) setActiveFederationId(federationId string, useDefaultGateway bool) { +func (fc *FedimintClient) SetActiveFederationId(federationId string, useDefaultGateway bool) { fc.ActiveFederationId = federationId if useDefaultGateway { - fc.useDefaultGateway() + fc.UseDefaultGateway() } } -func (fc *FedimintClient) getActiveGatewayId() string { +func (fc *FedimintClient) GetActiveGatewayId() string { return fc.ActiveGatewayId } -func (fc *FedimintClient) setActiveGatewayId(gatewayId string) { +func (fc *FedimintClient) SetActiveGatewayId(gatewayId string) { fc.ActiveGatewayId = gatewayId } -func (fc *FedimintClient) useDefaultGateway() error { +func (fc *FedimintClient) UseDefaultGateway() error { // hits list_gateways and sets activeGatewayId to the first gateway gateways, err := fc.Ln.ListGateways() if err != nil { @@ -103,40 +109,80 @@ func (fc *FedimintClient) get(endpoint string) ([]byte, error) { func (fc *FedimintClient) post(endpoint string, body interface{}) ([]byte, error) { jsonBody, err := json.Marshal(body) - fmt.Println("jsonBody: ", string(jsonBody)) if err != nil { return nil, err } + fmt.Println("jsonBody: ", string(jsonBody)) return fc.fetchWithAuth(endpoint, "POST", jsonBody) } -func (fc *FedimintClient) postWithFederationId(endpoint string, body interface{}, federationId string) ([]byte, error) { - effectiveFederationId := federationId - if effectiveFederationId == "" { - effectiveFederationId = fc.ActiveFederationId +func (fc *FedimintClient) postWithFederationId(endpoint string, body interface{}, federationId *string) ([]byte, error) { + // Marshal the original body to JSON + originalBodyJSON, err := json.Marshal(body) + if err != nil { + return nil, err } - return fc.post(endpoint, map[string]interface{}{ - "body": body, - "federationId": effectiveFederationId, - }) + // Unmarshal the JSON into a map to add federationId + var bodyMap map[string]interface{} + err = json.Unmarshal(originalBodyJSON, &bodyMap) + if err != nil { + return nil, err + } + + // Add federationId to the map + effectiveFederationId := fc.ActiveFederationId + if federationId != nil { + effectiveFederationId = *federationId + } + bodyMap["federationId"] = effectiveFederationId + + // Marshal the modified map back to JSON + modifiedBodyJSON, err := json.Marshal(bodyMap) + if err != nil { + return nil, err + } + + // Use the modified JSON as the body for the POST request + return fc.fetchWithAuth(endpoint, "POST", modifiedBodyJSON) } -func (fc *FedimintClient) postWithGatewayIdAndFederationId(endpoint string, body interface{}, gatewayId string, federationId string) ([]byte, error) { - effectiveFederationId := federationId - if effectiveFederationId == "" { - effectiveFederationId = fc.ActiveFederationId +func (fc *FedimintClient) postWithGatewayIdAndFederationId(endpoint string, body interface{}, gatewayId *string, federationId *string) ([]byte, error) { + // Marshal the original body to JSON + originalBodyJSON, err := json.Marshal(body) + if err != nil { + return nil, err } - effectiveGatewayId := gatewayId - if effectiveGatewayId == "" { - effectiveGatewayId = fc.ActiveGatewayId + + // Unmarshal the JSON into a map to add federationId + var bodyMap map[string]interface{} + err = json.Unmarshal(originalBodyJSON, &bodyMap) + if err != nil { + return nil, err + } + + // Add federationId to the map + effectiveFederationId := fc.ActiveFederationId + if federationId != nil { + effectiveFederationId = *federationId + } + bodyMap["federationId"] = effectiveFederationId + + // Add gatewayId to the map + effectiveGatewayId := fc.ActiveGatewayId + if gatewayId != nil { + effectiveGatewayId = *gatewayId + } + bodyMap["gatewayId"] = effectiveGatewayId + + // Marshal the modified map back to JSON + modifiedBodyJSON, err := json.Marshal(bodyMap) + if err != nil { + return nil, err } - return fc.post(endpoint, map[string]interface{}{ - "body": body, - "gatewayId": effectiveGatewayId, - "federationId": effectiveFederationId, - }) + // Use the modified JSON as the body for the POST request + return fc.fetchWithAuth(endpoint, "POST", modifiedBodyJSON) } func (fc *FedimintClient) Info() (*types.InfoResponse, error) { @@ -165,13 +211,14 @@ func (fc *FedimintClient) Config() (*types.FedimintResponse, error) { return &configResp, nil } -func (fc *FedimintClient) Backup(metadata *types.BackupRequest, federationId string) error { +func (fc *FedimintClient) Backup(metadata *types.BackupRequest, federationId *string) error { _, err := fc.postWithFederationId("/admin/backup", metadata, federationId) return err } -func (fc *FedimintClient) DiscoverVersion(threshold *int) (*types.FedimintResponse, error) { - resp, err := fc.post("/admin/discover-version", threshold) +func (fc *FedimintClient) DiscoverVersion(threshold uint16) (*types.FedimintResponse, error) { + request := types.DiscoverVersionRequest{Threshold: threshold} + resp, err := fc.post("/admin/discover-version", request) if err != nil { return nil, err } @@ -183,13 +230,13 @@ func (fc *FedimintClient) DiscoverVersion(threshold *int) (*types.FedimintRespon return &versionResp, nil } -func (fc *FedimintClient) ListOperations(limit int, federationId *string) (*types.OperationOutput, error) { +func (fc *FedimintClient) ListOperations(limit uint16, federationId *string) (*types.ListOperationsResponse, error) { request := types.ListOperationsRequest{Limit: limit} - resp, err := fc.post("/admin/list-operations", request) + resp, err := fc.postWithFederationId("/admin/list-operations", request, federationId) if err != nil { return nil, err } - var operationsResp types.OperationOutput + var operationsResp types.ListOperationsResponse err = json.Unmarshal(resp, &operationsResp) if err != nil { return nil, err @@ -217,16 +264,19 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us var response types.JoinResponse responseBody, err := fc.post("/admin/join", request) - - if setActiveFederationId { - fc.setActiveFederationId(response.ThisFederationId, useDefaultGateway) + if err != nil { + return response, err } + err = json.Unmarshal(responseBody, &response) if err != nil { return response, err } - err = json.Unmarshal(responseBody, &response) + if setActiveFederationId { + fc.SetActiveFederationId(response.ThisFederationId, useDefaultGateway) + } + if err != nil { return response, err } @@ -239,7 +289,7 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us func (onchain *OnchainModule) createDepositAddress(timeout int, federationId *string) (*modules.OnchainDepositAddressResponse, error) { request := modules.OnchainDepositAddressRequest{Timeout: timeout} - resp, err := onchain.Client.postWithFederationId("/onchain/deposit-address", request, *federationId) + resp, err := onchain.Client.postWithFederationId("/onchain/deposit-address", request, federationId) if err != nil { return nil, err } @@ -253,7 +303,7 @@ func (onchain *OnchainModule) createDepositAddress(timeout int, federationId *st func (onchain *OnchainModule) awaitDeposit(operationId string, federationId *string) (*modules.OnchainAwaitDepositResponse, error) { request := modules.OnchainAwaitDepositRequest{OperationId: operationId} - resp, err := onchain.Client.postWithFederationId("/onchain/await-deposit", request, *federationId) + resp, err := onchain.Client.postWithFederationId("/onchain/await-deposit", request, federationId) if err != nil { return nil, err } @@ -267,7 +317,7 @@ func (onchain *OnchainModule) awaitDeposit(operationId string, federationId *str func (onchain *OnchainModule) withdraw(address string, amountSat int, federationId *string) (*modules.OnchainWithdrawResponse, error) { request := modules.OnchainWithdrawRequest{Address: address, AmountSat: amountSat} - resp, err := onchain.Client.postWithFederationId("/onchain/withdraw", request, *federationId) + resp, err := onchain.Client.postWithFederationId("/onchain/withdraw", request, federationId) if err != nil { return nil, err } @@ -285,7 +335,7 @@ func (onchain *OnchainModule) withdraw(address string, amountSat int, federation func (mint *MintModule) DecodeNotes(notes string, federationId *string) (*modules.DecodeNotesResponse, error) { request := modules.DecodeNotesRequest{Notes: notes} - resp, err := mint.Client.postWithFederationId("/mint/decode-notes", request, *federationId) + resp, err := mint.Client.postWithFederationId("/mint/decode-notes", request, federationId) if err != nil { return nil, err } @@ -303,7 +353,7 @@ func (mint *MintModule) EncodeNotes(notesJson modules.NotesJson, federationId *s return nil, err } request := modules.EncodeNotesRequest{NotesJsonStr: string(notesJsonStr)} - resp, err := mint.Client.postWithFederationId("/mint/encode-notes", request, *federationId) + resp, err := mint.Client.postWithFederationId("/mint/encode-notes", request, federationId) if err != nil { return nil, err } @@ -317,7 +367,7 @@ func (mint *MintModule) EncodeNotes(notesJson modules.NotesJson, federationId *s func (mint *MintModule) Reissue(notes string, federationId *string) (*modules.MintReissueResponse, error) { request := modules.MintReissueRequest{Notes: notes} - resp, err := mint.Client.postWithFederationId("/mint/reissue", request, *federationId) + resp, err := mint.Client.postWithFederationId("/mint/reissue", request, federationId) if err != nil { return nil, err } @@ -336,7 +386,7 @@ func (mint *MintModule) Spend(amountMsat uint64, allowOverpay bool, timeout uint Timeout: timeout, IncludeInvite: includeInvite, } - resp, err := mint.Client.postWithFederationId("/mint/spend", request, *federationId) + resp, err := mint.Client.postWithFederationId("/mint/spend", request, federationId) if err != nil { return nil, err } @@ -350,7 +400,7 @@ func (mint *MintModule) Spend(amountMsat uint64, allowOverpay bool, timeout uint func (mint *MintModule) Validate(notes string, federationId *string) (*modules.MintValidateResponse, error) { request := modules.MintValidateRequest{Notes: notes} - resp, err := mint.Client.postWithFederationId("/mint/validate", request, *federationId) + resp, err := mint.Client.postWithFederationId("/mint/validate", request, federationId) if err != nil { return nil, err } @@ -400,8 +450,7 @@ func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, expiryT Description: description, ExpiryTime: expiryTime, } - fmt.Println("request: ", request) - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice", request, *gatewayId, *federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice", request, gatewayId, federationId) if err != nil { return nil, err } @@ -421,7 +470,7 @@ func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, des ExternalPubkey: pubkey, } fmt.Println("request: ", request) - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey", request, *gatewayId, *federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey", request, gatewayId, federationId) if err != nil { return nil, err } @@ -442,7 +491,7 @@ func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amo Tweak: tweak, } fmt.Println("request: ", request) - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey-tweaked", request, *gatewayId, *federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey-tweaked", request, gatewayId, federationId) if err != nil { return nil, err } @@ -456,7 +505,7 @@ func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amo func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) (*types.InfoResponse, error) { request := modules.LnClaimPubkeyReceiveRequest{PrivateKey: privateKey} - resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive", request, *federationId) + resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive", request, federationId) if err != nil { return nil, err } @@ -470,7 +519,7 @@ func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) func (ln *LnModule) ClaimPubkeyReceiveTweaked(privateKey string, tweaks []uint64, federationId *string) (*types.InfoResponse, error) { request := modules.LnClaimPubkeyTweakedRequest{PrivateKey: privateKey, Tweaks: tweaks} - resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive-tweaked", request, *federationId) + resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive-tweaked", request, federationId) if err != nil { return nil, err } @@ -484,7 +533,7 @@ func (ln *LnModule) ClaimPubkeyReceiveTweaked(privateKey string, tweaks []uint64 func (ln *LnModule) AwaitInvoice(operationId string, federationId *string) (*types.InfoResponse, error) { request := modules.LnAwaitInvoiceRequest{OperationId: operationId} - resp, err := ln.Client.postWithFederationId("/ln/await-invoice", request, *federationId) + resp, err := ln.Client.postWithFederationId("/ln/await-invoice", request, federationId) if err != nil { return nil, err } @@ -503,7 +552,7 @@ func (ln *LnModule) Pay(paymentInfo string, amountMsat *uint64, lnurlComment *st LnurlComment: lnurlComment, } fmt.Println("request: ", request) - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/pay", request, *gatewayId, *federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/pay", request, gatewayId, federationId) if err != nil { return nil, err } diff --git a/wrappers/fedimint-go/pkg/fedimint/types/common.go b/wrappers/fedimint-go/pkg/fedimint/types/common.go index 3ae057f..2220db6 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/common.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/common.go @@ -1,5 +1,7 @@ package types +import "encoding/json" + type Tiered map[int]interface{} type TieredSummary struct { @@ -20,7 +22,21 @@ type BackupRequest struct { } type ListOperationsRequest struct { - Limit int `json:"limit"` + Limit uint16 `json:"limit"` +} + +// OperationOutput mirrors the Rust OperationOutput struct for JSON unmarshalling +type OperationOutput struct { + ID string `json:"id"` + CreationTime string `json:"creationTime"` + OperationKind string `json:"operationKind"` + OperationMeta json.RawMessage `json:"operationMeta"` // Use json.RawMessage for arbitrary JSON + Outcome *json.RawMessage `json:"outcome,omitempty"` // Pointer to handle optional field +} + +// ListOperationsResponse represents the JSON response structure from the listOperations endpoint +type ListOperationsResponse struct { + Operations []OperationOutput `json:"operations"` } type FederationIdsResponse struct { @@ -37,12 +53,8 @@ type JoinResponse struct { FederationIds []string `json:"federationIds"` } -type OperationOutput struct { - ID string `json:"id"` - CreationTime string `json:"creation_time"` - OperationKind string `json:"operation_kind"` - OperationMeta interface{} `json:"operation_meta"` - Outcome interface{} `json:"outcome,omitempty"` +type DiscoverVersionRequest struct { + Threshold uint16 `json:"threshold"` } type FedimintResponse map[string]interface{} diff --git a/wrappers/fedimint-ts/FedimintClient.ts b/wrappers/fedimint-ts/FedimintClient.ts index 540ed73..ee8f3a1 100644 --- a/wrappers/fedimint-ts/FedimintClient.ts +++ b/wrappers/fedimint-ts/FedimintClient.ts @@ -188,6 +188,8 @@ class FedimintClient { * @param body - The body of the request. */ private async post(endpoint: string, body: any): FedimintResponse { + console.log("body: ", body); + console.log("endpoint: ", this.baseUrl + endpoint); const res = await fetch(`${this.baseUrl}${endpoint}`, { method: "POST", headers: { @@ -197,6 +199,8 @@ class FedimintClient { body: JSON.stringify(body), }); + console.log("res: ", res); + if (!res.ok) { throw new Error( `POST request failed. Status: ${res.status}, Body: ${await res.text()}` diff --git a/wrappers/fedimint-ts/test.ts b/wrappers/fedimint-ts/test.ts index 9ae021f..7b4acc7 100644 --- a/wrappers/fedimint-ts/test.ts +++ b/wrappers/fedimint-ts/test.ts @@ -36,12 +36,16 @@ const newKeyPair = (): KeyPair => { }; async function buildTestClient() { - const baseUrl = process.env.BASE_URL || "http://127.0.0.1:3333"; - const password = process.env.PASSWORD || "password"; + const baseUrl = process.env.FEDIMINT_CLIENTD_BASE_URL || "127.0.0.1:3333"; + const password = process.env.FEDIMINT_CLIENTD_PASSWORD || "password"; + const activeFederationId = + process.env.FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID || + "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3"; const builder = new FedimintClientBuilder(); - builder.setBaseUrl(baseUrl).setPassword(password).setActiveFederationId( - "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" // Fedi Alpha Mutinynet - ); + builder + .setBaseUrl(baseUrl) + .setPassword(password) + .setActiveFederationId(activeFederationId); const client = await builder.build();