-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Also log autowithdrawal routing errors * Only log autowithdrawal success in worker * Use WalletType for WalletLog.wallet * Fix autowithdrawal success message * Infer walletName from walletType in upsertWallet
- Loading branch information
Showing
6 changed files
with
101 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
prisma/migrations/20240415113539_withdrawal_wallet_id/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- AlterTable | ||
ALTER TABLE "Withdrawl" ADD COLUMN "walletId" INTEGER; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Withdrawl" ADD CONSTRAINT "Withdrawl_walletId_fkey" FOREIGN KEY ("walletId") REFERENCES "Wallet"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
CREATE OR REPLACE FUNCTION create_withdrawl(lnd_id TEXT, invoice TEXT, msats_amount BIGINT, msats_max_fee BIGINT, username TEXT, auto_withdraw BOOLEAN, wallet_id INTEGER) | ||
RETURNS "Withdrawl" | ||
LANGUAGE plpgsql | ||
AS $$ | ||
DECLARE | ||
user_id INTEGER; | ||
user_msats BIGINT; | ||
withdrawl "Withdrawl"; | ||
BEGIN | ||
PERFORM ASSERT_SERIALIZED(); | ||
|
||
SELECT msats, id INTO user_msats, user_id FROM users WHERE name = username; | ||
IF (msats_amount + msats_max_fee) > user_msats THEN | ||
RAISE EXCEPTION 'SN_INSUFFICIENT_FUNDS'; | ||
END IF; | ||
|
||
IF EXISTS (SELECT 1 FROM "Withdrawl" WHERE hash = lnd_id AND status IS NULL) THEN | ||
RAISE EXCEPTION 'SN_PENDING_WITHDRAWL_EXISTS'; | ||
END IF; | ||
|
||
IF EXISTS (SELECT 1 FROM "Withdrawl" WHERE hash = lnd_id AND status = 'CONFIRMED') THEN | ||
RAISE EXCEPTION 'SN_CONFIRMED_WITHDRAWL_EXISTS'; | ||
END IF; | ||
|
||
INSERT INTO "Withdrawl" (hash, bolt11, "msatsPaying", "msatsFeePaying", "userId", "autoWithdraw", "walletId", created_at, updated_at) | ||
VALUES (lnd_id, invoice, msats_amount, msats_max_fee, user_id, auto_withdraw, wallet_id, now_utc(), now_utc()) RETURNING * INTO withdrawl; | ||
|
||
UPDATE users SET msats = msats - msats_amount - msats_max_fee WHERE id = user_id; | ||
|
||
RETURN withdrawl; | ||
END; | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters