-- |
-- Module      :  Data.Solidity.Prim.String
-- Copyright   :  Aleksandr Krupenkin 2016-2021
-- License     :  Apache-2.0
--
-- Maintainer  :  mail@akru.me
-- Stability   :  experimental
-- Portability :  noportable
--
-- Ethereum Abi UTF8-encoded string type.
--

module Data.Solidity.Prim.String where

import           Data.Text                (Text)
import           Data.Text.Encoding       (decodeUtf8, encodeUtf8)

import           Data.Solidity.Abi        (AbiGet (..), AbiPut (..),
                                           AbiType (..))
import           Data.Solidity.Prim.Bytes ()

instance AbiType Text where
    isDynamic :: Proxy Text -> Bool
isDynamic Proxy Text
_ = Bool
True

instance AbiPut Text where
    abiPut :: Putter Text
abiPut = Putter ByteString
forall a. AbiPut a => Putter a
abiPut Putter ByteString -> (Text -> ByteString) -> Putter Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
encodeUtf8

instance AbiGet Text where
    abiGet :: Get Text
abiGet = ByteString -> Text
decodeUtf8 (ByteString -> Text) -> Get ByteString -> Get Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get ByteString
forall a. AbiGet a => Get a
abiGet