Skip to content

Commit

Permalink
Add Address32 to EVM.Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
larskuhtz committed Jan 28, 2025
1 parent e8176c5 commit 6db3f9f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Chainweb/PayloadProvider/EVM/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module Chainweb.PayloadProvider.EVM.Utils
( ChainId(..)
, Randao(..)
, BlockValue(..)
, Address32(..)
, toAddress32
, _blockValueStu
, DefaultBlockParameter(..)

Expand Down Expand Up @@ -183,6 +185,28 @@ newtype ChainId = ChainId { _chainId :: Natural }
deriving (Show, Eq, Ord, Generic)
deriving (ToJSON, FromJSON) via (HexQuantity Natural)

-- -------------------------------------------------------------------------- --
-- Address 32

newtype Address32 = Address32 (BytesN 32)
deriving (Show, Eq, Ord)
deriving newtype (RLP, Bytes, Storable)
deriving (FromJSON, ToJSON) via (HexBytes (BytesN 32))

instance HasTextRepresentation Address32 where
toText = toText . HexBytes . bytes
fromText = fmap (Address32 . fromHexBytes) . fromText
{-# INLINE toText #-}
{-# INLINE fromText #-}

toAddress32
:: Address
-> Address32
toAddress32 (Address b) = Address32 (appendN zeroN b)

zeroN :: KnownNat n => BytesN n
zeroN = replicateN 0

-- -------------------------------------------------------------------------- --
-- Randao

Expand Down

0 comments on commit 6db3f9f

Please sign in to comment.