Skip to content

Commit

Permalink
1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed Jan 31, 2020
1 parent 95fecee commit 1a6bad4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for Bag of Holding

## 1.4.1 (2020-01-31)

`boh poll` now takes any number of transaction IDs as raw arguments, and
processes them all. The `--tx` flag is no longer needed.

## 1.4.0 (2020-01-31)

**New Command:** `boh poll` to easily query the result of a Transaction.
Expand Down
2 changes: 1 addition & 1 deletion bag-of-holding.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: bag-of-holding
version: 1.4.0
version: 1.4.1
synopsis: A terminal-based wallet for Chainweb.
description: A terminal-based wallet for Chainweb.
homepage: https://github.com/kadena-community/bag-of-holding
Expand Down
4 changes: 2 additions & 2 deletions exec/BOH/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ pCommand = hsubparser
<> command "wallet" (info (UI <$> pArgs) (progDesc "Open the Bag of Holding Wallet UI"))
<> command "poll" (info (Poll <$> pPollArgs) (progDesc "Get the result of a /listen call"))

data PollArgs = PollArgs ChainwebVersion BaseUrl P.ChainId BL.ByteString
data PollArgs = PollArgs ChainwebVersion BaseUrl P.ChainId [BL.ByteString]

pPollArgs :: Parser PollArgs
pPollArgs = PollArgs
<$> pVersion
<*> pUrl
<*> strOption (long "chain" <> help "Chain that the transaction was sent to")
<*> strOption (long "tx" <> help "Transaction ID for which to query the result")
<*> some (strArgument (metavar "TXID" <> help "Transaction ID for which to query the result."))

-- | Wallet UI arguments.
data UIArgs = UIArgs ChainwebVersion FilePath Account BaseUrl
Expand Down
36 changes: 25 additions & 11 deletions exec/BOH/Poll.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ import Servant.Client
---

pollOnKey :: PollArgs -> IO ()
pollOnKey (PollArgs v u cid k) = case decode' ("\"" <> k <> "\"") of
Nothing -> BL.putStrLn "Illegal Transaction ID"
Just k' -> do
m <- newManager tlsManagerSettings
let !cenv = ClientEnv m u Nothing
runClientM (poll v cid $ Receipt k') cenv >>= \case
Left _ -> BL.putStrLn "Lookup failure." >> exitFailure
Right (Just res) -> BL.putStrLn . encodePretty $ txr res
Right Nothing -> do
BL.putStrLn "That transaction doesn't exist, or hasn't completed yet."
exitFailure
pollOnKey (PollArgs v u cid ks) = do
m <- newManager tlsManagerSettings
let !cenv = ClientEnv m u Nothing
rs <- traverse (f cenv) ks
traverse_ g rs
case sequenceA rs of
Left _ -> exitFailure
Right _ -> pure ()
where
-- | Make a Pact @/poll@ call on the user's input.
f :: ClientEnv -> BL.ByteString -> IO (Either BL.ByteString TXResult)
f cenv k = case decode' ("\"" <> k <> "\"") of
Nothing -> pure . Left $ "Illegal Transaction ID: " <> k
Just k' -> h k <$> runClientM (poll v cid $ Receipt k') cenv

-- | Process the results of the HTTP call.
h :: BL.ByteString -> Either a (Maybe b) -> Either BL.ByteString b
h k (Left _) = Left $ "Lookup failure: " <> k
h _ (Right (Just res)) = Right res
h k (Right Nothing) = Left $ k <> " doesn't exist, or hasn't completed yet."

-- | Report the results of the post-processing.
g :: Either BL.ByteString TXResult -> IO ()
g (Left e) = BL.putStrLn e
g (Right r) = BL.putStrLn . encodePretty $ txr r

0 comments on commit 1a6bad4

Please sign in to comment.