Commit Graph

650 Commits

Author SHA1 Message Date
sihamon
a0df47f13a Add multi-mint swap to CLI and API (#212)
* Add multi-mint swap to CLI and API

* Add confirmation prompt to CLI

* Replace several assert statements

* Define response for API endpoint swap

* Adapt to latest changes on main

* Fix: missing argument after latest changes on main

* API: use local wallet for swap

* Improve swap command

* clean up cli swap

* fix comment

* clean up router

* fix up

* remove outgoing

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2023-06-23 20:04:28 +02:00
callebtc
25385f1f16 [Wallet] store public keys of each keyset (#165)
* store public keys of each keyset

* deserialize public keys from db

* Fix: import accidentally removed during merge

* Sort imports correctly

---------

Co-authored-by: sihamon <sihamon@proton.me>
2023-06-23 19:30:45 +02:00
callebtc
a3e67d21aa Use m̶u̶l̶t̶i̶p̶r̶o̶c̶e̶s̶s̶i̶n̶g̶ asyncio locks instead of db locks (#256)
* use mp locks instead of db locks

* replace mp.Lock with asyncio.Lock

* make format

* push

* remove db connection (and lock) and delete asyncio locks
2023-06-23 19:10:32 +02:00
callebtc
62a6ec34b0 no async for deserialization functions (#255) 2023-06-23 00:21:31 +02:00
callebtc
c61971b268 balance: await wallet.load_proofs() (#254) 2023-06-18 15:12:32 +02:00
callebtc
12bc0c23cb [Mint] Fix: check keyset id in mint and allow custom split amounts for LIGHTNING=False (#253)
* check keyset existence and return error

* fix split specific amounts for LIGHTNING=False

* wallet loading

* remove wallet balance checks
2023-06-18 14:00:34 +02:00
callebtc
67caf5f532 update readme (#251) 2023-06-11 00:16:00 +02:00
callebtc
defcf7aac4 [Wallet] DB optimization for faster payments (#250)
* get rid of redundant proof loads

* fix test?

* fix one test?

* api: load_mint for invoice

* clean up tests
2023-06-11 00:10:07 +02:00
callebtc
959cc00c8a [Wallet] send without split (#249)
* send without split

* change test amount for nosplit send
2023-06-10 21:45:47 +02:00
callebtc
af3e82691e [Wallet] Allow minting of specific amounts (#248)
* Allow to start wallet API by cashu --daemon

* Provide access to wallet name via settings

* Make format

* Use flag is_eager for daemon option

* add setting api_host

* fix: add missing amount

* refactor mint

* cli and api for splitting and tests

* invoice balance?

* remove balance checks until I know why it doesnt update

* remove all balance checks from tests

* delete old code

* remove debug logs

---------

Co-authored-by: sihamon <sihamon@proton.me>
2023-06-10 20:45:03 +02:00
sihamon
786fbf2856 Allow to start wallet API by cashu --daemon (#243)
* Allow to start wallet API by cashu --daemon

* Provide access to wallet name via settings

* Make format

* Use flag is_eager for daemon option

* add setting api_host

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2023-06-08 14:42:37 +02:00
callebtc
5c820f9469 fix typo (#239) 2023-05-26 12:51:36 +02:00
callebtc
f052e2e788 update .env example to reflect latest flags (#238) 2023-05-26 12:49:59 +02:00
callebtc
7ed2161dba [Wallet] API: optional amount in InvoiceResponse (#236)
* fix missing value in InvoiceResponse API

* wallet api: optional amount in invoiceresponse

* skip tor test again
2023-05-23 18:30:33 +02:00
xphade
21069fb61a Implement dynamic amount of tokens for change (#223)
With the recent update to NUT-08, we can ensure that the amount of blank
outputs is always enough to cover any overpaid lightning fees. This
change implements this functionality for both the wallet and the mint.
The mint updateis backwards-compatible with respect to old wallets.
2023-05-23 17:40:48 +02:00
sihamon
5df0a9aa59 Catch all exceptions in wallet API (#220)
* Catch all exceptions in wallet API

* Use middleware instead of route class to catch exceptions

* Wallet API: simplify load_mint
2023-05-22 21:06:31 +02:00
sihamon
08ceeda36f [Wallet] Define responses for API (#233)
* Define responses for wallet API

* Make format
2023-05-22 14:31:29 +02:00
Erik Brakke
a3ded1cd94 Add secp256k1 deps to dockerfile (#235)
Co-authored-by: Erik Brakke <erik@datasembly.com>
2023-05-22 14:25:26 +02:00
callebtc
151fa1421a db: postgres cast int to bigint (#231)
* db: postgres cast int to bigint

* migrations: use db.big_int
2023-05-19 08:59:13 +02:00
Angus Pearson
730772d6a7 [Mint] LNBits backend refactor httpx (#234) 2023-05-19 08:55:19 +02:00
Angus Pearson
e25100c1e0 Mint API: Check ?amount is within a sensible range (#226) 2023-05-18 22:31:20 +02:00
callebtc
5f3f88c8ed [Mint] rewrite lnbits backend with httpx (#230)
* rewrite lnbits backend with httpx

* add httpx
2023-05-18 19:47:44 +02:00
callebtc
f0735cfc4a fix postgres views, closes #206 (#222) 2023-05-16 22:14:13 +02:00
callebtc
d0283670d3 Refactor Compat and Database for LNbits comaptibility (#219)
* remove changes to Compat and Database so its compatible with the classes from LNbits

* ledger.py: Annotate Connection type

* fix invoice memp
2023-05-15 22:15:56 +02:00
callebtc
6272aee189 make format (#218) 2023-05-15 17:11:02 +02:00
Semisol
d4c7a15e89 add transactions and locking for certain operations (#217) 2023-05-15 17:09:28 +02:00
callebtc
ddd8cebdb0 more logging (#216) 2023-05-15 00:37:46 +02:00
callebtc
4789e2a504 Mint/moremore_traces (#215)
* more trace logging

* a lot more logging
2023-05-15 00:15:07 +02:00
callebtc
352f77f9e9 more traces (#214) 2023-05-14 23:39:03 +02:00
callebtc
68d9020cb3 mint: add trace logs (#213) 2023-05-14 23:06:35 +02:00
xphade
d1cae88062 Assert mint_private_key is available at startup (#208)
* Assert `mint_private_key` is available at startup

If the mint's private key is not available, the ledger cannot be created
because no pubkey can be derived. We now explicitly assert this with a
descriptive error message.

Additionally fixed some typing errors.

* Shorten error message
2023-05-14 14:12:00 +02:00
sihamon
e7df2028fa Allow to set maximum peg in/out for mint (#209)
* Allow to set maximum peg in/out for mint

* Make format

* remove duplicate error

* move business logic to ledger

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2023-05-13 20:41:24 +02:00
callebtc
aa9b5bd55c add CONTRIBUTING.md (#211) 2023-05-13 20:11:50 +02:00
callebtc
f3cf1c69c4 [Wallet] Bugfix/enable-funding-multiple-mints (#210)
* Fix bug where no additional mints can be funded

As soon as one mint is in the database, the new multimint selector only
considers this mint, even if the `MINT_` environment variables point to
a different one. This commit fixes it by explicitly adding the set mint
URL to the selector.

Additionally did some small cleanups.

* Move mint adding to higher-level function

* bypass selection at first time

* use contextx, more explicit

* remove whitespace

---------

Co-authored-by: xphade <18196286+xphade@users.noreply.github.com>
2023-05-13 19:49:37 +02:00
callebtc
4088ab2876 Wallet REST API (#199)
* Add REST API for Cashu wallet

* Add simple way to start REST API server

* Add simple tests for wallet REST API

* Add TokenV3 to REST API

* Improve tests for wallet REST API

* Make format

* Remove unused import

* Rename nostr module for API

* Unify helper functions for CLI and API

* Make format

* Move error handling from helper functions to API

* Remove 'is_api' flag where possible

* Make format, cleanup, add comments

* Fix typo for burn also in API

* Improve error handling for API

* Add flag 'trust_new_mint' to receive command

To enable trusting or mistrusting unknown mints via API

* Allow selecting mint for sending from API

* Fix: set specific mint via API

* Fix: select mint with maximum balance via CLI

* Use different variables for mint_nr

* Allow selecting mint when sending via nostr via API

* Remove unnessecary 'is_api' flags from 'send_nostr'

* Remove HTTPException from nostr.py

* Allow selecting mint for sending with parameter also via CLI

* Allow trusting unknown mint for receiving also via CLI

* Make format

* Enable trusting unknown mint also when receiving via nostr

* Fix: wrong indentation of in receive function

* Use relative imports for wallet API

* Unify get_mint_wallet for CLI and API

* Unify send command for CLI and API

* Unify receive for CLI and API

* Catch errors in nostr via API

* Remove flag 'is_api' from verify_mints_tokenv2

* Remove cli_helpers left from last merge

* refactor cli selection

* load mint in nostr_send

* cleanup

* add cli_helpers.py

* legacy deserialization in cli

* make format

* clean up api response

* fix tests

* try pk

* verify mints in api

* try github tests

* Fix: verify_mints for API

* Uncomment verify_mints in receive of API

* update README

* Show mint url in pending

* clean up balance response

* fix test

* mint selection in api

* clean up API

* CLI: verify mint for receive -a

* clean up

* Rest -> REST

* Remove unused imports

---------

Co-authored-by: sihamon <sihamon@proton.me>
Co-authored-by: sihamon <126967444+sihamon@users.noreply.github.com>
2023-05-11 23:27:13 +02:00
callebtc
7f524927e2 [Wallet] backwards compat for breaking nut04 change use also payment_hash (#198)
* wallet: backwards compat for breaking nut04 change use also payment_hash

* make format
2023-05-11 12:50:24 +02:00
callebtc
c31f008fb4 [Mint] load the latest keyset from db based on the derivation path (#193)
* load the latest keyset from db based on the derivation path and not the on-line generated keyset id (necessary because we changed the keyset id derivation algorithm)

* better comments

* generate keys for keyset from db
2023-05-07 17:47:38 +02:00
callebtc
e9f33337db Fix/nut 04 payment hash (#191)
* payment_hash -> hash

* add aes encryption

* urlsafe base64 for free

* move files to crypto

* use random hash instead of encryption

* get rid of useless code

* simplify
2023-05-04 00:12:18 +02:00
calle
84d2471902 mint: reenable balance views (#190) 2023-05-02 00:52:26 +02:00
calle
61078ce7c8 [Mint] add mint api tests (#189)
* add mint api tests

* add /info test and fix NUT-09 contact info strings

* add test mint api

* replace with requests
2023-05-02 00:43:49 +02:00
calle
3c47ab2ac7 squash many mypy warnings (#188) 2023-05-01 23:09:16 +02:00
calle
e0a8da4f77 enable tor test (#185) 2023-05-01 22:44:06 +02:00
calle
321fc733c8 [Mint] Fix key derivation (#187)
* fix private key derivation

* add backwards compatilibity for old keysets

* bump version

* test pubkeys and private keys

* make format

* reset keys for tests

* fix cli tests
2023-05-01 22:43:51 +02:00
calle
d201b89df2 settings: add mint derivation path (#166) 2023-05-01 22:39:50 +02:00
calle
89fb2787e6 Python/relative_import (#186)
* relative import all the things

* make format

* add __init__.py to cli/

* fix mypy errors

* get rid of more mypy

* mypy fix crud.py

* fix another mypy error
2023-05-01 22:39:23 +02:00
calle
c9c8c1d12f [Wallet] coinselection of all tokens from old epochs (#164)
* coinselection of all tokens from old epochs

* delete debug prints

* cleaner

* comment
2023-05-01 22:38:43 +02:00
calle
f25e36f333 improve logging for keyests (#184) 2023-04-30 00:05:53 +02:00
moonsettler
9525655dc1 Update .env.example (#181) 2023-04-27 15:25:14 +02:00
calle
87f9241de1 [Mint] Fix key rotation (#177)
* rotate keys every 5 seconds

* every 10 seconds

* do not regenerate all past keys for each epoch cycle

* remove automatic rotation

* make format

* print to logger

* rephrase print
2023-04-26 20:20:17 +02:00
Sebastian Falbesoner
28812919ac fix double "or" typo in burn parameter validation error message (#172) 2023-04-23 13:57:08 +02:00