Skip to content

Commit

Permalink
added evm versions, removed named instances
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Sep 22, 2023
1 parent d2d34f8 commit 61f6fc2
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 133 deletions.
16 changes: 8 additions & 8 deletions src/Language/Solidity/Compiler/Releases.purs
Expand Up @@ -39,14 +39,14 @@ data Build
= Stable (BuildR ())
| Prerelease (BuildR (prerelease :: String))

derive instance genericBuild :: Generic Build _
instance showBuild :: Show Build where
derive instance Generic Build _
instance Show Build where
show = genericShow

instance decodeJsonBuild :: DecodeJson Build where
instance DecodeJson Build where
decodeJson j = Prerelease <$> decodeJson j <|> Stable <$> decodeJson j

instance encodeJsonBuild :: EncodeJson Build where
instance EncodeJson Build where
encodeJson (Stable s) = encodeJson s
encodeJson (Prerelease s) = encodeJson s

Expand All @@ -57,10 +57,10 @@ newtype ReleaseList =
, latestRelease :: String
}

derive instance genericReleaseList :: Generic ReleaseList _
derive newtype instance decodeJsonReleaseList :: DecodeJson ReleaseList
derive newtype instance encodeJsonReleaseList :: EncodeJson ReleaseList
instance showReleaseList :: Show ReleaseList where
derive instance Generic ReleaseList _
derive newtype instance DecodeJson ReleaseList
derive newtype instance EncodeJson ReleaseList
instance Show ReleaseList where
show = genericShow

newtype ReleaseRepo =
Expand Down
14 changes: 7 additions & 7 deletions src/Language/Solidity/Compiler/Types/Common.purs
Expand Up @@ -26,20 +26,20 @@ flattenOptionalArray rs = if Array.null rs then Nothing else Just rs
--- Some fields are strings which are really JSON
newtype Strung a = Strung a

derive newtype instance eqStrung :: Eq a => Eq (Strung a)
derive newtype instance ordStrung :: Ord a => Ord (Strung a)
derive newtype instance semigroupStrung :: Semigroup a => Semigroup (Strung a)
derive newtype instance monoidStrung :: Monoid a => Monoid (Strung a)
derive newtype instance Eq a => Eq (Strung a)
derive newtype instance Ord a => Ord (Strung a)
derive newtype instance Semigroup a => Semigroup (Strung a)
derive newtype instance Monoid a => Monoid (Strung a)

derive instance newtypeStrung :: Newtype (Strung a) _
derive instance Newtype (Strung a) _

instance decodeJsonStrung :: DecodeJson a => DecodeJson (Strung a) where
instance DecodeJson a => DecodeJson (Strung a) where
decodeJson j =
decodeJson j
>>= (lmap TypeMismatch <<< jsonParser)
>>= decodeJson
>>=
pure <<< Strung

instance encodeJsonStrung :: EncodeJson a => EncodeJson (Strung a) where
instance EncodeJson a => EncodeJson (Strung a) where
encodeJson (Strung a) = fromString <<< stringify $ encodeJson a
28 changes: 14 additions & 14 deletions src/Language/Solidity/Compiler/Types/Input.purs
Expand Up @@ -22,16 +22,16 @@ import Language.Solidity.Compiler.Types.Settings (class IsSelection, CompilerSet
--- "language" field of input
data SourceLanguage = Solidity | Yul

derive instance eqSourceLanguage :: Eq SourceLanguage
derive instance ordSourceLanguage :: Ord SourceLanguage
derive instance Eq SourceLanguage
derive instance Ord SourceLanguage

instance decodeJsonSourceLanguage :: DecodeJson SourceLanguage where
instance DecodeJson SourceLanguage where
decodeJson j = decodeJson j >>= case _ of
"Solidity" -> pure Solidity
"Yul" -> pure Yul
x -> Left $ Named ("Unknown source language " <> x) $ UnexpectedValue j

instance encodeJsonSourceLanguage :: EncodeJson SourceLanguage where
instance EncodeJson SourceLanguage where
encodeJson = A.fromString <<< case _ of
Solidity -> "Solidity"
Yul -> "Yul"
Expand All @@ -49,10 +49,10 @@ data Source
, content :: String
}

