Skip to content

Commit

Permalink
Use addr_test HRP for testnet addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Oct 27, 2020
1 parent 368b9fc commit 6f19081
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -985,20 +985,20 @@ _decodeStakeAddress serverNetwork txt = do
"Unable to decode stake-address: must be a valid bech32 string."

instance EncodeAddress 'Mainnet where
encodeAddress = _encodeAddress
encodeAddress = _encodeAddress [Bech32.humanReadablePart|addr|]

instance EncodeAddress ('Testnet pm) where
encodeAddress = _encodeAddress
-- https://github.com/cardano-foundation/CIPs/tree/master/CIP5
encodeAddress = _encodeAddress [Bech32.humanReadablePart|addr_test|]

_encodeAddress :: W.Address -> Text
_encodeAddress (W.Address bytes) =
_encodeAddress :: Bech32.HumanReadablePart -> W.Address -> Text
_encodeAddress hrp (W.Address bytes) =
if isJust (CBOR.deserialiseCbor CBOR.decodeAddressPayload bytes)
then base58
else bech32
where
base58 = T.decodeUtf8 $ encodeBase58 bitcoinAlphabet bytes
bech32 = Bech32.encodeLenient hrp (dataPartFromBytes bytes)
hrp = [Bech32.humanReadablePart|addr|]

instance DecodeAddress 'Mainnet where
decodeAddress = _decodeAddress SL.Mainnet
Expand Down

0 comments on commit 6f19081

Please sign in to comment.