From f0867b77c980e1eba9cee6af533d93c4b22cc690 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Wed, 15 Apr 2020 11:25:31 -0400
Subject: [PATCH] Add an optional redeemCounter value (default to 0)

---
 src/PaymentServer/Redemption.hs | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/PaymentServer/Redemption.hs b/src/PaymentServer/Redemption.hs
index 53f6573..fa5a8e1 100644
--- a/src/PaymentServer/Redemption.hs
+++ b/src/PaymentServer/Redemption.hs
@@ -29,6 +29,8 @@ import Data.Aeson
   , FromJSON(parseJSON)
   , withObject
   , (.:)
+  , (.:?)
+  , (.!=)
   , genericToEncoding
   , defaultOptions
   , encode
@@ -80,9 +82,15 @@ data Redeem
   = Redeem
   { redeemVoucher :: Voucher        -- ^ The voucher being redeemed.
   , redeemTokens :: [BlindedToken]  -- ^ Tokens to be signed as part of this redemption.
+  , redeemCounter :: Integer        -- ^ Counter tag on this redemption.
   } deriving (Show, Eq, Generic)
 
-instance FromJSON Redeem
+instance FromJSON Redeem where
+  parseJSON = withObject "redeem" $ \o -> do
+    voucher <- o .: "redeemVoucher"
+    tokens <- o .: "redeemTokens"
+    counter <- o .:? "redeemCounter" .!= 0
+    return $ Redeem voucher tokens counter
 
 instance ToJSON Redeem where
   toEncoding = genericToEncoding defaultOptions
-- 
GitLab