Commit Graph

187 Commits

Author SHA1 Message Date
lollerfirst
ed0d25dec7 [FIX] Wallet sort outputs before swapping (#648)
* sort proofs

* outputs-ordering

* mypy fix

* clean up

* test if output amounts are sorted

* clean up test

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2024-11-05 15:00:37 +01:00
callebtc
92627399a5 Wallet: store quotes (#657)
* wallet_quotes_wip

* fix quote in db

* fix subscription test

* clean up api

* fix api tests

* fix balance check
2024-11-01 13:27:27 +01:00
elnosh
21418a114a sort split in split_wallet_state (#653) 2024-11-01 10:22:12 +01:00
callebtc
09d007ec88 Refactor conditions and fix HTLC multisig (#643)
* refactor conditions and fix htlc multisig

* restore db/write.py

* safer check for P2PK secrets for SIG_ALL

* comment cleanup
2024-10-22 14:02:45 +02:00
callebtc
4490cc6fce Add get quote API to wallet + check proof states in batches (#637)
* add get quote api to wallet

* wrong string

* test before pushing

* fix tests for deprecated api only

* sigh
2024-10-08 18:12:10 +02:00
callebtc
7fdca3b1a1 Fix: ledger requires deprecated paid flags in db + wallet disable base64 keysets by default (#634)
* wallet: deprecate base64 keysets by default

* readd deprecated paid to melt quotes as well

* readd paid flag removed in #622 before
2024-10-04 15:32:36 +02:00
Pavol Rusnak
75ffa39807 chore: modernize f-string usage (#627) 2024-10-04 14:11:00 +02:00
callebtc
700320a8c4 Fix: wallet include fees in swap outputs for inputs of successive melt (#630)
* wallet: add fees to outputs for melt that requires a split

* add test that requires a swap

* verify test fails, will revert

* revert true

* hopefully fix the tests

* fix default fee selection

* cleanup and renamings

* cleanup coinselect function, estimate fees

* fix test

* add comments

* weird error
2024-10-03 09:50:23 +02:00
callebtc
d8d3037cc5 WIP: New melt flow (#622)
* `PaymentResult`

* ledger: rely on PaymentResult instead of paid flag. Double check for payments marked pending.

* `None` is `PENDING`

* make format

* reflected changes API tests where `PaymentStatus` is used + reflected changes in lnbits

* reflect changes in blink backend and tests

* fix lnbits get_payment_status

* remove paid flag

* fix mypy

* remove more paid flags

* fix strike mypy

* green

* shorten all state checks

* fix

* fix some tests

* gimme 

* fix............

* fix lnbits

* fix error

* lightning refactor

* add more regtest tests

* add tests for pending state and failure

* shorten checks

* use match case for startup check - and remember modified checking_id from pay_invoice

* fix strike pending return

* new tests?

* refactor startup routine into get_melt_quote

* test with purge

* refactor blink

* cleanup responses

* blink: return checking_id on failure

* fix lndgrpc try except

* add more testing for melt branches

* speed things up a bit

* remove comments

* remove comments

* block pending melt quotes

* remove comments

---------

Co-authored-by: lollerfirst <lollerfirst@gmail.com>
2024-09-24 14:55:35 +02:00
callebtc
637e4ba80c NUT-04: add description (#613)
* NUT-04: add description

* skip test for deprecated api

* fix for lndgrpc

* add test for cli

* add two random tests

* add max length to request model validator

* skip cli test with description for deprecated api

* add cli test for invoice command

* default value to None
2024-09-09 11:50:02 +02:00
callebtc
0287c02f97 sanitize mint URL before adding (#606) 2024-09-08 15:59:10 +02:00
callebtc
ef5aee92d6 NUT-06: add icon URL (#604)
* mint info icon

* Update cashu/core/models.py

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>

* Update cashu/mint/router.py

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>

* Update cashu/wallet/mint_info.py

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>

* fix setting

---------

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
2024-09-08 15:00:32 +02:00
callebtc
e14dc6d7ca strip URL (#605) 2024-07-29 17:27:59 +02:00
callebtc
125ce9e8db Remove unused coinselection (#597) 2024-07-24 07:17:54 +02:00
callebtc
3077ca4c7d Wallet: add CLI flag --force-swap flag and force swapping all inactive keysets (#580)
* Wallet: add flag --force-swap to send command

* Reame split to swap across codebase

* rename remaining splits to swap

* fix restore index with multiple keysets

* fix wallet api restore
2024-07-11 23:08:36 +02:00
callebtc
77697c52ee Fix loading b64 keysets and add option to set b64 inactive in WalletSettings (#579)
* Mint: fix loading b64 keysets and Wallet: option to set b64 inactive

* typo

* readd include fees flag (unused)

* fix test to respect new default False flag

* fix default flag for regtest
2024-07-11 15:25:16 +02:00
callebtc
26b94951fc Fix Tokenv4 handling of base64 keysets (#575)
* wip: handle tokenv4 if the keyset is base64

* wip

* Tokens now dataclasses

* Deserialize DLEQ from string

* add tokenv3/v4 base64 keyset ID tests

* fix cli
2024-07-10 14:12:03 +02:00
callebtc
6a0a370ba5 Mint: table locks (#566)
* clean up db

* db: table lock

* db.table_with_schema

* fix encrypt.py

* postgres nowait

* add timeout to lock

* melt quote state in db

* kinda working

* kinda working with postgres

* remove dispose

* getting there

* porperly clean up db for tests

* faster tests

* configure connection pooling

* try github with connection pool

* invoice dispatcher does not lock db

* fakewallet: pay_if_regtest waits

* pay fakewallet invoices

* add more

* faster

* slower

* pay_if_regtest async

* do not lock the invoice dispatcher

* test: do I get disk I/O errors if we disable the invoice_callback_dispatcher?

* fix fake so it workss without a callback dispatchert

* test on github

* readd tasks

* refactor

* increase time for lock invoice disatcher

* try avoiding a race

* remove task

* github actions: test regtest with postgres

* mint per module

* no connection pool for testing

* enable pool

* do not resend paid event

* reuse connection

* close db connections

* sessions

* enable debug

* dispose engine

* disable connection pool for tests

* enable connection pool for postgres only

* clean up shutdown routine

* remove wait for lightning fakewallet lightning invoice

* cancel invoice listener tasks on shutdown

* fakewallet conftest: decrease outgoing delay

* delay payment and set postgres only if needed

* disable fail fast for regtest

* clean up regtest.yml

* change order of tests_db.py

* row-specific mint_quote locking

* refactor

* fix lock statement

* refactor swap

* refactor

* remove psycopg2

* add connection string example to .env.example

* remove unnecessary pay

* shorter sleep in test_wallet_subscription_swap
2024-07-08 18:05:57 +02:00
callebtc
2739c3127a TokenV4 CBOR serialization (#502)
* WIP: cashuB with CBOR

* working

* tokenv4 works

* fix mypy
2024-06-30 14:36:44 +02:00
callebtc
1d8b5cd5ca Fix: Nut 05 mint response model (#564)
* change response model of NUT-05 to include payment_preimage and change (NUT-08)

* fix tests

* crud: same expiry as timestamp

* fix expiry handling

* add api tests to check new models
2024-06-27 14:35:03 +02:00
callebtc
6b38ef6c29 NUT-04 and NUT-05: Add state field to quotes (#560)
* wip adding states, tests failing

* add state field to quotes

* responses from quotes

* store correct state

* cleaner test

* fix swap check

* oops
2024-06-26 03:06:01 +02:00
callebtc
e846acf946 Mint: add websockets for quote updates (#413)
* add websockets for quote updates

* add test (not working)

* wip: emit events to everyone

* wip: emit events to everyone

* wip, lots of things broken but invoice callback works

* wip

* add wip files

* tests almost passing

* add task

* refactor nut constants

* startup fix

* works with old mints

* wip cli

* fix mypy

* remove automatic invoice test now with websockets

* remove comment

* better logging

* send back response

* add rate limiter to websocket

* add rate limiter to subscriptions

* refactor websocket ratelimit

* websocket tests

* subscription kinds

* doesnt start

* remove circular import

* update

* fix mypy

* move test file in test because it fails if it runs later... dunno why

* adjust websocket NUT-06 settings

* local import and small fix

* disable websockets in CLI if "no_check" is selected

* move subscription test to where it was

* check proof state with callback, add tests

* tests: run mint fixture per module instead of per session

* subscription command name fix

* test per session again

* update test race conditions

* fix tests

* clean up

* tmp

* fix db issues and remove cached secrets

* fix tests

* blindly try pipeline

* remove comments

* comments
2024-06-25 19:20:03 +02:00
callebtc
d30b1a2777 Add fees (#503)
* wip

* wip

* model

* refactor wallet transactions

* refactor wallet

* sending with fees works and outputs fill up the wallet

* wip work

* ok

* comments

* receive with amount=0

* correctly import postmeltrequest

* fix melt amount

* tests working

* remove mint_loaded decorator in deprecated wallet api

* wallet works with units

* refactor: melt_quote

* fix fees

* add file

* fees for melt inputs

* set default input fee for internal quotes to 0

* fix coinselect

* coin selection working

* yo

* fix all tests

* clean up

* last commit added fees for inputs for melt transactions - this commit adds a blanace too low exception

* fix fee return and melt quote max allowed amount check during creation of melt quote

* clean up code

* add tests for fees

* add melt tests

* update wallet fee information
2024-06-15 16:22:41 +02:00
callebtc
61cf7def24 Multinut LND (#492)
* amount in melt request

* apply fee limit

* more error handling

* wip: signal flag in /info

* clean up multinut

* decode mypy error lndrest

* fix test

* fix tests

* signal feature and blindmessages_deprecated

* setting

* fix blindedsignature method

* fix tests

* mint info file

* test mpp with lnd regtest

* nuts optionsl mint
 info

* try to enable mpp with lnd

* test mpp with third payment
2024-05-22 22:52:26 +02:00
Caleb Beery
bb7730694d Refactored the request mint wallet method to generate the invoice from a returned MintQuoteResponse. (#507) 2024-04-15 18:43:13 +02:00
Caleb Beery
26afd71d89 Restore wallet now restores tokens for all mint keysets. (#509) 2024-04-13 10:31:05 +02:00
Guilherme Pereira
3b2f1aa6f4 Issue #313: allow checking pending invoices (#493)
* Update deprecated datetime

* Add options to Invoices cli
With these options, we are able to return:
1) all invoices (this is the default);
2) pending invoices (paid False, out False);
3) paid invoices;
4) and unpaid invoices.

* make format

* Fix mypy error with datetime

* sort imports

* Remove unneeded unit when printing out info

* Fix wrong method doc

* Try to mint pending invoices

* make pre-commit

* Refactor --tests flag to --mint
The default will be false, i.e., if the user does not
pass in the --mint flag, it will not try to mint
the pending invoice.

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2024-04-03 17:51:15 +02:00
callebtc
b8ad0e0a8f Mint: Recover pending melts at startup (#499)
* wip works with fakewallet

* startup refactor

* add tests

* regtest tests for pending melts

* wip CLN

* remove db migration

* remove foreign key relation to keyset id

* fix: get_promise from db and restore DLEQs

* test: check for keyset not found error

* fix migrations

* lower-case all db column names

* add more tests for regtest

* simlate failure for lightning

* test wallet spent state with hodl invoices

* retry

* regtest with postgres

* retry postgres

* add sleeps

* longer sleep on github

* more sleep for github sigh

* increase sleep ffs

* add sleep loop

* try something

* do not pay with wallet but with ledger

* fix lnbits pending state

* fix pipeline to use fake admin from docker
2024-04-03 17:14:21 +02:00
callebtc
150195d66a Token state check with Y (#468)
* Token state check with Y

* remove backwards compat for v1
2024-03-12 15:53:18 +01:00
callebtc
4f52973908 Update PostRestoreResponse class to use "signatures" instead of "promises" (#467)
* update nut-09 endpoint

* add to deprecated router and wallet
2024-03-12 15:52:20 +01:00
callebtc
29be002495 Wallet: deprecate old h2c (#459)
* wallet: deprecate old hash to curve

* fix order

* added migration: untested

* recompute Y always
2024-02-26 23:07:13 +01:00
callebtc
be7a8a744f Revert "Wallet: deprecate old hash to curve (#457)" (#458)
This reverts commit b06d93c5ff.
2024-02-26 00:30:42 +01:00
callebtc
b06d93c5ff Wallet: deprecate old hash to curve (#457)
* wallet: deprecate old hash to curve

* fix order
2024-02-26 00:24:58 +01:00
callebtc
afbde83ae2 wallet print on json deseriliaztion error and batch invalidation of proofs (#430) 2024-02-16 12:11:39 +01:00
callebtc
3f090c1691 Mint: add expiry to quotes, closes #385 (#429)
* add expiry to quotes, closes #385

* fix wallet deprecated mock with expiry

* expiry is an optional field
2024-02-16 11:40:46 +01:00
callebtc
6db4604f99 Mint: store Y in db (#412)
* storage y db

* for proofs_pending as well

* pending check with Y

* fix pending table

* test_race_pending

* skip race condition test on github

* skip test on github actions

* move test_cli.py -> test_wallet_cli.py

* get full proof from memory

* add domain separation wallet
2024-02-10 22:52:55 +01:00
callebtc
a518274f7e Nutshell cleanup wishlist (#332)
* fix keys

* fix tests

* backwards compatible api upgrade

* upgrade seems to work

* fix tests

* add deprecated api functions

* add more tests of backwards compat

* add test serialization for nut00

* remove a redundant test

* move mint and melt to new api

* mypy works

* CI: mypy --check-untyped-defs

* add deprecated router

* add hints and remove logs

* fix tests

* cleanup

* use new mint and melt endpoints

* tests passing?

* fix mypy

* make format

* make format

* make format

* commit

* errors gone

* save

* adjust the API

* store quotes in db

* make mypy happy

* add fakewallet settings

* remove LIGHTNING=True and pass quote id for melt

* format

* tests passing

* add CoreLightningRestWallet

* add macaroon loader

* add correct config

* preimage -> proof

* move wallet.status() to cli.helpers.print_status()

* remove statuses from tests

* remove

* make format

* Use httpx in deprecated wallet

* fix cln interface

* create invoice before quote

* internal transactions and deprecated api testing

* fix tests

* add deprecated API tests

* fastapi type hints break things

* fix duplicate wallet error

* make format

* update poetry in CI to 1.7.1

* precommit restore

* remove bolt11

* oops

* default poetry

* store fee reserve for melt quotes and refactor melt()

* works?

* make format

* test

* finally

* fix deprecated models

* rename v1 endpoints to bolt11

* raise restore and check to v1, bump version to 0.15.0

* add version byte to keyset id

* remove redundant fields in json

* checks

* generate bip32 keyset wip

* migrate old keysets

* load duplicate keys

* duplicate old keysets

* revert router changes

* add deprecated /check and /restore endpoints

* try except invalidate

* parse unit from derivation path, adjust keyset id calculation with bytes

* remove keyest id from functions again and rely on self.keyset_id

* mosts tests work

* mint loads multiple derivation paths

* make format

* properly print units

* fix tests

* wallet works with multiple units

* add strike wallet and choose backend dynamically

* fix mypy

* add get_payment_quote to lightning backends

* make format

* fix startup

* fix lnbitswallet

* fix tests

* LightningWallet -> LightningBackend

* remove comments

* make format

* remove msat conversion

* add Amount type

* fix regtest

* use melt_quote as argument for pay_invoice

* test old api

* fees in sats

* fix deprecated fees

* fixes

* print balance correctly

* internally index keyset response by int

* add pydantic validation to input models

* add timestamps to mint db

* store timestamps for invoices, promises, proofs_used

* fix wallet migration

* rotate keys correctly for testing

* remove print

* update latest keyset

* fix tests

* fix test

* make format

* make format with correct black version

* remove nsat and cheese

* test against deprecated mint

* fix tests?

* actually use env var

* mint run with env vars

* moar test

* cleanup

* simplify tests, load all keys

* try out testing with internal invoices

* fix internal melt test

* fix test

* deprecated checkfees expects appropriate fees

* adjust comment

* drop lightning table

* split migration for testing for now, remove it later

* remove unused lightning table

* skip_private_key -> skip_db_read

* throw error on migration error

* reorder

* fix migrations

* fix lnbits fee return value negative

* fix typo

* comments

* add type

* make format

* split must use correct amount

* fix tests

* test deprecated api with internal/external melts

* do not split if not necessary

* refactor

* fix test

* make format with new black

* cleanup and add comments

* add quote state check endpoints

* fix deprecated wallet response

* split -> swap endpoint

* make format

* add expiry to quotes, get quote endpoints, and adjust to nut review comments

* allow overpayment of melt

* add lightning wallet tests

* commiting to save

* fix tests a bit

* make format

* remove comments

* get mint info

* check_spendable default False, and return payment quote checking id

* make format

* bump version in pyproject

* update to /v1/checkstate

* make format

* fix mint api checks

* return witness on /v1/checkstate

* no failfast

* try fail-fast: false in ci.yaml

* fix db lookup

* clean up literals
2024-01-08 00:57:15 +01:00
callebtc
6c8b1a858f Wallet/fix_nostr_timeout (#376)
* fix nostr receive

* split with amount pre 0.13

* drop 0.13.0 amount with split compatibility
2023-12-03 01:56:58 +01:00
callebtc
fa5193cd8f index on db and read spent proofs from db (#370)
* index on db and read spent proofs from db

* add benchmark for testing

* remove benchmark

* add option to disable cached secrets

* disable python 3.9 tests
2023-11-26 06:07:38 -03:00
callebtc
f7d0126805 Fix: Cast keyset keys (amount) to int (#368)
* load keys as integers

* add tests

* make format

* revert format from newer branch
2023-11-24 14:47:36 -03:00
callebtc
0c3777dd17 ensure that mint keys are loaded before calling appropriate api methods (#356) 2023-11-09 20:42:05 -03:00
callebtc
84cbeb6d30 fix proxy keys (#355)
* fix proxy keys

* fix all tests

* fix tor test
2023-11-09 17:03:45 -03:00
callebtc
0490f20932 Wallet: Lightning interface (#318)
* mint does not start yet

* fix import

* revert mint db migrations

* handle zero fee case

* cli: adjust fee message

* wallet: replace requests with httpx

* clean up

* rename http client decorator

* fix pending check in main, todo: TEST PROXIES WITH HTTPX

* fix up

* use httpx for nostr as well

* update packages to same versions as https://github.com/lnbits/lnbits/pull/1609/files

* fix proof deserialization

* check for string

* tests passing

* adjust wallet api tests

* lockfile

* add correct responses to Lightning interface and delete melt_id for proofs for which the payent has failed

* fix create_invoice checking_id response

* migrations atomic

* proofs are stored automatically when created

* make format

* use bolt11 lib

* stricter type checking

* add fee response to payments

* assert fees in test_melt

* test that mint_id and melt_id is stored correctly in proofs and proofs_used

* remove traces

* refactor: Lightning interface into own file and LedgerCrud with typing

* fix tests

* fix payment response

* rename variable
2023-10-21 14:38:16 +02:00
callebtc
cfab668e54 Mint: Allow 0-valued amounts for blank outputs (#348)
* allow 0 amount for blank outputs

* fix precommit as well
2023-10-18 15:18:07 +02:00
sihamon
a7cc210874 Join mint URL and endpoint in a safe way (#298)
* Join mint URL and endpoint in a safe way

* Use posixpath.join for joining URLs
2023-10-13 22:00:42 +02:00
callebtc
c444a063c1 Wallet: Cache keysets (#333)
* accept new keyset id calculation, cache keysets, remove duplicate representations

* remove comments

* check if keyset is present for DLEQ

* load keys from db if available

* store new keyset

* make mypy happy

* make mypy happy

* precommit
2023-10-13 21:58:42 +02:00
callebtc
744807b6f4 Remove P2SH (#341)
* remove p2sh

* Fix WalletAPI LockResponse
2023-10-13 21:41:54 +02:00
callebtc
d827579e65 Coalesce all witness fields to Proof.witness (#342)
* call proofs field witness

* test p2pk sig_all=True

* outputs also use witness field
2023-10-13 21:33:21 +02:00
callebtc
1149533e82 Wallet: fix secret derivation & new CLI command cashu selfpay (#331)
* refactor wallet restore tests

* fix secret derivation

* selfpay to refresh tokens
2023-10-03 18:34:12 +02:00
callebtc
638324940a Tests: Test with LIGHTNING=True and refactor mint (#326)
* refactor mint verification

* test with lightning=true

* rename proofs_used to secrets_used and refactor

* test with lightning

* spelling fixes
2023-09-24 14:35:13 +02:00