RN7EI6INGUUHGMNY5RU3NH56WPLRZY5ZMYDNFMNE3TGV4ESFLQIAC
POX3UAMTGCNS3SU5I6IKDNCCSHEAUSFBZ3WCMQ3EXKPNXETOI6BAC
3QVT6MA6I2CILQH3LUZABS4YQ7MN6CNRYTDRVS376OOHTPLYTFJAC
NEDDHXUK3GNFMOFO3KLU7NRIHCTYNWBT3D6HTKZAOXFDE6HMDZ6AC
IZEVQF627FA7VV25KJAWYWGGC35LZUUBBQRPN5ZAINTQLPEDRTEAC
2XQD6KKKD6QVHFHAEMVE3XXY7X2T7BLTLL7XIILZAXNJJH2YONUQC
KNSI575VAW6HRCZYXOEPQ4DTSML4EORML5MV4DJBRKE7TXCPS4EAC
FD7SV5I6VCW27HZ3T3K4MMGB2OYGJTPKFFA263TNTAMRJGQJWVNAC
Z7KS5XHHC6PAMTVBHXY7KUSS3BWAOU6FSYIITUCFOOJZU4OUJHBAC
GCVQD44VRPQVKPZEPIC4AOIXLJIG2ZMV3QI2Y7KALUT6NVUBSGSAC
7HPY3QPFPN35PSPUBVNW2GTFB3CBQZBST4J2BAVJ7QMXLIUN52JAC
QMRKFEPGFBCEWAIXPEIG5ILKAJ2JH5L3TOITHR4HNJXK5FN3KXBQC
A6HKMINBNGQLLX4QJMYWKQ4JAEHVJ4HIRVDKPPDI3FJUO2AAB7OQC
W35DDBFYF6Z4ZPCFEO5RPAONZLYCSNTXUSTS6FIUUVZHCI6Q7GHAC
O5FVTOM6YFBLEPF3S576K6IMT6ZZ5VQCSB3YVXNS4CKBITKCRZ7AC
NVOCQVASZWTKQJG7GPH7KHKZZR7NUG4WLV5YY4KAIRPCJRWCZPIAC
SCXG6TJWYIPRUMT27KGKIIF6FYKTUTY74UNZ2FQTT63XZ6HIF3AAC
eventTypeParser :: FieldParser (C.UTCTime -> LogEvent)
eventTypeParser f v = do
tn <- typename f
case tn of
"event_t" ->
let err = UnexpectedNull (B.unpack tn)
(tableOid f)
(maybe "" B.unpack (name f))
"UTCTime -> LogEvent"
"columns of type event_t should not contain null values"
in maybe (conversionError err) (nameEvent . decodeUtf8) v
_ ->
let err = Incompatible (B.unpack tn)
(tableOid f)
(maybe "" B.unpack (name f))
"UTCTime -> LogEvent"
"column was not of type event_t"
in conversionError err
nullField :: RowParser Null
nullField = field
eventTypeParser :: FieldParser (C.UTCTime -> LogEvent)
eventTypeParser f v = do
tn <- typename f
case tn of
"event_t" ->
let err = UnexpectedNull (B.unpack tn)
(tableOid f)
(maybe "" B.unpack (name f))
"UTCTime -> LogEvent"
"columns of type event_t should not contain null values"
in maybe (conversionError err) (nameEvent . decodeUtf8) v
_ ->
let err = Incompatible (B.unpack tn)
(tableOid f)
(maybe "" B.unpack (name f))
"UTCTime -> LogEvent"
"column was not of type event_t"
in conversionError err
creditToParser :: FieldParser (RowParser CreditTo)
creditToParser f v = do
tn <- typename f
let parser :: Text -> Conversion (RowParser CreditTo)
parser tname = pure $ case tname of
"credit_to_btc_addr" -> CreditToAddress <$> (fieldWith btcAddrParser <* nullField <* nullField)
"credit_to_user" -> CreditToUser <$> (nullField *> fieldWith uidParser <* nullField)
"credit_to_project" -> CreditToProject <$> (nullField *> nullField *> fieldWith pidParser)
_ -> empty
case tn of
"credit_to_t" -> maybe empty (parser . decodeUtf8) v
_ -> conversionError $
Incompatible
(B.unpack tn)
(tableOid f)
(maybe "" B.unpack (name f))
"RowParser CreditTo"
"column was not of type event_t"
"SELECT project_id, user_id, btc_addr, event_type, event_time, event_metadata FROM work_events \
"SELECT project_id, user_id, \
\credit_to_type, credit_to_btc_addr, credit_to_user_id, credit_to_project_id, \
\event_type, event_time, event_metadata FROM work_events \
creditToJSON (CreditToAddress addr) = v2 $ object [ "creditToAddress" .= addr ]
creditToJSON (CreditToUser uid) = v2 $ object [ "creditToUser" .= (uid ^. _UserId) ]
creditToJSON (CreditToAddress addr) = v2 $ object [ "creditToAddress" .= (addr ^. _BtcAddr) ]
creditToJSON (CreditToUser uid) = v2 $ object [ "creditToUser" .= tshow (uid ^. _UserId) ]
payoutsJSON (Payouts m) = v1 $
toJSON $ (creditToJSON *** id) <$> MS.assocs m
payoutsJSON (Payouts m) = v2 $
let payoutsRec :: (CreditTo, Rational) -> Value
payoutsRec (c, r) = object [ "creditTo" .= creditToJSON c
, "payoutRatio" .= r
]
in toJSON $ fmap payoutsRec (MS.assocs m)
workIndexJSONV1 :: WorkIndex -> Value
workIndexJSONV1 (WorkIndex widx) = v1 $
toJSON $ (L.toList . fmap intervalJSON) <$>
MS.mapKeysMonotonic (^? (_CreditToAddress._BtcAddr)) widx
workIndexJSON :: WorkIndex -> Value
workIndexJSON (WorkIndex widx) = v2 $
let widxRec :: (CreditTo, NonEmpty Interval) -> Value
widxRec (c, l) = object [ "creditTo" .= creditToJSON c
, "intervals" .= (intervalJSON <$> L.toList l)
]
in toJSON $ fmap widxRec (MS.assocs widx)
parsePayoutsJSON = unv1 "payouts" $ \v ->
Payouts . MS.mapKeys (CreditToAddress . BtcAddr) <$> parseJSON v
parsePayoutsJSON = unversion $ \ver -> case ver of
(Version 1 _) -> \v -> Payouts . MS.mapKeys (CreditToAddress . BtcAddr) <$> parseJSON v
(Version 2 0) -> \v -> do
xs <- parseJSON v
let parsePayoutRecord x = (,) <$> (parseCreditTo =<< (x .: "creditTo"))
<*> x .: "payoutRatio"
Payouts . MS.fromList <$> traverse parsePayoutRecord xs
_ -> badVersion "Payouts" ver