Skip to content

Commit

Permalink
Merge branch 'patch-1' into tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
srghma committed Feb 2, 2022
2 parents 54eba51 + 765bd7c commit 5c8705d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
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 @@ -316,6 +316,17 @@ instance decodeJsonSolidityFallback :: DecodeJson SolidityFallback where
decodeJson _ = 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 @@ -325,6 +336,7 @@ data AbiType
| AbiConstructor SolidityConstructor
| AbiEvent SolidityEvent
| AbiFallback SolidityFallback
| AbiReceive SolidityReceive

derive instance genericAbiType :: Generic AbiType _

Expand All @@ -341,6 +353,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

newtype Abi f = Abi (Array (f AbiType))
Expand Down
6 changes: 5 additions & 1 deletion src/Data/Generator.purs
Expand Up @@ -621,7 +621,11 @@ instance Monad m => Code (Abi Identity) m where
}
in
codegenFunction f
-- 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 $ concat codes
where
codegenFunction f = do
Expand Down Expand Up @@ -669,4 +673,4 @@ eventId (SolidityEvent e) =
let
eventArgs = map (\a -> format a) e.inputs
in
fromByteString $ keccak256 $ e.name <> "(" <> joinWith "," eventArgs <> ")"
fromByteString $ keccak256 $ e.name <> "(" <> joinWith "," eventArgs <> ")"

0 comments on commit 5c8705d

Please sign in to comment.