-
Notifications
You must be signed in to change notification settings - Fork 123
staticaddr: persist withdrawal info #938
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b780a9a
staticaddr: simplify handleWithdrawal
hieblmi 94aeae8
loopdb: withdrawal table and queries
hieblmi cd9bcdf
looprpc: add ListStaticAddressWithdrawals for historic withdrawal inf…
hieblmi 5718f11
staticaddr: store historic withdrawal info
hieblmi 614d619
loopd: retrieve historic withdrawal info
hieblmi 06bbb90
cmd: add listwithdrawals command
hieblmi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
2 changes: 2 additions & 0 deletions
2
loopdb/sqlc/migrations/000015_static_address_withdrawals.down.sql
This file contains hidden or 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,2 @@ | ||
DROP TABLE IF EXISTS withdrawals; | ||
DROP TABLE IF EXISTS withdrawal_deposits; |
42 changes: 42 additions & 0 deletions
42
loopdb/sqlc/migrations/000015_static_address_withdrawals.up.sql
This file contains hidden or 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,42 @@ | ||
-- withdrawals stores finalized static address withdrawals. | ||
CREATE TABLE IF NOT EXISTS withdrawals ( | ||
-- id is the auto-incrementing primary key for a withdrawal. | ||
id INTEGER PRIMARY KEY, | ||
|
||
-- withdrawal_id is the unique identifier for the withdrawal. | ||
withdrawal_id BLOB NOT NULL UNIQUE, | ||
|
||
-- withdrawal_tx_id is the transaction tx id of the withdrawal. | ||
withdrawal_tx_id TEXT UNIQUE, | ||
|
||
-- total_deposit_amount is the total amount of the deposits in satoshis. | ||
total_deposit_amount BIGINT NOT NULL, | ||
|
||
-- withdrawn_amount is the total amount of the withdrawal. It amounts | ||
-- to the total amount of the deposits minus the fees and optional change. | ||
withdrawn_amount BIGINT, | ||
|
||
-- change_amount is the optional change that the user selected. | ||
change_amount BIGINT, | ||
|
||
-- initiation_time is the creation of the withdrawal. | ||
initiation_time TIMESTAMP NOT NULL, | ||
|
||
-- confirmation_height is the block height at which the withdrawal was first | ||
-- confirmed. | ||
confirmation_height BIGINT | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS withdrawal_deposits ( | ||
-- id is the auto-incrementing primary key. | ||
id INTEGER PRIMARY KEY, | ||
|
||
-- withdrawal_id references the withdrawals table. | ||
withdrawal_id BLOB NOT NULL REFERENCES withdrawals(withdrawal_id), | ||
|
||
-- deposit_id references the deposits table. | ||
deposit_id BLOB NOT NULL REFERENCES deposits(deposit_id), | ||
|
||
-- Ensure that each deposit is used only once per withdrawal. | ||
UNIQUE(deposit_id, withdrawal_id) | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,47 @@ | ||
-- name: CreateWithdrawal :exec | ||
INSERT INTO withdrawals ( | ||
withdrawal_id, | ||
total_deposit_amount, | ||
initiation_time | ||
) VALUES ( | ||
$1, $2, $3 | ||
); | ||
|
||
-- name: CreateWithdrawalDeposit :exec | ||
INSERT INTO withdrawal_deposits ( | ||
withdrawal_id, | ||
deposit_id | ||
) VALUES ( | ||
$1, $2 | ||
); | ||
|
||
-- name: GetWithdrawalIDByDepositID :one | ||
SELECT withdrawal_id | ||
FROM withdrawal_deposits | ||
WHERE deposit_id = $1; | ||
|
||
-- name: UpdateWithdrawal :exec | ||
UPDATE withdrawals | ||
SET | ||
withdrawal_tx_id = $2, | ||
withdrawn_amount = $3, | ||
change_amount = $4, | ||
confirmation_height = $5 | ||
WHERE | ||
withdrawal_id = $1; | ||
|
||
-- name: GetWithdrawalDeposits :many | ||
SELECT | ||
deposit_id | ||
FROM | ||
withdrawal_deposits | ||
WHERE | ||
withdrawal_id = $1; | ||
|
||
-- name: GetAllWithdrawals :many | ||
SELECT | ||
* | ||
FROM | ||
withdrawals | ||
ORDER BY | ||
initiation_time DESC; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.