diff --git a/.gitignore b/.gitignore index 24ef0f2..cd3d02e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ fm_client_db .vscode .DS_Store fm_db + diff --git a/Cargo.lock b/Cargo.lock index 6049a01..b70f423 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1653,6 +1653,25 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", + "indexmap 2.2.5", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51ee2dd2e4f378392eeff5d51618cd9a63166a2513846bbc55f21cfacd9199d4" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.1.0", "indexmap 2.2.6", "slab", "tokio", @@ -2593,6 +2612,7 @@ checksum = "900d57987be3f2aeb70d385fff9b27fb74c5723cc9a52d904d4f9c807a0667bf" dependencies = [ "futures-core", "futures-sink", + "indexmap 2.2.5", "js-sys", "once_cell", "pin-project-lite", diff --git a/flake.lock b/flake.lock index 112303e..f406432 100644 --- a/flake.lock +++ b/flake.lock @@ -72,6 +72,7 @@ "fenix": { "inputs": { "nixpkgs": [ + "flakebox", "nixpkgs" ], "rust-analyzer-src": "rust-analyzer-src" diff --git a/flake.nix b/flake.nix index 8eea7c4..ff1a76b 100644 --- a/flake.nix +++ b/flake.nix @@ -96,6 +96,7 @@ export RUSTDOCFLAGS="--cfg tokio_unstable" export RUST_LOG="info" ''; + }; }); } diff --git a/wrappers/fedimint-go/.gitignore b/wrappers/fedimint-go/.gitignore index 4c49bd7..e58e5a2 100644 --- a/wrappers/fedimint-go/.gitignore +++ b/wrappers/fedimint-go/.gitignore @@ -1 +1,2 @@ .env +.idea diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index cfd198c..4a06b50 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -126,13 +126,13 @@ func main() { jsonBytes, err = json.Marshal(infoDataResponse) if err != nil { - fmt.Println("Error marshaling JSON(discover-version):", err) + fmt.Println("Error marshaling JSON(info):", err) return } var infoResponseData interface{} err = json.Unmarshal(jsonBytes, &infoResponseData) if err != nil { - fmt.Println("Error unmarshalling JSON(discover-version):", err) + fmt.Println("Error unmarshalling JSON(info):", err) return } @@ -168,7 +168,7 @@ func main() { logMethod("/v2/admin/list-operations") listOperationsData, err := fc.ListOperations(10, nil) if err != nil { - fmt.Println("Error calling JOIN: ", err) + fmt.Println("Error calling LIST OPERATIONS: ", err) return } @@ -214,7 +214,7 @@ func main() { // `/v2/ln/invoice` logMethod("/v2/ln/invoice") - invoiceData, err := fc.Ln.CreateInvoice(10000, "test", nil, nil, nil) + invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, fc.GetActiveGatewayId(), nil) if err != nil { fmt.Println("Error calling INVOICE: ", err) return @@ -236,6 +236,9 @@ func main() { // `/v2/ln/pay` logMethod("/v2/ln/pay") + if invoiceData == nil { + fmt.Println("invoice data is empty") + } payData, err := fc.Ln.Pay(invoiceData.Invoice, fc.GetActiveGatewayId(), nil, nil, nil) if err != nil { fmt.Println("Error calling PAY: ", err) @@ -258,6 +261,9 @@ func main() { // /v2/ln/await-invoice logMethod("/v2/ln/await-invoice") + if invoiceData == nil { + fmt.Println("invoice data is empty") + } awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, fc.GetActiveGatewayId(), nil) if err != nil { fmt.Println("Error calling AWAIT_INVOICE: ", err) @@ -305,7 +311,7 @@ func main() { // `/v1/ln/claim-external-pubkey-tweaked` logMethod("/v1/ln/claim-external-pubkey-tweaked") - claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(keyPair.PrivateKey, []uint64{1}, fc.GetActiveFederationId(), fc.GetActiveFederationId()) + claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(keyPair.PrivateKey, []uint64{1}, fc.GetActiveGatewayId(), fc.GetActiveFederationId()) if err != nil { fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) return @@ -353,6 +359,10 @@ func main() { // `/v2/mint/decode-notes` logMethod("/v2/mint/decode-notes") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } decodedData, err := fc.Mint.DecodeNotes(mintData.Notes) if err != nil { fmt.Println("Error calling DECODE_NOTES: ", err) @@ -375,6 +385,10 @@ func main() { // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes") + if decodedData == nil { + fmt.Println("decodedData is nil.") + return + } encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson) if err != nil { fmt.Println("Error calling DECODE_NOTES: ", err) @@ -397,6 +411,11 @@ func main() { // `/v2/mint/validate` logMethod("/v2/mint/validate") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } + validateData, err := fc.Mint.Validate(mintData.Notes, nil) if err != nil { fmt.Println("Error calling VALIDATE: ", err) @@ -419,6 +438,11 @@ func main() { // `/v2/mint/reissue` logMethod("/v2/mint/reissue") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } + reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) if err != nil { fmt.Println("Error calling REISSUE: ", err) @@ -441,6 +465,11 @@ func main() { // `/v2/mint/split` logMethod("/v2/mint/split") + if mintData == nil { + fmt.Println("mintData is nil.") + return + } + splitData, err := fc.Mint.Split(mintData.Notes) if err != nil { fmt.Println("Error calling SPLIT: ", err) @@ -464,6 +493,10 @@ func main() { // `/v2/mint/combine` logMethod("/v2/mint/combine") notesVec := func() []string { + if splitData == nil || splitData.Notes == nil { + fmt.Println("splitData or splitData.Notes is nil") + return nil + } result := make([]string, 0, len(splitData.Notes)) for _, value := range splitData.Notes { result = append(result, value) @@ -478,13 +511,13 @@ func main() { jsonBytes, err = json.Marshal(combineData) if err != nil { - fmt.Println("Error marshaling JSON(split):", err) + fmt.Println("Error marshaling JSON(combine-data):", err) return } var combineResponseData interface{} err = json.Unmarshal(jsonBytes, &combineResponseData) if err != nil { - fmt.Println("Error unmarshalling JSON(split):", err) + fmt.Println("Error unmarshalling JSON(combine-data):", err) return } diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index a4ce78c..0c0e9f4 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -119,6 +119,7 @@ func (fc *FedimintClient) post(endpoint string, body interface{}) ([]byte, error return fc.fetchWithAuth(endpoint, "POST", jsonBody) } + // postWithFederationId takes any request object, marshals it to JSON, optionally adds a federationId, and makes a POST request. func (fc *FedimintClient) postWithFederationId(endpoint string, requestBody interface{}, federationId *string) ([]byte, error) { // Initialize an empty map for the request body. @@ -143,9 +144,13 @@ func (fc *FedimintClient) postWithFederationId(endpoint string, requestBody inte // Determine the effective federationId to use effectiveFederationId := fc.ActiveFederationId fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) + if federationId != nil { - effectiveFederationId = *federationId + bodyMap["federationId"] = *federationId + } else { + bodyMap["federationId"] = fc.ActiveFederationId } + fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) // Add federationId to the map, which is now guaranteed to be initialized. @@ -157,6 +162,7 @@ func (fc *FedimintClient) postWithFederationId(endpoint string, requestBody inte return nil, fmt.Errorf("failed to marshal modified request map: %w", err) } + fmt.Printf("modifiedRequestJSON: %s\n", modifiedRequestJSON) // Proceed to make the POST request with the modified JSON body. @@ -313,7 +319,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("/wallet/deposit-address", request, federationId) if err != nil { return nil, err } @@ -327,7 +333,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("/wallet/await-deposit", request, federationId) if err != nil { return nil, err } @@ -341,7 +347,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("/wallet/withdraw", request, federationId) if err != nil { return nil, err } @@ -541,6 +547,7 @@ func (ln *LnModule) ClaimPubkeyReceive(privateKey string, gatewayId string, fede return &infoResp, nil } + func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, gatewayId string, federationId string) (*types.InfoResponse, error) { request := modules.LnClaimPubkeyTweakedRequest{PrivateKey: privateKey, Tweaks: tweaks} resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/claim-external-receive-tweaked", request, &gatewayId, &federationId)