diff --git a/.gitignore b/.gitignore index 4f7664f..cd3d02e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ fm_client_db .cargo .vscode .DS_Store -fm_db \ No newline at end of file +fm_db + diff --git a/fedimint-clientd/src/main.rs b/fedimint-clientd/src/main.rs index 73d37c0..024c4b3 100644 --- a/fedimint-clientd/src/main.rs +++ b/fedimint-clientd/src/main.rs @@ -254,7 +254,7 @@ fn fedimint_v2_rest() -> Router { post(fedimint::ln::list_gateways::handle_rest), ); - let wallet_router = Router::new() + let onchain_router = Router::new() .route( "/deposit-address", post(fedimint::onchain::deposit_address::handle_rest), @@ -291,7 +291,7 @@ fn fedimint_v2_rest() -> Router { .nest("/admin", admin_router) .nest("/mint", mint_router) .nest("/ln", ln_router) - .nest("/wallet", wallet_router) + .nest("/onchain", onchain_router) } /// Implements Cashu V1 API Routes: diff --git a/flake.lock b/flake.lock index 1577051..f406432 100644 --- a/flake.lock +++ b/flake.lock @@ -78,11 +78,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1712730246, - "narHash": "sha256-iB8bFj+07RHpmt+XuGGvYQk2Iwm12u6+DklGq/+Tg5s=", + "lastModified": 1712903033, + "narHash": "sha256-KcvsEm0h1mIwBHFAzWFBjGihnbf2fxpAaXOdVbUfAI4=", "owner": "nix-community", "repo": "fenix", - "rev": "d402ae4a5e5676722290470f61a5e8e3155b5487", + "rev": "c739f83545e625227f4d0af7fe2a71e69931fa4c", "type": "github" }, "original": { @@ -96,11 +96,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -135,11 +135,11 @@ ] }, "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -178,11 +178,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710695816, - "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "lastModified": 1712867921, + "narHash": "sha256-edTFV4KldkCMdViC/rmpJa7oLIU8SE/S35lh/ukC7bg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920", + "rev": "51651a540816273b67bc4dedea2d37d116c5f7fe", "type": "github" }, "original": { @@ -203,11 +203,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1699552432, - "narHash": "sha256-MxxTH/X5vnqLWEwokxdA5AkX/NpXOrHMn/95QwOdA4o=", + "lastModified": 1712818880, + "narHash": "sha256-VDxsvgj/bNypHq48tQWtc3VRbWvzlFjzKf9ZZIVO10Y=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "a5feb4f05f09adca661c869b1bf2324898cbaa43", + "rev": "657b33b0cb9bd49085202e91ad5b4676532c9140", "type": "github" }, "original": { diff --git a/misc/git-hooks/pre-commit b/misc/git-hooks/pre-commit index 7959e97..d21df26 100755 --- a/misc/git-hooks/pre-commit +++ b/misc/git-hooks/pre-commit @@ -9,13 +9,13 @@ set -e # Revert `git stash` on exit function revert_git_stash { - >&2 echo "Unstashing uncommitted changes..." + echo >&2 "Unstashing uncommitted changes..." git stash pop -q } # Stash pending changes and revert them when script ends if [ -z "${NO_STASH:-}" ] && [ $is_unclean -ne 0 ]; then - >&2 echo "Stashing uncommitted changes..." + echo >&2 "Stashing uncommitted changes..." GIT_LITERAL_PATHSPECS=0 git stash -q --keep-index trap revert_git_stash EXIT fi @@ -25,146 +25,145 @@ FLAKEBOX_GIT_LS="$(git ls-files)" export FLAKEBOX_GIT_LS_TEXT FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico|gif)\$")" - function check_nothing() { true } export -f check_nothing function check_cargo_fmt() { - set -euo pipefail + set -euo pipefail - flakebox-in-each-cargo-workspace cargo fmt --all --check + flakebox-in-each-cargo-workspace cargo fmt --all --check } export -f check_cargo_fmt function check_cargo_lock() { - set -euo pipefail + set -euo pipefail - # https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5 - flakebox-in-each-cargo-workspace cargo update --workspace --locked + # https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5 + flakebox-in-each-cargo-workspace cargo update --workspace --locked } export -f check_cargo_lock function check_leftover_dbg() { - set -euo pipefail - - errors="" - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do - if grep 'dbg!(' "$path" > /dev/null; then - >&2 echo "$path contains dbg! macro" - errors="true" - fi - done - - if [ -n "$errors" ]; then - >&2 echo "Fix the problems above or use --no-verify" 1>&2 - return 1 + set -euo pipefail + + errors="" + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do + if grep 'dbg!(' "$path" >/dev/null; then + echo >&2 "$path contains dbg! macro" + errors="true" fi + done + + if [ -n "$errors" ]; then + echo >&2 "Fix the problems above or use --no-verify" 1>&2 + return 1 + fi } export -f check_leftover_dbg function check_semgrep() { - set -euo pipefail + set -euo pipefail - # semgrep is not available on MacOS - if ! command -v semgrep > /dev/null ; then - >&2 echo "Skipping semgrep check: not available" - return 0 - fi + # semgrep is not available on MacOS + if ! command -v semgrep >/dev/null; then + echo >&2 "Skipping semgrep check: not available" + return 0 + fi - if [ ! -f .config/semgrep.yaml ] ; then - >&2 echo "Skipping semgrep check: .config/semgrep.yaml doesn't exist" - return 0 - fi + if [ ! -f .config/semgrep.yaml ]; then + echo >&2 "Skipping semgrep check: .config/semgrep.yaml doesn't exist" + return 0 + fi - if [ ! -s .config/semgrep.yaml ] ; then - >&2 echo "Skipping semgrep check: .config/semgrep.yaml empty" - return 0 - fi + if [ ! -s .config/semgrep.yaml ]; then + echo >&2 "Skipping semgrep check: .config/semgrep.yaml empty" + return 0 + fi - env SEMGREP_ENABLE_VERSION_CHECK=0 \ - semgrep -q --error --no-rewrite-rule-ids --config .config/semgrep.yaml + env SEMGREP_ENABLE_VERSION_CHECK=0 \ + semgrep -q --error --no-rewrite-rule-ids --config .config/semgrep.yaml } export -f check_semgrep function check_shellcheck() { - set -euo pipefail + set -euo pipefail - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do - shellcheck --severity=warning "$path" - done + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do + shellcheck --severity=warning "$path" + done } export -f check_shellcheck function check_trailing_newline() { - set -euo pipefail - - errors="" - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do - - # extra branches for clarity - if [ ! -s "$path" ]; then - # echo "$path is empty" - true - elif [ -z "$(tail -c 1 < "$path")" ]; then - # echo "$path ends with a newline or with a null byte" - true - else - >&2 echo "$path doesn't end with a newline" 1>&2 - errors="true" - fi - done - - if [ -n "$errors" ]; then - >&2 echo "Fix the problems above or use --no-verify" 1>&2 - return 1 + set -euo pipefail + + errors="" + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do + + # extra branches for clarity + if [ ! -s "$path" ]; then + # echo "$path is empty" + true + elif [ -z "$(tail -c 1 <"$path")" ]; then + # echo "$path ends with a newline or with a null byte" + true + else + echo >&2 "$path doesn't end with a newline" 1>&2 + errors="true" fi + done + + if [ -n "$errors" ]; then + echo >&2 "Fix the problems above or use --no-verify" 1>&2 + return 1 + fi } export -f check_trailing_newline function check_trailing_whitespace() { - set -euo pipefail - - rev="HEAD" - if ! git rev-parse -q 1>/dev/null HEAD 2>/dev/null ; then - >&2 echo "Warning: no commits yet, checking against --root" - rev="--root" - fi - if ! git diff --check $rev ; then - >&2 echo "Trailing whitespace detected. Please remove them before committing." - return 1 - fi + set -euo pipefail + + rev="HEAD" + if ! git rev-parse -q HEAD 1>/dev/null 2>/dev/null; then + echo >&2 "Warning: no commits yet, checking against --root" + rev="--root" + fi + if ! git diff --check $rev; then + echo >&2 "Trailing whitespace detected. Please remove them before committing." + return 1 + fi } export -f check_trailing_whitespace function check_typos() { - set -euo pipefail + set -euo pipefail - if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude ; then - >&2 echo "Typos found: Valid new words can be added to '.typos.toml'" - return 1 - fi + if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude; then + echo >&2 "Typos found: Valid new words can be added to '.typos.toml'" + return 1 + fi } export -f check_typos parallel \ --nonotice \ -::: \ - check_cargo_fmt \ - check_cargo_lock \ - check_leftover_dbg \ - check_semgrep \ - check_shellcheck \ - check_trailing_newline \ - check_trailing_whitespace \ - check_typos \ + ::: \ + check_cargo_fmt \ + check_cargo_lock \ + check_leftover_dbg \ + check_semgrep \ + check_shellcheck \ + check_trailing_newline \ + check_trailing_whitespace \ + check_typos \ check_nothing diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 2574729..4a06b50 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -66,6 +66,7 @@ func buildTestClient() *fedimint.FedimintClient { func main() { fc := buildTestClient() + fc.UseDefaultGateway() keyPair := newKeyPair() fmt.Printf("Generated Key Pair: ") fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey) @@ -125,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 } @@ -167,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 } @@ -191,7 +192,7 @@ func main() { // `/v2/ln/list-gateways` logMethod("/v2/ln/list-gateways") - gatewayList, err := fc.Ln.ListGateways(&fc.ActiveFederationId) + gatewayList, err := fc.Ln.ListGateways(nil) if err != nil { fmt.Println("Error calling LIST_GATEWAYS: ", err) return @@ -213,9 +214,7 @@ func main() { // `/v2/ln/invoice` logMethod("/v2/ln/invoice") - - gatewayId := "035f2f7912e0f570841d5c0d8976a40af0dcca5609198436f596e78d2c851ee58a" - invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, &gatewayId, nil) + invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, fc.GetActiveGatewayId(), nil) if err != nil { fmt.Println("Error calling INVOICE: ", err) return @@ -237,11 +236,10 @@ func main() { // `/v2/ln/pay` logMethod("/v2/ln/pay") - comment := "Test for services" - if invoiceData == nil { + if invoiceData == nil { fmt.Println("invoice data is empty") } - payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, &comment, &gatewayId, nil) + payData, err := fc.Ln.Pay(invoiceData.Invoice, fc.GetActiveGatewayId(), nil, nil, nil) if err != nil { fmt.Println("Error calling PAY: ", err) return @@ -263,10 +261,10 @@ func main() { // /v2/ln/await-invoice logMethod("/v2/ln/await-invoice") - if invoiceData == nil { + if invoiceData == nil { fmt.Println("invoice data is empty") } - awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) + awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, fc.GetActiveGatewayId(), nil) if err != nil { fmt.Println("Error calling AWAIT_INVOICE: ", err) return @@ -288,7 +286,7 @@ func main() { // `/v1/ln/invoice-external-pubkey-tweaked` logMethod("/v1/ln/invoice-external-pubkey-tweaked") - tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, &gatewayId, nil) + tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", fc.GetActiveGatewayId(), nil, nil) if err != nil { fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) return @@ -308,12 +306,12 @@ func main() { logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoiceResponseData) // pay the invoice - _, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil) + _, _ = fc.Ln.Pay(tweakInvoice.Invoice, fc.GetActiveGatewayId(), nil, nil, nil) fmt.Println("Paid locked invoice!") // `/v1/ln/claim-external-pubkey-tweaked` logMethod("/v1/ln/claim-external-pubkey-tweaked") - claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(keyPair.PrivateKey, []uint64{1}, 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 @@ -361,7 +359,7 @@ func main() { // `/v2/mint/decode-notes` logMethod("/v2/mint/decode-notes") - if mintData == nil { + if mintData == nil { fmt.Println("mintData is nil.") return } @@ -387,13 +385,13 @@ func main() { // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes") - if decodedData == nil { + if decodedData == nil { fmt.Println("decodedData is nil.") return } encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson) if err != nil { - fmt.Println("Error calling ENCODE_NOTES: ", err) + fmt.Println("Error calling DECODE_NOTES: ", err) return } @@ -417,6 +415,7 @@ func main() { fmt.Println("mintData is nil.") return } + validateData, err := fc.Mint.Validate(mintData.Notes, nil) if err != nil { fmt.Println("Error calling VALIDATE: ", err) @@ -443,6 +442,7 @@ func main() { fmt.Println("mintData is nil.") return } + reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) if err != nil { fmt.Println("Error calling REISSUE: ", err) @@ -469,6 +469,7 @@ func main() { fmt.Println("mintData is nil.") return } + splitData, err := fc.Mint.Split(mintData.Notes) if err != nil { fmt.Println("Error calling SPLIT: ", err) @@ -527,7 +528,7 @@ func main() { ///////////////////// // `/v2/onchain/deposit-address` - logMethod("/v2/wallet/deposit-address") + logMethod("/v2/onchain/deposit-address") addr, err := fc.Onchain.CreateDepositAddress(1000, nil) if err != nil { fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) @@ -549,7 +550,7 @@ func main() { logInputAndOutput(1000, addrResponseData) // `/v2/onchain/withdraw` - logMethod("/v2/wallet/withdraw") + logMethod("/v2/onchain/withdraw") withdrawData, err := fc.Onchain.Withdraw(addr.Address, 1000, nil) if err != nil { fmt.Println("Error calling WITHDRAW: ", err) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 9b97c2a..0c0e9f4 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -91,7 +91,7 @@ func (fc *FedimintClient) SetActiveGatewayId(gatewayId string) { func (fc *FedimintClient) UseDefaultGateway() error { // hits list_gateways and sets activeGatewayId to the first gateway - gateways, err := fc.Ln.ListGateways(&fc.ActiveFederationId) + gateways, err := fc.Ln.ListGateways(nil) if err != nil { return fmt.Errorf("error getting gateways: %w", err) } @@ -107,87 +107,116 @@ func (fc *FedimintClient) get(endpoint string) ([]byte, error) { return fc.fetchWithAuth(endpoint, "GET", nil) } +// Post performs a POST request with JSON body, handling JSON marshalling within. func (fc *FedimintClient) post(endpoint string, body interface{}) ([]byte, error) { jsonBody, err := json.Marshal(body) if err != nil { - return nil, err + return nil, fmt.Errorf("error marshaling request body: %w", err) } - fmt.Println("jsonBody: ", string(jsonBody)) + + fmt.Printf("jsonBody: %s\n", jsonBody) + // Assuming fetchWithAuth is correctly implemented. return fc.fetchWithAuth(endpoint, "POST", jsonBody) } -func (fc *FedimintClient) postWithFederationId(endpoint string, body interface{}, federationId *string) ([]byte, error) { - // Marshal the body to JSON - bodyJSON, err := json.Marshal(body) - if err != nil { - return nil, err - } - // Initialize and convert JSON to map for manipulation - var bodyMap = make(map[string]interface{}) // Initialize the map here - if err := json.Unmarshal(bodyJSON, &bodyMap); err != nil { - return nil, err - } +// 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. + requestMap := make(map[string]interface{}) - // If bodyMap is nil after unmarshalling, initialize it - if bodyMap == nil { - println("bodyMap is nil") - bodyMap = make(map[string]interface{}) + // If the requestBody is not nil and not empty, marshal and unmarshal it into the map. + if requestBody != nil { + requestJSON, err := json.Marshal(requestBody) + if err != nil { + return nil, fmt.Errorf("failed to marshal request body: %w", err) + } + + // Unmarshal the JSON into the map only if it's not empty to avoid overwriting the initialized map. + if string(requestJSON) != "{}" { + err = json.Unmarshal(requestJSON, &requestMap) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal request JSON into map: %w", err) + } + } } - // Set federationId in the body map + // Determine the effective federationId to use + effectiveFederationId := fc.ActiveFederationId + fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) + if federationId != nil { bodyMap["federationId"] = *federationId } else { bodyMap["federationId"] = fc.ActiveFederationId } - // Marshal the modified body back to JSON - modifiedBodyJSON, err := json.Marshal(bodyMap) + fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) + + // Add federationId to the map, which is now guaranteed to be initialized. + requestMap["federationId"] = effectiveFederationId + + // Marshal the request map back to JSON to use as the request body. + modifiedRequestJSON, err := json.Marshal(requestMap) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to marshal modified request map: %w", err) } - // Make the POST request with the modified body - return fc.fetchWithAuth(endpoint, "POST", modifiedBodyJSON) + + fmt.Printf("modifiedRequestJSON: %s\n", modifiedRequestJSON) + + // Proceed to make the POST request with the modified JSON body. + return fc.fetchWithAuth(endpoint, "POST", modifiedRequestJSON) } -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 +func (fc *FedimintClient) postWithGatewayIdAndFederationId(endpoint string, requestBody interface{}, gatewayId *string, federationId *string) ([]byte, error) { + // Initialize an empty map for the request body. + requestMap := make(map[string]interface{}) + + // If the requestBody is not nil and not empty, marshal and unmarshal it into the map. + if requestBody != nil { + requestJSON, err := json.Marshal(requestBody) + if err != nil { + return nil, fmt.Errorf("failed to marshal request body: %w", err) + } + + // Unmarshal the JSON into the map only if it's not empty to avoid overwriting the initialized map. + if string(requestJSON) != "{}" { + err = json.Unmarshal(requestJSON, &requestMap) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal request JSON into map: %w", err) + } + } } - var bodyMap = make(map[string]interface{}) - // Add federationId to the map + // Determine the effective federationId to use effectiveFederationId := fc.ActiveFederationId if federationId != nil { effectiveFederationId = *federationId } - bodyMap["federationId"] = effectiveFederationId - - // Unmarshal the JSON into a map to add federationId - err = json.Unmarshal(originalBodyJSON, &bodyMap) - if err != nil { - return nil, err - } + fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) + requestMap["federationId"] = effectiveFederationId - // Add gatewayId to the map + // Determine the effective gatewayId to use effectiveGatewayId := fc.ActiveGatewayId if gatewayId != nil { effectiveGatewayId = *gatewayId } - bodyMap["gatewayId"] = effectiveGatewayId + fmt.Printf("effectiveGatewayId: %s\n", effectiveGatewayId) - // Marshal the modified map back to JSON - modifiedBodyJSON, err := json.Marshal(bodyMap) + // Add gatewayId to the map, which is now guaranteed to be initialized. + requestMap["gatewayId"] = effectiveGatewayId + + // Marshal the request map back to JSON to use as the request body. + modifiedRequestJSON, err := json.Marshal(requestMap) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to marshal modified request map: %w", err) } - // Use the modified JSON as the body for the POST request - return fc.fetchWithAuth(endpoint, "POST", modifiedBodyJSON) + fmt.Printf("modifiedRequestJSON: %s\n", modifiedRequestJSON) + + // Proceed to make the POST request with the modified JSON body. + return fc.fetchWithAuth(endpoint, "POST", modifiedRequestJSON) } func (fc *FedimintClient) Info() (*types.InfoResponse, error) { @@ -281,10 +310,6 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us if setActiveFederationId { fc.SetActiveFederationId(response.ThisFederationId, useDefaultGateway) } - - if err != nil { - return response, err - } return response, nil } @@ -467,7 +492,7 @@ func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, expiryT return &invoiceResp, nil } -func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, description string, expiryTime *int, gatewayId *string, federationId *string) (*modules.LnInvoiceResponse, error) { +func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, description string, gatewayId string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { request := modules.LnInvoiceExternalPubkeyRequest{ AmountMsat: amountMsat, Description: description, @@ -475,7 +500,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 } @@ -487,7 +512,7 @@ func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, des return &invoiceResp, nil } -func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amountMsat uint64, description string, expiryTime *int, gatewayId *string, federationId *string) (*modules.LnInvoiceResponse, error) { +func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amountMsat uint64, description string, gatewayId string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { request := modules.LnInvoiceExternalPubkeyTweakedRequest{ AmountMsat: amountMsat, Description: description, @@ -496,7 +521,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 } @@ -508,9 +533,9 @@ func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amo return &invoiceResp, nil } -func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) (*types.InfoResponse, error) { +func (ln *LnModule) ClaimPubkeyReceive(privateKey string, gatewayId 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.postWithGatewayIdAndFederationId("/ln/claim-external-receive", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -522,9 +547,10 @@ func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) return &infoResp, nil } -func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, federationId string) (*types.InfoResponse, error) { + +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.postWithFederationId("/ln/claim-external-receive-tweaked", request, &federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/claim-external-receive-tweaked", request, &gatewayId, &federationId) if err != nil { return nil, err } @@ -536,9 +562,9 @@ func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, return &infoResp, nil } -func (ln *LnModule) AwaitInvoice(operationId string, federationId *string) (*types.InfoResponse, error) { +func (ln *LnModule) AwaitInvoice(operationId string, gatewayId 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.postWithGatewayIdAndFederationId("/ln/await-invoice", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -550,17 +576,20 @@ func (ln *LnModule) AwaitInvoice(operationId string, federationId *string) (*typ return &infoResp, nil } -func (ln *LnModule) Pay(paymentInfo string, amountMsat *uint64, lnurlComment *string, gatewayId *string, federationId *string) (*modules.LnPayResponse, error) { +func (ln *LnModule) Pay(paymentInfo string, gatewayId string, amountMsat *uint64, lnurlComment *string, federationId *string) (*modules.LnPayResponse, error) { request := modules.LnPayRequest{ PaymentInfo: paymentInfo, AmountMsat: amountMsat, 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 } + + fmt.Printf("Raw response body: %s\n", string(resp)) + var payResp modules.LnPayResponse err = json.Unmarshal(resp, &payResp) if err != nil { @@ -570,7 +599,7 @@ func (ln *LnModule) Pay(paymentInfo string, amountMsat *uint64, lnurlComment *st } func (ln *LnModule) ListGateways(federationId *string) ([]modules.Gateway, error) { - resp, err := ln.Client.postWithFederationId("/ln/list-gateways", nil, nil) + resp, err := ln.Client.postWithFederationId("/ln/list-gateways", nil, federationId) if err != nil { return nil, err } diff --git a/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go b/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go index e4fa3f7..1ecebda 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go @@ -45,11 +45,16 @@ type LnPayRequest struct { LnurlComment *string `json:"lnurlComment"` } +type PaymentTypeInfo struct { + Internal *string `json:"internal,omitempty"` + Lightning *string `json:"lightning,omitempty"` +} + type LnPayResponse struct { - OperationId string `json:"operationId"` - PaymentType string `json:"paymentType"` - ContractId string `json:"contractId"` - Fee int `json:"fee"` + OperationId string `json:"operationId"` + PaymentType PaymentTypeInfo `json:"paymentType"` + ContractId string `json:"contractId"` + Fee int `json:"fee"` } type AwaitLnPayRequest struct { @@ -59,13 +64,13 @@ type AwaitLnPayRequest struct { type GatewayInfo struct { API string `json:"api"` Fees GatewayFees `json:"fees"` - GatewayID string `json:"gatewayId"` - GatewayRedeemKey string `json:"gatewayRedeemKey"` - LightningAlias string `json:"lightningAlias"` - MintChannelID int `json:"mintChannelId"` - NodePubKey string `json:"nodePubKey"` - RouteHints []interface{} `json:"routeHints"` // Adjust the type according to the actual structure of route hints - SupportsPrivatePayments bool `json:"supportsPrivatePayments"` + GatewayID string `json:"gateway_id"` + GatewayRedeemKey string `json:"gateway_redeem_key"` + LightningAlias string `json:"lightning_alias"` + MintChannelID int `json:"mint_channel_id"` + NodePubKey string `json:"node_pub_key"` + RouteHints []interface{} `json:"route_hints"` // Consider defining a more specific type if possible + SupportsPrivatePayments bool `json:"supports_private_payments"` } type GatewayFees struct { @@ -79,15 +84,10 @@ type GatewayTTL struct { } type Gateway struct { - FederationID string `json:"federationId"` + FederationID string `json:"federation_id"` Info GatewayInfo `json:"info"` TTL GatewayTTL `json:"ttl"` Vetted bool `json:"vetted"` } -// string::> FederationId type ListGatewaysResponse map[string][]Gateway - -type SwitchGatewayRequest struct { - GatewayId string `json:"gatewayId"` -} diff --git a/wrappers/fedimint-py/AsyncFedimintClient.py b/wrappers/fedimint-py/AsyncFedimintClient.py index 95a26a8..bd08e22 100644 --- a/wrappers/fedimint-py/AsyncFedimintClient.py +++ b/wrappers/fedimint-py/AsyncFedimintClient.py @@ -380,7 +380,7 @@ def __init__(self, client): async def create_deposit_address(self, timeout: int, federation_id: str = None): request: OnchainDepositAddressRequest = {"timeout": timeout} return await self.client._post_with_federation_id( - "/wallet/deposit-address", request, federation_id + "/onchain/deposit-address", request, federation_id ) async def await_deposit( @@ -388,7 +388,7 @@ async def await_deposit( ) -> OnchainAwaitDepositResponse: request: OnchainAwaitDepositRequest = {"operationId": operation_id} return await self.client._post_with_federation_id( - "/wallet/await-deposit", request, federation_id + "/onchain/await-deposit", request, federation_id ) async def withdraw( @@ -402,5 +402,5 @@ async def withdraw( "amountSat": amount_sat, } return await self.client._post_with_federation_id( - "/wallet/withdraw", request, federationId + "/onchain/withdraw", request, federationId ) diff --git a/wrappers/fedimint-py/FedimintClient.py b/wrappers/fedimint-py/FedimintClient.py index ecd5810..07b4c57 100644 --- a/wrappers/fedimint-py/FedimintClient.py +++ b/wrappers/fedimint-py/FedimintClient.py @@ -70,6 +70,7 @@ def __init__( def get_active_federation_id(self): return self.active_federation_id + # *** def set_active_federation_id(self, federation_id: str): self.active_federation_id = federation_id @@ -162,9 +163,11 @@ def discover_version(self, threshold: int) -> DiscoverVersionResponse: def federation_ids(self): return self._get("/admin/federation-ids") + # *** def list_operations(self, request: ListOperationsRequest): return self._post_with_federation_id("/admin/list-operations", request) + # *** def join(self, invite_code: str, use_manual_secret: bool = False): return self._post( "/admin/join", @@ -342,7 +345,7 @@ def __init__(self, client): def create_deposit_address(self, timeout: int, federation_id: str = None): request: OnchainDepositAddressRequest = {"timeout": timeout} return self.client._post_with_federation_id( - "/wallet/deposit-address", request, federation_id + "/onchain/deposit-address", request, federation_id ) def await_deposit( @@ -350,7 +353,7 @@ def await_deposit( ) -> OnchainAwaitDepositResponse: request: OnchainAwaitDepositRequest = {"operationId": operation_id} return self.client._post_with_federation_id( - "/wallet/await-deposit", request, federation_id + "/onchain/await-deposit", request, federation_id ) def withdraw( @@ -364,5 +367,5 @@ def withdraw( "amountSat": amount_sat, } return self.client._post_with_federation_id( - "/wallet/withdraw", request, federation_id + "/onchain/withdraw", request, federation_id ) diff --git a/wrappers/fedimint-ts/FedimintClient.ts b/wrappers/fedimint-ts/FedimintClient.ts index da35cd3..fda8926 100644 --- a/wrappers/fedimint-ts/FedimintClient.ts +++ b/wrappers/fedimint-ts/FedimintClient.ts @@ -289,7 +289,6 @@ class FedimintClient { gatewayId: effectiveGatewayId, }); } catch (error) { - console.error("Error posting with federation and gateway id: ", error); throw error; } } @@ -559,7 +558,6 @@ class FedimintClient { const request: MintEncodeNotesRequest = { notesJsonStr: JSON.stringify(notesJson), }; - console.log("request: ", request); return await this.post( "/mint/encode-notes", @@ -677,7 +675,7 @@ class FedimintClient { const request: OnchainDepositAddressRequest = { timeout }; return await this.postWithFederationId( - "/wallet/deposit-address", + "/onchain/deposit-address", request, federationId ); @@ -696,7 +694,7 @@ class FedimintClient { const request: OnchainAwaitDepositRequest = { operationId }; return await this.postWithFederationId( - "/wallet/await-deposit", + "/onchain/await-deposit", request, federationId ); @@ -720,7 +718,7 @@ class FedimintClient { const request: OnchainWithdrawRequest = { address, amountSat }; return await this.postWithFederationId( - "/wallet/withdraw", + "/onchain/withdraw", request, federationId );