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
42a12779
Unverified
Commit
42a12779
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Some minor cleanups, mostly docs/comments
parent
8a0a8aa4
No related branches found
No related tags found
1 merge request
!55
Some minor cleanups, mostly docs/comments
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 @
42a12779
...
@@ -7,8 +7,7 @@ module PaymentServer.Persistence
...
@@ -7,8 +7,7 @@ module PaymentServer.Persistence
,
Fingerprint
,
Fingerprint
,
RedeemError
(
NotPaid
,
AlreadyRedeemed
,
DuplicateFingerprint
)
,
RedeemError
(
NotPaid
,
AlreadyRedeemed
,
DuplicateFingerprint
)
,
PaymentError
(
AlreadyPaid
,
PaymentFailed
)
,
PaymentError
(
AlreadyPaid
,
PaymentFailed
)
,
VoucherDatabase
(
payForVoucher
,
redeemVoucherWithCounter
)
,
VoucherDatabase
(
payForVoucher
,
redeemVoucher
,
redeemVoucherWithCounter
)
,
redeemVoucher
,
VoucherDatabaseState
(
MemoryDB
,
SQLiteDB
)
,
VoucherDatabaseState
(
MemoryDB
,
SQLiteDB
)
,
memory
,
memory
,
sqlite
,
sqlite
...
@@ -63,7 +62,14 @@ data RedeemError =
...
@@ -63,7 +62,14 @@ data RedeemError =
NotPaid
NotPaid
-- | The voucher has already been redeemed.
-- | The voucher has already been redeemed.
|
AlreadyRedeemed
|
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
|
DuplicateFingerprint
deriving
(
Show
,
Eq
)
deriving
(
Show
,
Eq
)
...
@@ -78,6 +84,13 @@ data RedeemError =
...
@@ -78,6 +84,13 @@ data RedeemError =
-- to support this case.
-- to support this case.
type
Fingerprint
=
Text
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
)
type
RedemptionKey
=
(
Voucher
,
Integer
)
-- | A VoucherDatabase provides persistence for state related to vouchers.
-- | A VoucherDatabase provides persistence for state related to vouchers.
...
@@ -97,6 +110,9 @@ class VoucherDatabase d where
...
@@ -97,6 +110,9 @@ class VoucherDatabase d where
-- | Attempt to redeem a voucher. If it has not been redeemed before or it
-- | Attempt to redeem a voucher. If it has not been redeemed before or it
-- has been redeemed with the same fingerprint, the redemption succeeds.
-- has been redeemed with the same fingerprint, the redemption succeeds.
-- Otherwise, it fails.
-- Otherwise, it fails.
--
-- This is a backwards compatibility API. Callers should prefer
-- redeemVoucherWithCounter.
redeemVoucher
redeemVoucher
::
d
-- ^ The database
::
d
-- ^ The database
->
Voucher
-- ^ A voucher to consider for redemption
->
Voucher
-- ^ A voucher to consider for redemption
...
@@ -128,8 +144,10 @@ data VoucherDatabaseState =
...
@@ -128,8 +144,10 @@ data VoucherDatabaseState =
-- | A mapping from redeemed (voucher, counter) pairs to fingerprints
-- | A mapping from redeemed (voucher, counter) pairs to fingerprints
-- associated with the redemption.
-- associated with the redemption.
,
redeemed
::
IORef
(
Map
.
Map
RedemptionKey
Fingerprint
)
,
redeemed
::
IORef
(
Map
.
Map
RedemptionKey
Fingerprint
)
-- | A map from fingerprints to redemption details for successful
-- | A mapping from fingerprints to redemption details for successful
-- redemptions.
-- 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
)
,
fingerprints
::
IORef
(
Map
.
Map
Fingerprint
RedemptionKey
)
}
}
|
SQLiteDB
{
connect
::
IO
Sqlite
.
Connection
}
|
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