Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for contracts that implement receive #64

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions abi-data/abis/ReceiveImplemented.json
@@ -0,0 +1,25 @@
[
{
"constant": false,
"inputs": [
{
"name": "x",
"type": "uint256"
}
],
"name": "simpleFunction",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
13 changes: 13 additions & 0 deletions src/Data/AbiParser.purs
Expand Up @@ -308,6 +308,17 @@ instance decodeJsonSolidityFallback :: DecodeJson SolidityFallback where
decodeJson json = do
pure $ SolidityFallback

data SolidityReceive = SolidityReceive

derive instance genericSolidityReceive :: Generic SolidityReceive _

instance showSolidityReceive :: Show SolidityReceive where
show = genericShow

instance decodeJsonSolidityReceive :: DecodeJson SolidityReceive where
decodeJson json = do
pure $ SolidityReceive

--------------------------------------------------------------------------------
-- | ABI
--------------------------------------------------------------------------------
Expand All @@ -317,6 +328,7 @@ data AbiType =
| AbiConstructor SolidityConstructor
| AbiEvent SolidityEvent
| AbiFallback SolidityFallback
| AbiReceive SolidityReceive

derive instance genericAbiType :: Generic AbiType _

Expand All @@ -333,6 +345,7 @@ instance decodeJsonAbiType :: DecodeJson AbiType where
"constructor" -> AbiConstructor <$> decodeJson json'
"event" -> AbiEvent <$> decodeJson json'
"fallback" -> AbiFallback <$> decodeJson json'
"receive" -> AbiReceive <$> decodeJson json'
_ -> Left $ Named "Unkown abi type" $ UnexpectedValue json


Expand Down
7 changes: 3 additions & 4 deletions src/Data/CodeGen.purs
Expand Up @@ -180,10 +180,9 @@ maybeAnnotateArity abi =
go (SolidityFunction f) = SolidityFunction f {name = f.name <> show (length f.inputs)}

parseAbi :: forall r. {truffle :: Boolean | r} -> Json -> Either String AbiWithErrors
parseAbi {truffle} abiJson = case truffle of
false -> lmap printJsonDecodeError $ decodeJson abiJson
true -> let mabi = abiJson ^? _Object <<< ix "abi"
in note "truffle artifact missing abi field" mabi >>= \json -> lmap printJsonDecodeError $ decodeJson json
parseAbi _ abiJson = case abiJson ^? _Object <<< ix "abi" of
Nothing -> lmap printJsonDecodeError $ decodeJson abiJson
Just json -> lmap printJsonDecodeError $ decodeJson json

genPSModuleStatement :: GeneratorOptions -> FilePath -> String
genPSModuleStatement opts fp = comment <> "\n"
Expand Down
10 changes: 5 additions & 5 deletions src/Data/Generator.purs
Expand Up @@ -638,9 +638,9 @@ instance codeAbi :: Code (Abi Identity) where
}
functionCodeBlock <- funToFunctionCodeBlock f opts
genCode functionCodeBlock opts
AbiFallback _ ->
-- Fallback is a function that gets called in case someone
-- sends ether to the contract with no function specified
-- so it's like, you would never call it on purpose, so we ignore it.
pure ""
-- Fallback and Receive are functions that get called in case someone
-- sends ether to the contract with no function specified
-- so it's like, you would never call it on purpose, so we ignore it.
AbiFallback _ -> pure ""
AbiReceive _ -> pure ""
pure $ newLine2 codes