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
5ecdc27f
Commit
5ecdc27f
authored
5 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Generate recognizable unpaid and double-spend responses
parent
94fcbc6c
No related branches found
Branches containing commit
No related tags found
1 merge request
!34
Generate recognizable unpaid and double-spend responses
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/PaymentServer/Redemption.hs
+29
-14
29 additions, 14 deletions
src/PaymentServer/Redemption.hs
with
29 additions
and
14 deletions
src/PaymentServer/Redemption.hs
+
29
−
14
View file @
5ecdc27f
...
...
@@ -8,7 +8,6 @@
module
PaymentServer.Redemption
(
RedemptionAPI
,
Redeem
(
Redeem
)
,
Result
(
Failed
,
Succeeded
)
,
redemptionServer
)
where
...
...
@@ -19,7 +18,8 @@ import Control.Monad.IO.Class
(
liftIO
)
import
Data.Text
(
pack
(
Text
,
pack
)
import
qualified
Data.Text.IO
as
TextIO
import
Data.Text.Encoding
...
...
@@ -69,7 +69,9 @@ import PaymentServer.Issuer
)
data
Result
=
Failed
=
Unpaid
-- ^ A voucher has not been paid for.
|
DoubleSpend
-- ^ A voucher has already been redeemed.
|
OtherFailure
Text
-- ^ Some other unrecognized failure mode.
|
Succeeded
PublicKey
[
Signature
]
Proof
deriving
(
Show
,
Eq
)
...
...
@@ -87,7 +89,18 @@ instance ToJSON Redeem where
toEncoding
=
genericToEncoding
defaultOptions
instance
ToJSON
Result
where
toJSON
Failed
=
object
[
"success"
.=
False
]
toJSON
Unpaid
=
object
[
"success"
.=
False
,
"reason"
.=
(
"unpaid"
::
Text
)
]
toJSON
DoubleSpend
=
object
[
"success"
.=
False
,
"reason"
.=
(
"double-spend"
::
Text
)
]
toJSON
(
OtherFailure
description
)
=
object
[
"success"
.=
False
,
"reason"
.=
description
]
toJSON
(
Succeeded
key
signatures
proof
)
=
object
[
"success"
.=
True
,
"public-key"
.=
key
...
...
@@ -103,13 +116,18 @@ instance FromJSON Result where
<$>
v
.:
"public-key"
<*>
v
.:
"signatures"
<*>
v
.:
"proof"
else
return
Failed
else
do
reason
<-
v
.:
"reason"
if
reason
==
"unpaid"
then
return
Unpaid
else
if
reason
==
"double-spend"
then
return
DoubleSpend
else
return
$
OtherFailure
reason
type
RedemptionAPI
=
ReqBody
'
[
JSON
]
Redeem
:>
Post
'
[
JSON
]
Result
jsonErr400
=
err400
{
errBody
=
encode
Failed
jsonErr400
reason
=
err400
{
errBody
=
encode
reason
,
errHeaders
=
[
(
"Content-Type"
,
"application/json;charset=utf-8"
)
]
}
...
...
@@ -125,17 +143,14 @@ redeem issue database (Redeem voucher tokens) = do
result
<-
liftIO
$
PaymentServer
.
Persistence
.
redeemVoucher
database
voucher
fingerprint
case
result
of
Left
NotPaid
->
do
liftIO
$
putStrLn
"Attempt to redeem unpaid voucher"
throwError
jsonErr400
throwError
$
jsonErr400
Unpaid
Left
AlreadyRedeemed
->
do
liftIO
$
putStrLn
"Attempt to double-spend paid voucher"
throwError
jsonErr400
throwError
$
jsonErr400
DoubleSpend
Right
()
->
do
let
result
=
issue
tokens
case
result
of
Left
reason
->
do
liftIO
$
TextIO
.
putStrLn
reason
throwError
jsonErr400
throwError
$
jsonErr400
$
OtherFailure
reason
Right
(
ChallengeBypass
key
signatures
proof
)
->
return
$
Succeeded
key
signatures
proof
...
...
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