f-o-a-m / kepler

A Haskell framework that facilitates writing ABCI applications
https://kepler.dev
Apache License 2.0
34 stars 9 forks source link

Bank module #197

Closed IvantheTricourne closed 4 years ago

IvantheTricourne commented 4 years ago

Closes #189.

IvantheTricourne commented 4 years ago

Currently only missing the ability to do a custom query (i.e., w/ query params) to get balances for accounts.

IvantheTricourne commented 4 years ago

EDIT: Resolved. HttpApiData codecs now use proper text formatting.

Current issue:

HttpApiData codecs aren't working as intended

λ> let addr = Address "8148e31f7f9bce0cc5a38192116799aa4558e80f"
λ> (HasCodec.decode . HasCodec.encode $ addr) :: Either Text Address
Right (Address HexString "0x8148e31f7f9bce0cc5a38192116799aa4558e80f") -- correct
λ> (parseQueryParam . toQueryParam $ addr) :: Either Text Address
Right (Address HexString "0xefbfbd48efbfbd1f7fefbfbdefbfbd0cc5a3efbfbdefbfbd1167efbfbdefbfbd4558efbfbd0f")

This leads me to believe that cs resolves into something that doesn't work, given that these codecs are defined based on HasCodec instances of the Address type.

instance HasCodec Address where
  decode = Right . addressFromBytes
  encode = addressToBytes
instance ToHttpApiData Address where
  toQueryParam = cs . HasCodec.encode
instance FromHttpApiData Address where
  parseQueryParam = HasCodec.decode . cs

EDIT: cs resolves to the following:

instance ConvertibleStrings StrictText StrictByteString where
    convertString = Data.Text.Encoding.encodeUtf8
instance ConvertibleStrings StrictByteString StrictText where
    convertString = Data.Text.Encoding.decodeUtf8With Data.Text.Encoding.Error.lenientDecode
IvantheTricourne commented 4 years ago

Closing until #200 is merged into master.