Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Code Cleanup #24

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class Account():
class Account:

@property
def ScriptHash(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Asset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class Asset():
class Asset:

@property
def AssetId(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from boa.blockchain.vm.Neo.Header import GetIndex, GetHash, GetPrevHash, GetTimestamp, GetVersion, GetNextConsensus, GetMerkleRoot, GetConsensusData


class Block():
class Block:

@property
def TransactionCount(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Contract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class Contract():
class Contract:

@property
def Script(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Header.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


class Header():
class Header:

def getmyhash(self):
return GetHash(self)
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Input.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class TransactionInput():
class TransactionInput:

@property
def Hash(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Output.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class TransactionOutput():
class TransactionOutput:

@property
def AssetId(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Transaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class Transaction():
class Transaction:

@property
def Hash(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/TransactionAttribute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class TransactionAttribute():
class TransactionAttribute:

@property
def Usage(self):
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/Neo/Validator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class Validator():
class Validator:
pass


Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/SmartContract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class SmartContract():
class SmartContract:

def Sha1(data):
"""
Expand Down
2 changes: 1 addition & 1 deletion boa/blockchain/vm/System/ExecutionEngine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

class ExecutionEngine():
class ExecutionEngine:
"""
Not used.

Expand Down
8 changes: 4 additions & 4 deletions boa/blockchain/vm/VMOp.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
items = dir(sys.modules[__name__])


def ToName(op):
def to_name(op):
"""

:param op:
Expand All @@ -151,10 +151,10 @@ def ToName(op):
n = getattr(module, item)

try:
nn2 = int.from_bytes(n, 'little')
if op == nn2:
nn = int.from_bytes(n, 'little')
if op == nn:
return item
except Exception as e:
except Exception:
pass

return None
7 changes: 3 additions & 4 deletions boa/code/block.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

from byteplay3 import Opcode, Label
from byteplay3 import Opcode
from boa.code.pytoken import PyToken
from boa.code import pyop
from boa.code.vmtoken import NEO_SC_FRAMEWORK
import pdb


class Block():
class Block(object):

"""

Expand Down Expand Up @@ -529,13 +529,12 @@ def process_iter_body(self, setup_block):
def lookup_return_types(self, orig_method):
ivars = {}
klass_type = None
return_type = None
for index, token in enumerate(self.oplist):
if token.py_op == pyop.CALL_FUNCTION:
param_count = token.args

# why would param count be 256 when calling w/ kwargs?
# when keyword args are sent, the param count is 256 * num paramms?
# when keyword args are sent, the param count is 256 * num params?
if param_count % 256 == 0:
param_count = 2 * int(param_count / 256)

Expand Down
18 changes: 5 additions & 13 deletions boa/code/items.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
from byteplay3 import Code, Opcode
from boa.code.method import Method
from byteplay3 import Opcode
from boa.code.pytoken import PyToken

from boa.code import pyop
import importlib
import binascii
import sys
import os

from byteplay3 import Code, SetLinenoType, Label
from byteplay3 import Code, SetLinenoType
from boa.code import pyop

from boa.code.line import Line
from boa.code.method import Method

from boa.blockchain.vm import VMOp

from collections import OrderedDict

import pdb


class Item():
class Item(object):
"""

"""
Expand Down Expand Up @@ -163,10 +155,10 @@ def script_hash_addr(self):
:return:
"""

return SmartContractAppCall.ToScriptHashData(self.script_hash)
return SmartContractAppCall.to_script_hash_data(self.script_hash)

@staticmethod
def ToScriptHashData(item):
def to_script_hash_data(item):
"""

:return:
Expand Down
8 changes: 4 additions & 4 deletions boa/code/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from boa.code import pyop


class Line():
class Line(object):

"""

Expand All @@ -30,9 +30,9 @@ def is_constant(self):

:return:
"""

return (len(self.items) == 3 or len(self.items) == 5) and self.items[1][0] == pyop.LOAD_CONST and self.items[2][0] == pyop.STORE_NAME
# return False
is_correct_length = len(self.items) == 3 or len(self.items) == 5
is_storing_constant = self.items[1][0] == pyop.LOAD_CONST and self.items[2][0] == pyop.STORE_NAME
return is_correct_length and is_storing_constant

@property
def is_module_method_call(self):
Expand Down
11 changes: 4 additions & 7 deletions boa/code/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
import dis

import collections
import pdb

from byteplay3 import object_attributes, print_attr_values, printcodelist


class Method():
class Method(object):
"""
The method is the main unit of functionality. Any method can take 0 to many arguments and return 1 value

Expand All @@ -32,8 +29,9 @@ class Method():

The VMTokenizer is responsible for turning PyToken objects into VMToken objects.

When the method has been tokenized, each token then has an address within the method. Once these addresses are complete,
the ``convert_jumps`` method is called to tell each flow control operation where (which address) it will need to jump to.
When the method has been tokenized, each token then has an address within the method. Once these addresses are
complete, the ``convert_jumps`` method is called to tell each flow control operation where (which address) it will
need to jump.
"""

bp = None
Expand Down Expand Up @@ -356,7 +354,6 @@ def read_initial_tokens(self):
current_label = op

else:
instance_type = None
if op in [pyop.STORE_FAST, pyop.STORE_NAME, pyop.STORE_GLOBAL] and arg not in self.local_stores.keys():

self._check_for_type(arg, total_lines)
Expand Down
6 changes: 2 additions & 4 deletions boa/code/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

from collections import OrderedDict

import pdb


class Module():
class Module(object):
"""
A Module is the top level component which contains code objects.
When, for example, compiling ``path/to/my/file.py``, the items contained in ``file.py`` are the module.
Expand Down Expand Up @@ -554,7 +552,7 @@ def to_s(self):

# If this is a number, it is likely a custom python opcode, get the name
if str(pt.py_op).isnumeric():
opname = pyop.ToName(int(str(pt.py_op)))
opname = pyop.to_name(int(str(pt.py_op)))
if opname is not None:
op = "{:<20}".format(opname)

Expand Down
2 changes: 1 addition & 1 deletion boa/code/pyop.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
items = dir(sys.modules[__name__])


def ToName(op):
def to_name(op):
"""

:param op:
Expand Down
14 changes: 5 additions & 9 deletions boa/code/pytoken.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
from boa.code import pyop

from byteplay3 import Label, isopcode, haslocal, Code
from byteplay3 import Label, isopcode, haslocal

from opcode import opname

from boa.blockchain.vm import VMOp

import pdb
import inspect

NON_RETURN_SYS_CALLS = ['Notify', 'print', 'Log', 'Put', 'Register',
'reverse', 'append',
'Delete', 'SetVotes', 'ContractDestroy',
'MerkleRoot', 'Hash', 'PrevHash', 'GetHeader', ]


class PyToken():
class PyToken(object):

"""

Expand Down Expand Up @@ -111,8 +108,6 @@ def __init__(self, op, lineno, index=None, args=None, array_item=None):
self.array_item = array_item

def __str__(self):
arg = ''

if self.args:
if type(self.args) is Label:
arg = str(self.args)
Expand Down Expand Up @@ -225,7 +220,8 @@ def to_vm(self, tokenizer, prev_token=None):
elif op in [pyop.BINARY_MULTIPLY, pyop.INPLACE_MULTIPLY]:
token = tokenizer.convert1(VMOp.MUL, self)

elif op in [pyop.BINARY_FLOOR_DIVIDE, pyop.BINARY_TRUE_DIVIDE, pyop.INPLACE_FLOOR_DIVIDE, pyop.INPLACE_TRUE_DIVIDE]:
elif op in [pyop.BINARY_FLOOR_DIVIDE, pyop.BINARY_TRUE_DIVIDE,
pyop.INPLACE_FLOOR_DIVIDE, pyop.INPLACE_TRUE_DIVIDE]:
token = tokenizer.convert1(VMOp.DIV, self)

elif op in [pyop.BINARY_MODULO, pyop.INPLACE_MODULO]:
Expand Down Expand Up @@ -267,7 +263,7 @@ def to_vm(self, tokenizer, prev_token=None):

# arrays
elif op == pyop.BUILD_LIST:
token = tokenizer.convert_new_array(VMOp.NEWARRAY, self)
token = tokenizer.convert_new_array(self)
elif op == pyop.SETITEM:
token = tokenizer.convert_set_element(self, self.args)
# token = tokenizer.convert1(VMOp.SETITEM,self, data=self.args)
Expand Down
Loading