From 0ae6411539e43c74814bf44a90028a6acc725bb3 Mon Sep 17 00:00:00 2001 From: Tim Makarios Date: Fri, 4 Apr 2014 20:58:41 +1300 Subject: [PATCH] Correctly handle ripples/drops conversion when adding a currency --- rootstock.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rootstock.hs b/rootstock.hs index d16733d..7051c67 100644 --- a/rootstock.hs +++ b/rootstock.hs @@ -753,10 +753,10 @@ setupDatabase fundLine = do else lineBal addCurrency :: IOULine -> Double -> ExceptionalRootstock () -addCurrency fundLine priceInXRP = do +addCurrency fundLine priceInDrops = do mxrpNodeEntity <- lift $ runSqlQuery $ getBy $ NodeUnique XRP xrpNodeEntity <- maybe (throwError DatabaseNotSetUp) return mxrpNodeEntity - throwIf NonPositivePrice $ priceInXRP <= 0 + throwIf NonPositivePrice $ priceInDrops <= 0 let lineFund = IOUFund fundLine alreadyPresent <- isJust <$> (lift $ runSqlQuery $ getBy $ NodeUnique lineFund) @@ -767,12 +767,13 @@ addCurrency fundLine priceInXRP = do acLines <- lift getAccountLines lineBal <- getLineBal acLines fundLine vs <- lift $ gets valueSimplex - throwIf NewOutweighsOld $ priceInXRP * lineBal >= totalValue vs xrpNodeEntity + throwIf NewOutweighsOld $ + priceInDrops * lineBal >= totalValue vs xrpNodeEntity acInfo <- lift getAccountInfo lift $ runSqlQuery $ do lineNodeEntity <- insertReturnEntity $ Node {nodeFund = lineFund} writeValueSimplex acInfo acLines $ - addNode vs lineNodeEntity lineBal xrpNodeEntity priceInXRP + addNode vs lineNodeEntity lineBal xrpNodeEntity priceInDrops -------------------------------------------------------------------------------- @@ -961,6 +962,6 @@ main = do , lineCurrency = T.pack currency } ) - $ read priceInXRP + $ read priceInXRP * 1000000 _ -> putStrLn "Command not understood" -- 2.11.4.GIT