derive instance eqSource :: Eq Source
derive instance ordSource :: Ord Source
derive instance Eq Source
derive instance Ord Source

instance encodeJsonSource :: EncodeJson Source where
instance EncodeJson Source where
encodeJson (FromURLs u) =
"urls" := u.urls
~> "keccak256" :=? u.keccak256
Expand All @@ -62,10 +62,10 @@ instance encodeJsonSource :: EncodeJson Source where

newtype Sources = Sources (FO.Object Source)

derive instance newtypeSources :: Newtype Sources _
derive newtype instance encodeJsonSources :: EncodeJson Sources
derive newtype instance eqSources :: Eq Sources
derive newtype instance ordSources :: Ord Sources
derive instance Newtype Sources _
derive newtype instance EncodeJson Sources
derive newtype instance Eq Sources
derive newtype instance Ord Sources

--------------------------------------------------
--- the input object itself
Expand All @@ -76,10 +76,10 @@ newtype CompilerInput = CompilerInput
, settings :: Maybe CompilerSettings
}

derive instance eqCompilerInput :: Eq CompilerInput
derive instance ordCompilerInput :: Ord CompilerInput
derive instance Eq CompilerInput
derive instance Ord CompilerInput

instance encodeJsonCompilerInput :: EncodeJson CompilerInput where
instance EncodeJson CompilerInput where
encodeJson (CompilerInput i) =
"language" := i.language
~> "sources" := i.sources
Expand Down
110 changes: 55 additions & 55 deletions src/Language/Solidity/Compiler/Types/Output.purs
Expand Up @@ -91,10 +91,10 @@ instance decodeJsonErrorType :: DecodeJson ErrorType where

data ErrorSeverity = SeverityError | SeverityWarning

derive instance eqErrorSeverity :: Eq ErrorSeverity
derive instance ordErrorSeverity :: Ord ErrorSeverity
derive instance Eq ErrorSeverity
derive instance Ord ErrorSeverity

instance decodeJsonErrorSeverity :: DecodeJson ErrorSeverity where
instance DecodeJson ErrorSeverity where
decodeJson o = decodeJson o >>= case _ of
"error" -> pure SeverityError
"warning" -> pure SeverityWarning
Expand All @@ -109,8 +109,8 @@ newtype SourceLocation = SourceLocation
, message :: Maybe String
}

derive instance eqSourceLocation :: Eq SourceLocation
derive instance ordSourceLocation :: Ord SourceLocation
derive instance Eq SourceLocation
derive instance Ord SourceLocation

instance showSourceLocation :: Show SourceLocation where
show (SourceLocation sl) =
Expand All @@ -119,7 +119,7 @@ instance showSourceLocation :: Show SourceLocation where
in
sl.file <> ":" <> show sl.start <> "-" <> show sl.end <> msg

instance decodeJsonSourceLocation :: DecodeJson SourceLocation where
instance DecodeJson SourceLocation where
decodeJson j = do
o <- decodeJson j
file <- o .: "file"
Expand All @@ -143,10 +143,10 @@ data CompilationError
, secondarySourceLocations :: Array SourceLocation
}

derive instance eqCompilationError :: Eq CompilationError
derive instance ordCompilationError :: Ord CompilationError
derive instance Eq CompilationError
derive instance Ord CompilationError

instance decodeJsonCompilationError :: DecodeJson CompilationError where
instance DecodeJson CompilationError where
decodeJson j = (SimpleCompilationError <$> decodeJson j) <|> (decodeAsObject =<< decodeJson j)
where
decodeAsObject o = do
Expand Down Expand Up @@ -176,10 +176,10 @@ newtype SourceLevelOutput = SourceLevelOutput
, legacyAST :: Maybe A.Json
}

derive instance eqSourceLevelOutput :: Eq SourceLevelOutput
derive instance ordSourceLevelOutput :: Ord SourceLevelOutput
derive instance Eq SourceLevelOutput
derive instance Ord SourceLevelOutput

instance decodeJsonSourceLevelOutput :: DecodeJson SourceLevelOutput where
instance DecodeJson SourceLevelOutput where
decodeJson j = do
o <- decodeJson j
id <- o .: "id"
Expand All @@ -191,13 +191,13 @@ instance decodeJsonSourceLevelOutput :: DecodeJson SourceLevelOutput where
--- "contracts{}{}.evm.{deployedBytecode, bytecode}.object" field of output
data BytecodeObject = BytecodeHexString HexString | BytecodeUnlinked String

