Last active
September 7, 2017 15:54
-
-
Save HarryR/e9b3f999ecec2de5616e808d76facb98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"body": [ | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "name", | |
"type": "string", | |
"value": "'Mainstreet Token'" | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "decimals", | |
"type": "uint8", | |
"value": "18" | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "symbol", | |
"type": "string", | |
"value": "'MIT'" | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "version", | |
"type": "string", | |
"value": "'MIT_0.1'" | |
}, | |
{ | |
"access": null, | |
"name": "ownerMIT", | |
"type": { | |
"from": "address", | |
"to": "uint", | |
"type": "mapping" | |
}, | |
"value": null | |
}, | |
{ | |
"access": null, | |
"name": "allowed", | |
"type": { | |
"from": "address", | |
"to": { | |
"from": "address", | |
"to": "uint", | |
"type": "mapping" | |
}, | |
"type": "mapping" | |
}, | |
"value": null | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "totalMIT", | |
"type": "uint", | |
"value": null | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "start", | |
"type": "uint", | |
"value": null | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "mainstreetCrowdfund", | |
"type": "address", | |
"value": null | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "intellisys", | |
"type": "address", | |
"value": null | |
}, | |
{ | |
"access": [ | |
"public" | |
], | |
"name": "testing", | |
"type": "bool", | |
"value": null | |
}, | |
{ | |
"args": null, | |
"body": [ | |
[ | |
"if (msg.sender != mainstreetCrowdfund) ", | |
[ | |
"throw;\n ", | |
"" | |
], | |
"_;\n " | |
], | |
"" | |
], | |
"name": "fromCrowdfund", | |
"type": "modifier" | |
}, | |
{ | |
"args": null, | |
"body": [ | |
[ | |
"if (block.timestamp < start) ", | |
[ | |
"throw;\n ", | |
"" | |
], | |
"_;\n " | |
], | |
"" | |
], | |
"name": "isActive", | |
"type": "modifier" | |
}, | |
{ | |
"args": null, | |
"body": [ | |
[ | |
"if (!testing && block.timestamp >= start) ", | |
[ | |
"throw;\n ", | |
"" | |
], | |
"_;\n " | |
], | |
"" | |
], | |
"name": "isNotActive", | |
"type": "modifier" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "recipient", | |
"type": "address" | |
} | |
], | |
"body": [ | |
[ | |
"if (recipient == 0 || recipient == address(this)) ", | |
[ | |
"throw;\n ", | |
"" | |
], | |
"_;\n " | |
], | |
"" | |
], | |
"name": "recipientIsValid", | |
"type": "modifier" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "spender", | |
"type": "address" | |
}, | |
{ | |
"name": "value", | |
"type": "uint" | |
} | |
], | |
"body": [ | |
[ | |
"if ((value != 0) && (allowed[msg.sender][spender] != 0)) ", | |
[ | |
"throw;\n ", | |
"" | |
], | |
"_;\n " | |
], | |
"" | |
], | |
"name": "allowanceIsZero", | |
"type": "modifier" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "_mainstreetCrowdfund", | |
"type": "address" | |
}, | |
{ | |
"name": "_intellisys", | |
"type": "address" | |
}, | |
{ | |
"name": "_start", | |
"type": "uint" | |
}, | |
{ | |
"name": "_testing", | |
"type": "bool" | |
} | |
], | |
"body": [ | |
"mainstreetCrowdfund = _mainstreetCrowdfund;\n intellisys = _intellisys;\n start = _start;\n testing = _testing;\n ", | |
"" | |
], | |
"modifiers": [], | |
"name": "MainstreetToken", | |
"returns": null, | |
"type": "function" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "recipient", | |
"type": "address" | |
}, | |
{ | |
"name": "MIT", | |
"type": "uint" | |
} | |
], | |
"body": [ | |
"ownerMIT[recipient] += MIT;\n uint intellisysMIT = MIT / 10;\n ownerMIT[intellisys] += intellisysMIT;\n totalMIT += MIT + intellisysMIT;\n Transfer(0x0, recipient, MIT);\n Transfer(0x0, intellisys, intellisysMIT);\n ", | |
"" | |
], | |
"modifiers": [ | |
{ | |
"args": null, | |
"name": "external" | |
}, | |
{ | |
"args": null, | |
"name": "isNotActive" | |
}, | |
{ | |
"args": null, | |
"name": "fromCrowdfund" | |
} | |
], | |
"name": "addTokens", | |
"returns": null, | |
"type": "function" | |
}, | |
{ | |
"args": null, | |
"body": [ | |
"totalSupply = totalMIT;\n ", | |
"" | |
], | |
"modifiers": [ | |
{ | |
"args": null, | |
"name": "constant" | |
} | |
], | |
"name": "totalSupply", | |
"returns": [ | |
{ | |
"name": "totalSupply", | |
"type": "uint256" | |
} | |
], | |
"type": "function" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "_owner", | |
"type": "address" | |
} | |
], | |
"body": [ | |
"balance = ownerMIT[_owner];\n ", | |
"" | |
], | |
"modifiers": [ | |
{ | |
"args": null, | |
"name": "constant" | |
} | |
], | |
"name": "balanceOf", | |
"returns": [ | |
{ | |
"name": "balance", | |
"type": "uint256" | |
} | |
], | |
"type": "function" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "_to", | |
"type": "address" | |
}, | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"body": [ | |
[ | |
"if (ownerMIT[msg.sender] >= _value) ", | |
[ | |
"ownerMIT[msg.sender] -= _value;\n ownerMIT[_to] += _value;\n Transfer(msg.sender, _to, _value);\n return true;\n ", | |
"" | |
], | |
"else " | |
], | |
[ | |
"", | |
[ | |
"return false;\n ", | |
"" | |
], | |
"" | |
], | |
"" | |
], | |
"modifiers": [ | |
{ | |
"args": null, | |
"name": "isActive" | |
}, | |
{ | |
"args": [ | |
"_to" | |
], | |
"name": "recipientIsValid" | |
} | |
], | |
"name": "transfer", | |
"returns": [ | |
{ | |
"name": "success", | |
"type": "bool" | |
} | |
], | |
"type": "function" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "_from", | |
"type": "address" | |
}, | |
{ | |
"name": "_to", | |
"type": "address" | |
}, | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"body": [ | |
[ | |
"if (allowed[_from][msg.sender] >= _value && ownerMIT[_from] >= _value) ", | |
[ | |
"ownerMIT[_to] += _value;\n ownerMIT[_from] -= _value;\n allowed[_from][msg.sender] -= _value;\n Transfer(_from, _to, _value);\n return true;\n ", | |
"" | |
], | |
"else " | |
], | |
[ | |
"", | |
[ | |
"return false;\n ", | |
"" | |
], | |
"" | |
], | |
"" | |
], | |
"modifiers": [ | |
{ | |
"args": null, | |
"name": "isActive" | |
}, | |
{ | |
"args": [ | |
"_to" | |
], | |
"name": "recipientIsValid" | |
} | |
], | |
"name": "transferFrom", | |
"returns": [ | |
{ | |
"name": "success", | |
"type": "bool" | |
} | |
], | |
"type": "function" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "_spender", | |
"type": "address" | |
}, | |
{ | |
"name": "_value", | |
"type": "uint256" | |
} | |
], | |
"body": [ | |
"allowed[msg.sender][_spender] = _value;\n Approval(msg.sender, _spender, _value);\n return true;\n ", | |
"" | |
], | |
"modifiers": [ | |
{ | |
"args": null, | |
"name": "isActive" | |
}, | |
{ | |
"args": [ | |
"_spender", | |
"_value" | |
], | |
"name": "allowanceIsZero" | |
} | |
], | |
"name": "approve", | |
"returns": [ | |
{ | |
"name": "success", | |
"type": "bool" | |
} | |
], | |
"type": "function" | |
}, | |
{ | |
"args": [ | |
{ | |
"name": "_owner", | |
"type": "address" | |
}, | |
{ | |
"name": "_spender", | |
"type": "address" | |
} | |
], | |
"body": [ | |
"remaining = allowed[_owner][_spender];\n ", | |
"" | |
], | |
"modifiers": [ | |
{ | |
"args": null, | |
"name": "constant" | |
} | |
], | |
"name": "allowance", | |
"returns": [ | |
{ | |
"name": "remaining", | |
"type": "uint256" | |
} | |
], | |
"type": "function" | |
} | |
], | |
"inherits": [ | |
"ERC20" | |
], | |
"name": "MainstreetToken", | |
"type": "contract" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import sys | |
import json | |
import re | |
import itertools | |
import json | |
import grako | |
import hashlib | |
grammar_ebnf = """ | |
@@comments :: /\/\*.*?\*\// | |
@@eol_comments :: /\/\/.*?$/ | |
SourceUnit = { PragmaDirective | ContractDefinition }+ ; | |
PragmaDirective = type:'pragma' name:name version:/[^;]+/ ';' ; | |
ContractDefinition = type:'contract' name:name [ inherits:InheritanceSpecifier ] body:ContractPart ; | |
ContractPart = '{' @:{ FunctionDefinition | ModifierDefinition | StateVariableDeclaration | EventDefinition | struct }+ '}' ; | |
InheritanceSpecifier = 'is' @+:name { ',' @+:name }* ; | |
AccessModifierName = 'public' | 'internal' | 'external' | 'private' | 'constant' ; | |
AccessModifiers = { AccessModifierName }+ ; | |
EventDefinition = type:'event' name:name args:ParameterList ';' ; | |
HexNumber = /0x[0-9a-fA-F]+/ ; | |
DecimalNumber = /[0-9]+/ ; | |
BooleanLiteral = 'true' | 'false' ; | |
NumberLiteral = ( HexNumber | DecimalNumber ) [ ' ' NumberUnit ] ; | |
NumberUnit = 'wei' | 'szabo' | 'finney' | 'ether' | |
| 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'years' ; | |
StringLiteral = @:/(["'])([^'\r\n]|\\.)*["']/ ; | |
Expression = /\s*/ @:( NumberLiteral | BooleanLiteral | StringLiteral | name ) /\s*/ ; | |
ExpressionList = ( @+:Expression { ',' @+:Expression }* ) ; | |
StateVariableDeclaration = type:all_types [ access:AccessModifiers ] name:name [ value:StateVariableAssignment ] ';' ; | |
StateVariableAssignment = '=' @:Expression ; | |
Int = 'int' | 'int8' | 'int16' | 'int24' | 'int32' | 'int40' | 'int48' | 'int56' | 'int64' | 'int72' | 'int80' | 'int88' | 'int96' | 'int104' | 'int112' | 'int120' | 'int128' | 'int136' | 'int144' | 'int152' | 'int160' | 'int168' | 'int176' | 'int184' | 'int192' | 'int200' | 'int208' | 'int216' | 'int224' | 'int232' | 'int240' | 'int248' | 'int256' ; | |
Uint = 'uint' | 'uint8' | 'uint16' | 'uint24' | 'uint32' | 'uint40' | 'uint48' | 'uint56' | 'uint64' | 'uint72' | 'uint80' | 'uint88' | 'uint96' | 'uint104' | 'uint112' | 'uint120' | 'uint128' | 'uint136' | 'uint144' | 'uint152' | 'uint160' | 'uint168' | 'uint176' | 'uint184' | 'uint192' | 'uint200' | 'uint208' | 'uint216' | 'uint224' | 'uint232' | 'uint240' | 'uint248' | 'uint256' ; | |
Byte = 'byte' | 'bytes' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32' ; | |
scalar_types = Int | |
| Uint | |
| Byte | |
| 'bool' | |
| 'address' | |
| 'string' | |
; | |
all_types = scalar_types | |
| mapping_body ; | |
mapping_body = type:'mapping' '(' from:name '=>' to:( mapping_body | name ) ')' ; | |
struct = type:'struct' name:name fields:struct_fields ; | |
struct_fields = '{' { @+:struct_field ';' }+ '}' ; | |
struct_field = type:all_types name:name ; | |
ModifierDefinition = type:'modifier' name:name args:ParameterList body:ModifierBody ; | |
ModifierBody = '{' @:{ any [ ModifierBody any ] } '}' ; | |
ModifierInvocation = name:name [ '(' [ args:ExpressionList ] ')' ] ; | |
FunctionModifiers = { ModifierInvocation }* ; | |
FunctionDefinition = type:'function' name:name args:ParameterList | |
{ 'returns' returns:ParameterList | modifiers+:ModifierInvocation }* | |
( body:FunctionBody | ';' ) | |
; | |
FunctionBody = '{' @:{ any [ ModifierBody any ] } '}' ; | |
ParameterList = '(' @:[ function_args ] ')' ; | |
function_arg = type:all_types [ 'indexed' ] name:name ; | |
function_args = ( @+:function_arg { ',' @+:function_arg }* ) ; | |
name = /[_a-zA-Z$][a-zA-Z0-9_$]*/ ; | |
bracketed = any '{' @+:( { bracketed any }+ | any ) '}' ; | |
any_in_paren = /[^()]*/ ; | |
any = /[^{}]*/ ; | |
""" | |
model = grako.tool.genmodel("Bracketed", grammar_ebnf) | |
def main(): | |
if len(sys.argv) < 2: | |
print("Usage: parse.py <file> [file ...]") | |
return | |
files = sys.argv[1:] | |
for filename in files: | |
with open(filename, 'r') as handle: | |
original = model.parse(handle.read(), rule_name='SourceUnit') | |
print(json.dumps(original)) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment