diff --git a/abi-data/abis/ReceiveImplemented.json b/abi-data/abis/ReceiveImplemented.json new file mode 100644 index 0000000..74053ac --- /dev/null +++ b/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" + } +] diff --git a/src/Data/AbiParser.purs b/src/Data/AbiParser.purs index d5c7a97..ff85d09 100644 --- a/src/Data/AbiParser.purs +++ b/src/Data/AbiParser.purs @@ -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 -------------------------------------------------------------------------------- @@ -317,6 +328,7 @@ data AbiType = | AbiConstructor SolidityConstructor | AbiEvent SolidityEvent | AbiFallback SolidityFallback + | AbiReceive SolidityReceive derive instance genericAbiType :: Generic AbiType _ @@ -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 diff --git a/src/Data/CodeGen.purs b/src/Data/CodeGen.purs index 2a9a1d6..9321697 100644 --- a/src/Data/CodeGen.purs +++ b/src/Data/CodeGen.purs @@ -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" diff --git a/src/Data/Generator.purs b/src/Data/Generator.purs index 65d9105..664759e 100644 --- a/src/Data/Generator.purs +++ b/src/Data/Generator.purs @@ -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