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
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
0981bb0e
Commit
0981bb0e
authored
5 years ago
by
Ramakrishnan Muthukrishnan
Browse files
Options
Downloads
Patches
Plain Diff
persistence: WIP of sqlite based persistence
parent
25ffdca0
No related branches found
Branches containing commit
No related tags found
1 merge request
!26
Initial implementation of Persistence using sqlite
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PaymentServer.cabal
+1
-0
1 addition, 0 deletions
PaymentServer.cabal
src/PaymentServer/Persistence.hs
+37
-0
37 additions, 0 deletions
src/PaymentServer/Persistence.hs
with
38 additions
and
0 deletions
PaymentServer.cabal
+
1
−
0
View file @
0981bb0e
...
...
@@ -35,6 +35,7 @@ library
, text
, containers
, cryptonite
, sqlite-simple
default-language: Haskell2010
ghc-options: -Wmissing-import-lists -Wunused-imports
pkgconfig-depends: ristretto
...
...
This diff is collapsed.
Click to expand it.
src/PaymentServer/Persistence.hs
+
37
−
0
View file @
0981bb0e
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances #-}
module
PaymentServer.Persistence
(
Voucher
,
Fingerprint
...
...
@@ -21,6 +23,10 @@ import Data.IORef
,
modifyIORef
,
readIORef
)
import
qualified
Database.SQLite.Simple
as
Sqlite
import
Database.SQLite.Simple.FromRow
(
FromRow
(
fromRow
)
)
-- | A voucher is a unique identifier which can be associated with a payment.
-- A paid voucher can be redeemed for ZKAPs which can themselves be exchanged
...
...
@@ -103,3 +109,34 @@ memory = do
paid
<-
newIORef
mempty
redeemed
<-
newIORef
mempty
return
$
Memory
paid
redeemed
instance
VoucherDatabase
Sqlite
.
Connection
where
-- payForVoucher :: Sqlite.Connection -> Voucher -> IO ()
payForVoucher
dbConn
voucher
=
do
undefined
-- redeemVoucher :: Sqlite.Connection -> Voucher -> Fingerprint -> IO (Either RedeemError ())
redeemVoucher
dbConn
voucher
fingerprint
=
do
unpaid
<-
Set
.
notMember
voucher
<$>
getPaidVouchers
dbConn
existingFingerprint
<-
getVoucherFingerprint
dbConn
voucher
case
(
unpaid
,
existingFingerprint
)
of
(
True
,
_
)
->
return
$
Left
NotPaid
(
False
,
[]
)
->
-- TODO: insert voucher and fingerprint into the redeemed table
return
$
Right
()
(
False
,
[
fingerprint'
])
->
if
fingerprint
==
fingerprint'
then
return
$
Right
()
else
return
$
Left
AlreadyRedeemed
instance
FromRow
Fingerprint
where
fromRow
=
Sqlite
.
field
getPaidVouchers
::
Sqlite
.
Connection
->
IO
(
Set
.
Set
Voucher
)
getPaidVouchers
dbConn
=
Set
.
fromList
<$>
Sqlite
.
query_
dbConn
"SELECT DISTINCT name FROM vouchers"
getVoucherFingerprint
::
Sqlite
.
Connection
->
Voucher
->
IO
[
Fingerprint
]
getVoucherFingerprint
dbConn
voucher
=
do
Sqlite
.
query
dbConn
"SELECT redeemed.fingerprint FROM vouchers INNER JOIN redeemed ON vouchers.id = redeemed.voucher_id AND vouchers.name = ?"
(
Sqlite
.
Only
voucher
)
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