Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
967e34f1
Unverified
Commit
967e34f1
authored
Apr 15, 2020
by
Jean-Paul Calderone
Committed by
GitHub
Apr 15, 2020
Browse files
Options
Downloads
Plain Diff
Merge pull request #55 from PrivateStorageio/52.vary-by-counter
Some minor cleanups, mostly docs/comments
parents
62f58c90
42a12779
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/PaymentServer/Persistence.hs
+23
-5
23 additions, 5 deletions
src/PaymentServer/Persistence.hs
with
23 additions
and
5 deletions
src/PaymentServer/Persistence.hs
+
23
−
5
View file @
967e34f1
...
...
@@ -7,8 +7,7 @@ module PaymentServer.Persistence
,
Fingerprint
,
RedeemError
(
NotPaid
,
AlreadyRedeemed
,
DuplicateFingerprint
)
,
PaymentError
(
AlreadyPaid
,
PaymentFailed
)
,
VoucherDatabase
(
payForVoucher
,
redeemVoucherWithCounter
)
,
redeemVoucher
,
VoucherDatabase
(
payForVoucher
,
redeemVoucher
,
redeemVoucherWithCounter
)
,
VoucherDatabaseState
(
MemoryDB
,
SQLiteDB
)
,
memory
,
sqlite
...
...
@@ -63,7 +62,14 @@ data RedeemError =
NotPaid
-- | The voucher has already been redeemed.
|
AlreadyRedeemed
-- | The fingerprint given has already been seen.
-- | The fingerprint given has already been seen. Redemption with a
-- duplicate fingerprint is disallowed. Even though tokens could be issued
-- in this case, they would be the same as tokens already issued for a
-- different redemption attempt. The re-issued tokens are not distinct from
-- the originals and attempts to spend them will lead to double-spend
-- errors. A well-behaved client will never request tokens with a duplicate
-- fingerprint. We check for this case to prevent a misbehaving client from
-- accidentally creating worthless tokens.
|
DuplicateFingerprint
deriving
(
Show
,
Eq
)
...
...
@@ -78,6 +84,13 @@ data RedeemError =
-- to support this case.
type
Fingerprint
=
Text
-- | A RedemptionKey is a unique key that identifies an attempt to redeem a
-- voucher for some tokens. It includes a counter value distinct from the
-- voucher value to allow one voucher to be redeemed for more than one batch
-- of tokens. This allows partial progress on redemption when a voucher is
-- worth many, many tokens. Redemption is restricted to a single successful
-- attempt per RedemptionKey (with retries using the same Fingerprint
-- allowed).
type
RedemptionKey
=
(
Voucher
,
Integer
)
-- | A VoucherDatabase provides persistence for state related to vouchers.
...
...
@@ -97,6 +110,9 @@ class VoucherDatabase d where
-- | Attempt to redeem a voucher. If it has not been redeemed before or it
-- has been redeemed with the same fingerprint, the redemption succeeds.
-- Otherwise, it fails.
--
-- This is a backwards compatibility API. Callers should prefer
-- redeemVoucherWithCounter.
redeemVoucher
::
d
-- ^ The database
->
Voucher
-- ^ A voucher to consider for redemption
...
...
@@ -128,8 +144,10 @@ data VoucherDatabaseState =
-- | A mapping from redeemed (voucher, counter) pairs to fingerprints
-- associated with the redemption.
,
redeemed
::
IORef
(
Map
.
Map
RedemptionKey
Fingerprint
)
-- | A map from fingerprints to redemption details for successful
-- redemptions.
-- | A mapping from fingerprints to redemption details for successful
-- redemptions. This is the logical reverse of `redeemed` and should
-- always contain the same values as `redeemed`, but reversed. It is
-- maintained separately for efficient lookup by fingerprint.
,
fingerprints
::
IORef
(
Map
.
Map
Fingerprint
RedemptionKey
)
}
|
SQLiteDB
{
connect
::
IO
Sqlite
.
Connection
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment