Skip to content

Commit

Permalink
merge: f-o-a-m#64
Browse files Browse the repository at this point in the history
  • Loading branch information
srghma committed Feb 15, 2022
1 parent b5da6f7 commit 465b886
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
25 changes: 25 additions & 0 deletions abi-data/abis/ReceiveImplemented.json
Original file line number Diff line number Diff line change
@@ -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/Web3Generator/AbiParser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,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 _ = do
pure $ SolidityReceive

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

derive instance genericAbiType :: Generic AbiType _

Expand All @@ -343,6 +355,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
3 changes: 2 additions & 1 deletion src/Web3Generator/Generator.purs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ instance Monad m => Code (Abi Identity) m where
in
codegenFunction f
AbiFallback _ -> pure []
AbiReceive _ -> pure []
pure $ concat codes
where
codegenFunction f = do
Expand Down Expand Up @@ -690,4 +691,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 465b886

Please sign in to comment.