mJsonBsToCommand :: BLC.ByteString -> Maybe BSC.ByteString
mJsonBsToCommand bs = JSON.decode bs >>= \v ->
                      (mAdjustAccount <$> tryParse v) <|>
                      (mAdjustCreateAcct <$> tryParse v) <|>
                      (mtransact <$> tryParse v)
  where

    tryParse v = parseMaybe parseJSON v

    mAdjustAccount (AccountAdjustPayload acct amt) =
        let JRational r = amt
        in BSC.pack $ "AdjustAccount " ++  T.unpack acct ++ " " ++ show r

    mAdjustCreateAcct (AccountPayload acct) =
        BSC.pack $ "CreateAccount " ++  T.unpack acct

    mtransact (TransactBody code _) =
        BSC.pack $ T.unpack code


--
mJsonBsToCommand :: BLC.ByteString -> Maybe BSC.ByteString
mJsonBsToCommand bs = JSON.decode bs >>= \v ->
                      (mAdjustAccount <$> tryParse v) <|>
                      (mAdjustCreateAcct <$> tryParse v) <|>
                      (mtransact <$> tryParse v)
  where

    tryParse v = parseMaybe parseJSON v

    mAdjustAccount (AccountAdjustPayload acct amt) =
        let JRational r = amt
        in BSC.pack $ "AdjustAccount " ++  T.unpack acct ++ " " ++ show r

    mAdjustCreateAcct (AccountPayload acct) =
        BSC.pack $ "CreateAccount " ++  T.unpack acct

    mtransact (TransactBody code _) =
        BSC.pack $ T.unpack code


--
mJsonBsToCommand bs = JSON.decode bs >>= \v ->
                      (mAdjustAccount <$> tryParse v) <|>
                      (mAdjustCreateAcct <$> tryParse v) <|>
                      (mtransact <$> tryParse v)
  where

    tryParse v = parseMaybe parseJSON v

    mAdjustAccount (AccountAdjustPayload acct amt) =
        let JRational r = amt
        in BSC.pack $ "AdjustAccount " ++  T.unpack acct ++ " " ++ show r

    mAdjustCreateAcct (AccountPayload acct) =
        BSC.pack $ "CreateAccount " ++  T.unpack acct

    mtransact (TransactBody code _) =
        BSC.pack $ T.unpack code


--