Skip to content

altered syntax to work with postgres#365

Closed
trbouma wants to merge 2 commits into
cashubtc:mainfrom
trbouma:postgres_compat_latest
Closed

altered syntax to work with postgres#365
trbouma wants to merge 2 commits into
cashubtc:mainfrom
trbouma:postgres_compat_latest

Conversation

@trbouma
Copy link
Copy Markdown
Contributor

@trbouma trbouma commented Nov 16, 2023

I got the following error when attempting to connect to postgres. The error has to do with a syntax variation of where AS should be placed. I fixed by moving the AS clause. It now works with postgres and I tested with SQLite

2023-11-16 14:26:06.96 | ERROR | psycopg2.errors.SyntaxError: subquery in FROM must have an alias
LINE 3:             SELECT COALESCE(SUM(s), 0) AS balance FROM (
                                                               ^
HINT:  For example, FROM (SELECT ...) [AS] foo.


The above exception was the direct cause of the following exception:

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.SyntaxError) subquery in FROM must have an alias
LINE 3:             SELECT COALESCE(SUM(s), 0) AS balance FROM (
                                                               ^
HINT:  For example, FROM (SELECT ...) [AS] foo.

[SQL: 
            CREATE VIEW balance_issued AS
            SELECT COALESCE(SUM(s), 0) AS balance FROM (
                SELECT SUM(amount) AS s
                FROM promises
                WHERE amount > 0
            );
        ]
(Background on this error at: http://sqlalche.me/e/13/f405)

2023-11-16 14:26:06.96 | ERROR | Application startup failed. Exiting.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fa5193c) 66.31% compared to head (f091faf) 66.00%.

❗ Current head f091faf differs from pull request most recent head ff1824d. Consider uploading reports for the commit ff1824d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #365      +/-   ##
==========================================
- Coverage   66.31%   66.00%   -0.31%     
==========================================
  Files          68       68              
  Lines        5219     5160      -59     
==========================================
- Hits         3461     3406      -55     
+ Misses       1758     1754       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@callebtc callebtc closed this Feb 2, 2024
@ye0man ye0man added this to nutshell Jan 21, 2026
@github-project-automation github-project-automation Bot moved this to Done in nutshell Jan 21, 2026
jooray added a commit to jooray/nutshell that referenced this pull request May 10, 2026
Aligns the mint's wire format with the unmerged onchain payment-method
NUT (PR cashubtc#365) so wallets implementing it can talk to our mint without
zcash-specific glue.

Method rename:
- backend now registered as Method("onchain") instead of Method("zcash");
  the (onchain, zec) method-unit pair signals native Zcash chain.
- mint info MintMethodSetting/MeltMethodSetting branch keyed on
  method.name == "onchain".
- All internal MINT_ZCASH_* settings keep their names (they configure
  the zwalletd backend; only the spec-facing method changes).

Router:
- router_zcash.py removed; replaced with router_onchain.py serving
  /v1/{mint,melt}/{quote,}/onchain endpoints.
- Mint quote bypasses ledger.mint_quote() so the request can be
  amount-less per NUT-XX. We allocate a deposit address with amount=0
  internally; the running deposit total is polled from the backend on
  each GET /v1/mint/quote/onchain/{quote} and persisted as
  MintQuote.amount, surfaced as `amount_paid`.
- Mint quote response uses NUT-XX shape: no `state` field; emits
  `amount_paid` and `amount_issued` (derived from the underlying
  state machine: amount_issued == amount on ISSUED, amount_paid == amount
  on PAID/PENDING/ISSUED, both zero on UNPAID).
- Mint quote `pubkey` is REQUIRED (Pydantic enforces).
- Melt quote response uses NUT-XX shape: `fee_options[]` array (single
  entry for Zcash's near-flat fee market), `selected_estimated_blocks`
  (echoed from the wallet's melt request), `outpoint` (txid for both
  transparent and shielded — see ZCASH-CDK-COMPATIBILITY.md §6.3 for
  why we don't surface vout).
- Melt request requires `estimated_blocks`, validated against the
  quote's fee_options.

Models:
- New PostMintQuoteOnchainRequest/Response, PostMeltQuoteOnchainRequest/
  Response, PostMeltOnchainRequest, OnchainFeeOption matching XX.md
  on branch thesimplekid/onchain (commit d76e7e5, last ACK 2026-05-06).

Backend:
- ZcashBackend.get_deposit_total(checking_id) helper exposes
  total_confirmed zatoshi for the onchain mint quote accounting.

Tests:
- All 25 backend tests in test_mint_lightning_zcash.py updated to the
  onchain method name and pass green.

Deviations from NUT-XX still in place (tracked in
ZCASH-CDK-COMPATIBILITY.md §6.5):
- one mint per quote (cashu ledger marks the quote ISSUED on first mint)
- one deposit per quote in practice (first deposit is captured as the
  full amount; later deposits to the same address bump amount_paid but
  cannot be minted without lifting the single-mint restriction)
- `change` not yet removed from the wider model (NUT-XX forbids it; the
  decision is still under spec review as of 2026-05-06)
jooray added a commit to jooray/nutshell that referenced this pull request May 10, 2026
Aligns the mint's wire format with the unmerged onchain payment-method
NUT (PR cashubtc#365) so wallets implementing it can talk to our mint without
zcash-specific glue.

Method rename:
- backend now registered as Method("onchain") instead of Method("zcash");
  the (onchain, zec) method-unit pair signals native Zcash chain.
- mint info MintMethodSetting/MeltMethodSetting branch keyed on
  method.name == "onchain".
- All internal MINT_ZCASH_* settings keep their names (they configure
  the zwalletd backend; only the spec-facing method changes).

Router:
- router_zcash.py removed; replaced with router_onchain.py serving
  /v1/{mint,melt}/{quote,}/onchain endpoints.
- Mint quote bypasses ledger.mint_quote() so the request can be
  amount-less per NUT-XX. We allocate a deposit address with amount=0
  internally; the running deposit total is polled from the backend on
  each GET /v1/mint/quote/onchain/{quote} and persisted as
  MintQuote.amount, surfaced as amount_paid.
- Mint quote response uses NUT-XX shape: no state field; emits
  amount_paid and amount_issued (derived from the underlying state
  machine: amount_issued == amount on ISSUED, amount_paid == amount
  on PAID/PENDING/ISSUED, both zero on UNPAID).
- Mint quote pubkey is REQUIRED (Pydantic enforces).
- Melt quote response uses NUT-XX shape: fee_options array (single
  entry for Zcash near-flat fee market), selected_estimated_blocks
  (echoed from the wallet melt request), outpoint (txid for both
  transparent and shielded; we do not surface vout).
- Melt request requires estimated_blocks, validated against the
  quote fee_options.

Models:
- New PostMintQuoteOnchainRequest/Response, PostMeltQuoteOnchainRequest/
  Response, PostMeltOnchainRequest, OnchainFeeOption matching XX.md
  on branch thesimplekid/onchain (commit d76e7e5, last ACK 2026-05-06).

Backend:
- ZcashBackend.get_deposit_total(checking_id) helper exposes
  total_confirmed zatoshi for the onchain mint quote accounting.

Tests:
- All 25 backend tests in test_mint_lightning_zcash.py updated to the
  onchain method name and pass green.

Deviations from NUT-XX still in place (tracked in
ZCASH-CDK-COMPATIBILITY.md §6.5):
- one mint per quote (cashu ledger marks the quote ISSUED on first mint)
- one deposit per quote in practice (first deposit is captured as the
  full amount; later deposits to the same address bump amount_paid but
  cannot be minted without lifting the single-mint restriction)
- change not yet removed from the wider model (NUT-XX forbids it; the
  decision is still under spec review as of 2026-05-06)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants