Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Balance Views Grouped By Keyset #652

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lollerfirst
Copy link
Contributor

@lollerfirst lollerfirst commented Oct 28, 2024

Issues:

Balance views new SQL:

CREATE VIEW {db.table_with_schema('balance_issued')} AS
SELECT id AS keyset, COALESCE(s, 0) AS balance FROM (
    SELECT id, SUM(amount) AS s
    FROM {db.table_with_schema('promises')}
    WHERE amount > 0
    GROUP BY id
);

CREATE VIEW {db.table_with_schema('balance_redeemed')} AS
SELECT id AS keyset, COALESCE(s, 0) AS balance FROM (
    SELECT id, SUM(amount) AS s
    FROM {db.table_with_schema('proofs_used')}
    WHERE amount > 0
    GROUP BY id
);

CREATE VIEW {db.table_with_schema('balance')} AS
SELECT keyset, s_issued - s_used AS balance FROM (
    SELECT bi.keyset AS keyset,
        bi.balance AS s_issued,
        COALESCE(bu.balance, 0) AS s_used
    FROM {db.table_with_schema('balance_issued')} bi
    LEFT OUTER JOIN {db.table_with_schema('balance_redeemed')} bu
    ON bi.keyset = bu.keyset
);

New migration m022_keyset_specific_balance_views takes care of deleting the previous views and replacing them with these.

Some minor relative changes to get_balance() functions.

@lollerfirst
Copy link
Contributor Author

# Max mint balance in satoshis
# MINT_MAX_BALANCE=1000000
# Max peg-in amount in satoshis
# MINT_MAX_PEG_IN=100000
# Max peg-out amount in satoshis
# MINT_MAX_PEG_OUT=100000
# Use to allow only peg-out to LN
# MINT_PEG_OUT_ONLY=FALSE

I think the scope of this PR should be limited to fixing the balance views. We can do the limits settings for different units in a follow-up. Sounds good?

@callebtc
Copy link
Collaborator

callebtc commented Nov 5, 2024

I think the scope of this PR should be limited to fixing the balance views.

agreed!

@lollerfirst lollerfirst marked this pull request as ready for review November 5, 2024 14:42
@callebtc
Copy link
Collaborator

callebtc commented Nov 5, 2024

Please rebase to main

@lollerfirst
Copy link
Contributor Author

re-based.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants