Add support for only handling annoted public functions.

This commit is contained in:
Jacques Wagener 2019-06-27 14:06:51 +02:00
parent 83bc66813e
commit b13f970f96
No known key found for this signature in database
GPG Key ID: C294D1025DA0E923
3 changed files with 32 additions and 11 deletions

View File

@ -23,6 +23,7 @@ type
payable*: bool
method_id*: string
method_sig*: string
is_private*: bool
proc generate_method_sig*(func_sig: FunctionSignature, v2_sig: bool = false): string =
@ -59,6 +60,10 @@ proc generate_function_signature*(proc_def: NimNode): FunctionSignature =
case child.kind:
of nnkIdent:
func_sig.name = strVal(child)
func_sig.is_private = true
of nnkPostfix:
func_sig.name = strVal(child[1])
func_sig.is_private = false
of nnkFormalParams:
for param in child:
case param.kind

View File

@ -4,7 +4,7 @@ import system
import strformat
import tables
import endians
import sequtils
import ./eth_abi_utils, ./builtin_keywords
@ -30,8 +30,12 @@ type
proc get_func_name(proc_def: NimNode): string =
var func_name = ""
for child in proc_def:
if child.kind == nnkPostfix:
func_name = strVal(child[1])
break
if child.kind == nnkIdent:
func_name = strVal(child)
break
return func_name
@ -150,6 +154,14 @@ proc handle_contract_interface(stmts: NimNode): NimNode =
discard
# raise newException(ParserError, ">> Invalid stmt \"" & getTypeInst(child) & "\" not supported in contract block")
echo function_signatures
if filter(function_signatures, proc(x: FunctionSignature): bool = x.is_private).len == 0:
raise newException(
ParserError,
"No public functions have defined, use * postfix to annotate public functions."
)
# Build Main Entrypoint.
var out_stmts = newStmtList()
out_stmts.add(
@ -188,15 +200,12 @@ proc handle_contract_interface(stmts: NimNode): NimNode =
newIdentNode("selector")
)
# selector_CaseStmt.add(newIdentNode("selector"))
# nnkStmtList.newTree(
# nnkCall.newTree(
# newIdentNode("hello"),
# newIdentNode("a")
# )
# )
# Build function selector.
for func_sig in function_signatures:
if func_sig.is_private:
echo "!!!"
continue
echo "Building " & func_sig.method_sig
var call_and_copy_block = nnkStmtList.newTree()
var call_to_func = nnkCall.newTree(

View File

@ -7,8 +7,8 @@ import endians
import macros
import stint
contract("MyContract"):
expandMacros:
contract("MyContract"):
# proc becomeKing(): uint256 =
# var a: int32
@ -16,10 +16,17 @@ contract("MyContract"):
# a += 1.int32
# return a.stuint(256)
proc get_sender222(): address =
if true:
return msg.sender
proc get_sender(): address =
if true:
return msg.sender
proc publicGetSender*(): address =
return msg.sender
# getCaller(addr tmp_addr)
# proc addition(a: uint256, b: uint256): uint256 =
# return a + b