derive instance eqBytecodeObject :: Eq BytecodeObject
derive instance ordBytecodeObject :: Ord BytecodeObject
derive instance Eq BytecodeObject
derive instance Ord BytecodeObject

instance decodeJsonBytecodeObject :: DecodeJson BytecodeObject where
instance DecodeJson BytecodeObject where
decodeJson = map mkBytecodeObject <<< decodeJson

instance encodeJsonBytecodeObject :: EncodeJson BytecodeObject where
instance EncodeJson BytecodeObject where
encodeJson = encodeJson <<< unBytecodeObject

mkBytecodeObject :: String -> BytecodeObject
Expand All @@ -215,28 +215,28 @@ data LinkReference = LinkReference
, length :: Int
}

derive instance eqLinkReference :: Eq LinkReference
derive instance ordLinkReference :: Ord LinkReference
derive instance Eq LinkReference
derive instance Ord LinkReference

instance decodeJsonLinkReference :: DecodeJson LinkReference where
instance DecodeJson LinkReference where
decodeJson j = do
o <- decodeJson j
start <- o .: "start"
length <- o .: "length"
pure $ LinkReference { start, length }

instance encodeJsonLinkReference :: EncodeJson LinkReference where
instance EncodeJson LinkReference where
encodeJson (LinkReference { start, length }) =
"start" := start
~> "length" := length
~> jsonEmptyObject

newtype LinkReferences = LinkReferences (FileMapped (ContractMapped (Array LinkReference)))

derive instance newtypeLinkReferences :: Newtype LinkReferences _
derive newtype instance eqLinkReferences :: Eq LinkReferences
derive newtype instance ordLinkReferences :: Ord LinkReferences
derive newtype instance decodeJsonLinkReferences :: DecodeJson LinkReferences
derive instance Newtype LinkReferences _
derive newtype instance Eq LinkReferences
derive newtype instance Ord LinkReferences
derive newtype instance DecodeJson LinkReferences

--------------------------------------------------
--- "contracts{}{}.evm.{deployedBytecode, bytecode}" field of output
Expand All @@ -247,10 +247,10 @@ newtype BytecodeOutput = BytecodeOutput
, linkReferences :: Maybe LinkReferences
}

derive instance eqBytecodeOutput :: Eq BytecodeOutput
derive instance ordBytecodeOutput :: Ord BytecodeOutput
derive instance Eq BytecodeOutput
derive instance Ord BytecodeOutput

instance decodeJsonBytecodeOutput :: DecodeJson BytecodeOutput where
instance DecodeJson BytecodeOutput where
decodeJson j = do
o <- decodeJson j
object <- o .:? "object"
Expand All @@ -263,40 +263,40 @@ instance decodeJsonBytecodeOutput :: DecodeJson BytecodeOutput where
--- "contracts{}{}.evm.methodIdentifiers" field of output
newtype MethodIdentifiers = MethodIdentifiers (FO.Object HexString)

derive instance newtypeMethodIdentifiers :: Newtype MethodIdentifiers _
derive newtype instance eqMethodIdentifiers :: Eq MethodIdentifiers
derive newtype instance ordMethodIdentifiers :: Ord MethodIdentifiers
derive newtype instance decodeJsonMethodIdentifiers :: DecodeJson MethodIdentifiers
derive instance Newtype MethodIdentifiers _
derive newtype instance Eq MethodIdentifiers
derive newtype instance Ord MethodIdentifiers
derive newtype instance DecodeJson MethodIdentifiers

--------------------------------------------------
--- "contracts{}{}.evm.gasEstimates.*" values of output

data GasEstimate = InfiniteGas | GasCount BigNumber

derive instance eqGasEstimate :: Eq GasEstimate
derive instance ordGasEstimate :: Ord GasEstimate
derive instance Eq GasEstimate
derive instance Ord GasEstimate

instance decodeJsonGasEstimate :: DecodeJson GasEstimate where
instance DecodeJson GasEstimate where
decodeJson j = decodeJson j >>= case _ of
"infinite" -> pure InfiniteGas
x -> note (Named "invalid BigNumber" $ UnexpectedValue j) $ GasCount <$> fromStringAs Int.decimal x

newtype GasEstimates = GasEstimates (FO.Object GasEstimate)

derive newtype instance eqGasEstimates :: Eq GasEstimates
derive newtype instance ordGasEstimates :: Ord GasEstimates
derive newtype instance decodeJsonGasEstimates :: DecodeJson GasEstimates
derive newtype instance Eq GasEstimates
derive newtype instance Ord GasEstimates
derive newtype instance DecodeJson GasEstimates

newtype CreationGasEstimates = CreationGasEstimates
{ codeDepositCost :: Maybe GasEstimate
, executionCost :: Maybe GasEstimate
, totalCost :: Maybe GasEstimate
}

derive instance eqCreationGasEstimates :: Eq CreationGasEstimates
derive instance ordCreationGasEstimates :: Ord CreationGasEstimates
derive instance Eq CreationGasEstimates
derive instance Ord CreationGasEstimates

instance decodeJsonCreationGasEstimates :: DecodeJson CreationGasEstimates where
instance DecodeJson CreationGasEstimates where
decodeJson j = do
o <- decodeJson j
codeDepositCost <- o .:? "codeDepositCost"
Expand All @@ -312,10 +312,10 @@ newtype ContractGasEstimates = ContractGasEstimates
, internal :: Maybe (FO.Object GasEstimate)
}

derive instance eqContractGasEstimates :: Eq ContractGasEstimates
derive instance ordContractGasEstimates :: Ord ContractGasEstimates
derive instance Eq ContractGasEstimates
derive instance Ord ContractGasEstimates

instance decodeJsonContractGasEstimates :: DecodeJson ContractGasEstimates where
instance DecodeJson ContractGasEstimates where
decodeJson j = do
o <- decodeJson j
creation <- o .:? "creation"
Expand All @@ -335,10 +335,10 @@ newtype EvmOutput = EvmOutput
, gasEstimates :: Maybe GasEstimates
}

derive instance eqEvmOutput :: Eq EvmOutput
derive instance ordEvmOutput :: Ord EvmOutput
derive instance Eq EvmOutput
derive instance Ord EvmOutput

instance decodeJsonEvmOutput :: DecodeJson EvmOutput where
instance DecodeJson EvmOutput where
decodeJson j = do
o <- decodeJson j
assembly <- o .:? "assembly"
Expand All @@ -363,10 +363,10 @@ newtype EwasmOutput = EwasmOutput
, wasm :: Maybe HexString
}

derive instance eqEwasmOutput :: Eq EwasmOutput
derive instance ordEwasmOutput :: Ord EwasmOutput
derive instance Eq EwasmOutput
derive instance Ord EwasmOutput

instance decodeJsonEwasmOutput :: DecodeJson EwasmOutput where
instance DecodeJson EwasmOutput where
decodeJson j = do
o <- decodeJson j
wast <- o .:? "wast"
Expand All @@ -386,10 +386,10 @@ newtype ContractLevelOutput = ContractLevelOutput
, ewasm :: Maybe EwasmOutput
}

derive instance eqContractLevelOutput :: Eq ContractLevelOutput
derive instance ordContractLevelOutput :: Ord ContractLevelOutput
derive instance Eq ContractLevelOutput
derive instance Ord ContractLevelOutput

instance decodeJsonContractLevelOutput :: DecodeJson ContractLevelOutput where
instance DecodeJson ContractLevelOutput where
decodeJson j = do
o <- decodeJson j
abi <- o .:? "abi"
Expand All @@ -409,10 +409,10 @@ newtype CompilerOutput = CompilerOutput
, contracts :: FileMapped (ContractMapped ContractLevelOutput)
}

derive instance eqCompilerOutput :: Eq CompilerOutput
derive instance ordCompilerOutput :: Ord CompilerOutput
derive instance Eq CompilerOutput
derive instance Ord CompilerOutput

instance decodeJsonCompilerOutput :: DecodeJson CompilerOutput where
instance DecodeJson CompilerOutput where
decodeJson j = do
o <- decodeJson j
errors <- o .:? "errors" .!= []
Expand Down

0 comments on commit 61f6fc2

Please sign in to comment.