Skip to content
Snippets Groups Projects
Unverified Commit 42a12779 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Some minor cleanups, mostly docs/comments

parent 8a0a8aa4
No related branches found
No related tags found
1 merge request!55Some minor cleanups, mostly docs/comments
...@@ -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 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment