From 38629d4528aad26c32e78fb6f2d5f1ced571ae22 Mon Sep 17 00:00:00 2001 From: Jacques Wagener Date: Wed, 6 Nov 2019 17:19:38 +0200 Subject: [PATCH] Add check for payable default func. --- examples/default_func.nim | 2 +- examples/erc20.nim | 2 +- nimplay/nimplay_macros.nim | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/default_func.nim b/examples/default_func.nim index a17cc45..56f6f45 100644 --- a/examples/default_func.nim +++ b/examples/default_func.nim @@ -3,5 +3,5 @@ import ../nimplay0_1 contract("Default"): - proc default*() {.payable.} = + proc default*() = discard diff --git a/examples/erc20.nim b/examples/erc20.nim index c95982d..9244457 100644 --- a/examples/erc20.nim +++ b/examples/erc20.nim @@ -7,7 +7,7 @@ contract("NimCoin"): name*: bytes32 symbol*: bytes32 decimals*: uint256 - total_supply*: uint256 + total_supply: uint256 minter*: address initialised: bool diff --git a/nimplay/nimplay_macros.nim b/nimplay/nimplay_macros.nim index 780e2b6..733af1f 100644 --- a/nimplay/nimplay_macros.nim +++ b/nimplay/nimplay_macros.nim @@ -62,7 +62,7 @@ proc get_local_output_type_conversion(tmp_result_name, tmp_result_converted_name var ident_node = newIdentNode(tmp_result_converted_name) var conversion_node = parseStmt(unindent(fmt""" var {tmp_result_converted_name}: array[32, byte] - if tmp_result_name: {tmp_result_converted_name}[31] = 1 + if {tmp_result_name}: {tmp_result_converted_name}[31] = 1 """)) return (ident_node, conversion_node) of "uint256": @@ -550,7 +550,13 @@ proc handle_contract_interface(in_stmts: NimNode): NimNode = # Add default function. var default_func_node: NimNode if global_ctx.has_default_func: - default_func_node = parseStmt(unindent(""" + var + default_fsig = filter( + function_signatures, proc(x: FunctionSignature): bool = x.name == "default" + )[0] + assert_payable_str = if default_fsig.payable: "assertNotPayable()" else: "" + default_func_node = parseStmt(unindent(fmt""" + {assert_payable_str} default() finish(nil, 0) """))