Skip to content

Commit f5d418a

Browse files
martyallsafareli
authored andcommitted
tests pass (#131)
1 parent c28f3b3 commit f5d418a

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/Network/Ethereum/Web3/Solidity/AbiEncoding.purs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import Network.Ethereum.Web3.Solidity.UInt (UIntN, unUIntN, uIntNFromBigNumber)
2121
import Network.Ethereum.Web3.Solidity.Vector (Vector)
2222
import Partial.Unsafe (unsafePartial)
2323
import Text.Parsing.Parser (ParseError, Parser, ParserT, fail, runParser)
24-
import Text.Parsing.Parser.Token (hexDigit)
24+
import Text.Parsing.Parser.String (anyChar)
2525

2626
-- | Class representing values that have an encoding and decoding instance to/from a solidity type.
2727
class ABIEncode a where
2828
toDataBuilder :: a -> HexString
2929

3030
class ABIDecode a where
31-
fromDataParser :: Parser String a
31+
fromDataParser :: Parser HexString a
3232

3333
instance abiEncodeAlgebra :: ABIEncode BigNumber where
3434
toDataBuilder = int256HexBuilder
@@ -38,7 +38,7 @@ instance abiDecodeAlgebra :: ABIDecode BigNumber where
3838

3939
-- | Parse encoded value, droping the leading `0x`
4040
fromData :: forall a . ABIDecode a => HexString -> Either ParseError a
41-
fromData = flip runParser fromDataParser <<< unHex
41+
fromData = flip runParser fromDataParser
4242

4343
instance abiEncodeBool :: ABIEncode Boolean where
4444
toDataBuilder = uInt256HexBuilder <<< fromBool
@@ -156,11 +156,11 @@ uInt256HexBuilder x =
156156
in padLeft x'
157157

158158
-- | Parse as a signed `BigNumber`
159-
int256HexParser :: forall m . Monad m => ParserT String m BigNumber
159+
int256HexParser :: forall m . Monad m => ParserT HexString m BigNumber
160160
int256HexParser = toBigNumberFromSignedHexString <$> take 64
161161

162162
-- | Parse an unsigned `BigNumber`
163-
uInt256HexParser :: forall m . Monad m => ParserT String m BigNumber
163+
uInt256HexParser :: forall m . Monad m => ParserT HexString m BigNumber
164164
uInt256HexParser = toBigNumber <$> take 64
165165

166166
-- | Decode a `Boolean` as a BigNumber
@@ -172,5 +172,5 @@ toBool :: BigNumber -> Boolean
172172
toBool bn = not $ bn == zero
173173

174174
-- | Read any number of HexDigits
175-
take :: forall m . Monad m => Int -> ParserT String m HexString
176-
take n = unsafePartial fromJust <<< mkHexString <<< fromCharArray <$> replicateA n hexDigit
175+
take :: forall m . Monad m => Int -> ParserT HexString m HexString
176+
take n = unsafePartial fromJust <<< mkHexString <<< fromCharArray <$> replicateA n anyChar

src/Network/Ethereum/Web3/Solidity/Generic.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Record as Record
3030
import Data.Symbol (class IsSymbol, SProxy(..))
3131
import Network.Ethereum.Web3.Solidity.AbiEncoding (class ABIDecode, class ABIEncode, fromDataParser, take, toDataBuilder)
3232
import Network.Ethereum.Web3.Solidity.EncodingType (class EncodingType, isDynamic)
33-
import Network.Ethereum.Core.HexString (HexString, hexLength, unHex)
33+
import Network.Ethereum.Core.HexString (HexString, hexLength)
3434
import Network.Ethereum.Core.BigNumber (unsafeToInt)
3535
import Text.Parsing.Parser (ParseError, ParseState(..), Parser, runParser)
3636
import Text.Parsing.Parser.Combinators (lookAhead)
@@ -45,7 +45,7 @@ class GenericABIEncode a where
4545

4646
-- | A class for decoding generically composed datatypes from their abi encoding
4747
class GenericABIDecode a where
48-
genericFromDataParser :: Parser String a
48+
genericFromDataParser :: Parser HexString a
4949

5050
-- | An internally used type for encoding
5151
data EncodedValue =
@@ -156,24 +156,24 @@ instance abiDecodeConstructor :: GenericABIDecode a => GenericABIDecode (Constru
156156
genericABIDecode :: forall a rep.
157157
Generic a rep
158158
=> GenericABIDecode rep
159-
=> Parser String a
159+
=> Parser HexString a
160160
genericABIDecode = to <$> genericFromDataParser
161161

162162
genericFromData :: forall a rep.
163163
Generic a rep
164164
=> GenericABIDecode rep
165165
=> HexString
166166
-> Either ParseError a
167-
genericFromData = flip runParser genericABIDecode <<< unHex
167+
genericFromData = flip runParser genericABIDecode
168168

169169
-- helpers
170170

171-
factorParser :: forall a . ABIDecode a => EncodingType a => Parser String a
171+
factorParser :: forall a . ABIDecode a => EncodingType a => Parser HexString a
172172
factorParser
173173
| not $ isDynamic (Proxy :: Proxy a) = fromDataParser
174174
| otherwise = dParser
175175

176-
dParser :: forall a . ABIDecode a => Parser String a
176+
dParser :: forall a . ABIDecode a => Parser HexString a
177177
dParser = do
178178
dataOffset <- unsafeToInt <$> fromDataParser
179179
lookAhead $ do

0 commit comments

Comments
 (0)