Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #123 from input-output-hk/ksaric/CAD-2177
Browse files Browse the repository at this point in the history
[CAD-2177] smash should work also with pool_ids in Bech32 format.
  • Loading branch information
ksaric committed Nov 24, 2020
2 parents 199b1d7 + 9ce639e commit 0180604
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion smash-servant-types/src/Cardano/SMASH/Types.hs
Expand Up @@ -143,16 +143,27 @@ instance FromHttpApiData TickerName where
-- The underlying DB representation is HEX.
instance FromHttpApiData PoolId where
parseUrlPiece poolId =
case pHexStakePoolId poolId of
case pBech32OrHexStakePoolId poolId of
Nothing -> Left "Unable to parse pool id. Wrong format."
Just poolId' -> Right . PoolId . decodeUtf8 . B16.encode . serialiseToRawBytes $ poolId'

where
-- bech32 pool <<< e5cb8a89cabad2cb22ea85423bcbbe270f292be3dbe838948456d3ae
-- bech32 <<< pool1uh9c4zw2htfvkgh2s4prhja7yu8jj2lrm05r39yy2mf6uqqegn6
pBech32OrHexStakePoolId :: Text -> Maybe (Hash StakePoolKey)
pBech32OrHexStakePoolId str = pBech32StakePoolId str <|> pHexStakePoolId str

-- e5cb8a89cabad2cb22ea85423bcbbe270f292be3dbe838948456d3ae
pHexStakePoolId :: Text -> Maybe (Hash StakePoolKey)
pHexStakePoolId =
deserialiseFromRawBytesHex (AsHash AsStakePoolKey) . BSC.pack . toS

-- pool1uh9c4zw2htfvkgh2s4prhja7yu8jj2lrm05r39yy2mf6uqqegn6
pBech32StakePoolId :: Text -> Maybe (Hash StakePoolKey)
pBech32StakePoolId =
either (const Nothing) Just
. deserialiseFromBech32 (AsHash AsStakePoolKey)

instance ToSchema PoolMetadataHash where
declareNamedSchema _ =
return $ NamedSchema (Just "PoolMetadataHash") $ mempty
Expand Down

0 comments on commit 0180604

Please sign in to comment.