Ejemplo n.º 1
0
    -n, --networkid [network ID]:
        Ethereum network ID.  If no network ID is specified, this script
        will attempt to request the current ID from geth.  If no geth
        instance is found, defaults to '2' (Morden testnet).

@authors Chris Calderon ([email protected]) and Jack Peterson ([email protected])

"""
import os
import sys
import getopt
import json
import requests
from pyrpctools import get_db, save_db, ROOT, RPC_Client

DB = get_db()
SOURCE = os.path.join(ROOT, os.pardir, "src")
RPCHOST = "127.0.0.1"
RPCPORT = 8545
DEFAULT_NETWORK_ID = "2"
CONTRACTS_URL = "https://raw.githubusercontent.com/AugurProject/augur-contracts/master/contracts.json"

def make_groups():
    groups = {}
    for directory, subdirs, files in os.walk(SOURCE):
        if files:
            group_name = os.path.basename(directory).title()
            name_list = []
            for f in files:
                if f.endswith(".se"):
                    shortname = f[:-3]
Ejemplo n.º 2
0
def read_options():
    '''Reads user options and set's globals.'''
    global IMPORTS
    global VERBOSITY
    global BLOCKTIME
    global RPCHOST
    global RPCPORT
    global DB
    global RPC
    global COINBASE
    global CONTRACT
    global SOURCE

    opts = sys.argv[1:]
    i = 0
    bad_floats = map(float, (0, 'nan', '-inf', '+inf'))
    verb_vals = 1, 2

    while i < len(opts):

        if opts[i] in ('-e', '--exports'):
            IMPORTS = False
            i += 1

        elif opts[i] in ('-h', '--help'):
            print __doc__
            sys.exit(0)
            
        # -e and -h are the only options that can be the last arg
        # so if opts[i] isn't one of those or their long forms, then
        # I gotta check! if the next elif condition fails,
        # then the rest of the args are checked.

        elif (i + 1) == len(opts):
            print 'Invalid option use!', opts[i]
            print __doc__
            sys.exit(1)

        elif opts[i] in ('-b', '--blocktime'):
            try:
                b = float(opts[i+1])
            except ValueError as exc:
                print "The blocktime you provided is not a float!"
                sys.exit(1)
            if b in bad_floats:
                print 'Blocktime can not be 0, NaN, -inf, or +inf!'
                sys.exit(1)
            else:
                BLOCKTIME = b
            i += 2

        elif opts[i] in ('-c', '--contract'):
            CONTRACT = opts[i + 1]
            i += 2

        elif opts[i] in ('-d', '--dbfile'):
            rpc.DBPATH = os.path.join(rpc.ROOT, opts[i + 1])
            i += 2

        elif opts[i] in ('-H', '--rpchost'):
            RPCHOST = opts[i + 1]
            i += 2

        elif opts[i] in ('-p', '--rpcport'):
            try:
                RPCPORT = int(opts[i + 1])
            except:
                print "Bad Port!"
                sys.exit(1)
            i += 2

        elif opts[i] in ('-s', '--source'):
            val = os.path.realpath(opts[i + 1])
            if not os.path.isdir(val):
                print "Invalid options for --source:", val
                print "You must give a directory"
                sys.exit(1)
            SOURCE = val
            i += 2

        elif opts[i] in ('-v', '--verbosity'):
            try:
                v = int(opts[i+1])
            except ValueError as exc:
                print "Error:", exc
                sys.exit(1)
            if v not in verb_vals:
                print 'Verbosity must be 1 or 2!'
                sys.exit(1)
            else:
                VERBOSITY = v
            i += 2

        else:
            print 'Invalid option!', opts[i]
            print __doc__
            sys.exit(1)

    if CONTRACT is not None:
        try:
            get_fullname(CONTRACT)
        except ValueError:
            print 'unknown contract name:', CONTRACT
            sys.exit(1)
        try:
            # When we are recompiling a single contract,
            # We use the existing DB to get address info.
            DB = rpc.get_db()
        except:
            print '--dbfile value does not exist: {}'.format(rpc.DBPATH)
            print __doc__
            sys.exit(1)

    RPC = rpc.RPC_Client((RPCHOST, RPCPORT), VERBOSITY)
    COINBASE = RPC.eth_coinbase()['result']
Ejemplo n.º 3
0
def read_options():
    """Reads user options and set's globals."""
    global IMPORTS
    global VERBOSITY
    global BLOCKTIME
    global RPCHOST
    global RPCPORT
    global DB
    global RPC
    global COINBASE
    global CONTRACT
    global SOURCE
    global TRANSLATE

    opts = sys.argv[1:]
    i = 0
    bad_floats = map(float, (0, "nan", "-inf", "+inf"))
    verb_vals = 1, 2

    # gotta make sure to catch -C before other args
    for a in ("-C", "--chdir"):
        if a in opts:
            i = opts.index(a)
            if i == len(opts) - 1:
                print "Invalid option use!", opts[i]
                print __doc__
                sys.exit(1)

            d = opts[i + 1]
            d = os.path.realpath(d)
            if not os.path.isdir(d):
                print "Invalid option use!", opts[i]
                print __doc__
                sys.exit(1)

            rpc.ROOT = d
            opts.pop(i)  # remove -C
            opts.pop(i)  # and the dir from opts
            break

    while i < len(opts):

        if opts[i] in ("-e", "--externs"):
            IMPORTS = False
            i += 1

        elif opts[i] in ("-h", "--help"):
            print __doc__
            sys.exit(0)

        # -e and -h are the only options that can be the last arg
        # so if opts[i] isn't one of those or their long forms, then
        # I gotta check! if the next elif condition fails,
        # then the rest of the args are checked.

        elif (i + 1) == len(opts):
            print "Invalid option use!", opts[i]
            print __doc__
            sys.exit(1)

        elif opts[i] in ("-b", "--blocktime"):
            try:
                b = float(opts[i + 1])
            except ValueError as exc:
                print "The blocktime you provided is not a float!"
                sys.exit(1)
            if b in bad_floats:
                print "Blocktime can not be 0, NaN, -inf, or +inf!"
                sys.exit(1)
            else:
                BLOCKTIME = b
            i += 2

        elif opts[i] in ("-c", "--contract"):
            CONTRACT = opts[i + 1]
            i += 2

        elif opts[i] in ("-d", "--dbfile"):
            rpc.DBPATH = os.path.join(rpc.ROOT, opts[i + 1])
            i += 2

        elif opts[i] in ("-H", "--rpchost"):
            RPCHOST = opts[i + 1]
            i += 2

        elif opts[i] in ("-p", "--rpcport"):
            try:
                RPCPORT = int(opts[i + 1])
            except:
                print "Bad Port!"
                sys.exit(1)
            i += 2

        elif opts[i] in ("-s", "--source"):
            val = os.path.realpath(os.path.join(rpc.ROOT, opts[i + 1]))
            if not os.path.isdir(val):
                print "Invalid options for --source:", val
                print "You must give a directory"
                sys.exit(1)
            SOURCE = val
            i += 2

        elif opts[i] in ("-v", "--verbosity"):
            try:
                v = int(opts[i + 1])
            except ValueError as exc:
                print "Error:", exc
                sys.exit(1)
            if v not in verb_vals:
                print "Verbosity must be 1 or 2!"
                sys.exit(1)
            else:
                VERBOSITY = v
            i += 2

        elif opts[i] in ("-t", "--translate"):
            val = os.path.join(rpc.ROOT, opts[i + 1])
            val = os.path.realpath(val)
            TRANSLATE = val
            i += 2

        else:
            print "Invalid option!", opts[i]
            print __doc__
            sys.exit(1)

    if CONTRACT is not None:
        try:
            get_fullname(CONTRACT)
        except ValueError:
            print "unknown contract name:", CONTRACT
            sys.exit(1)
        try:
            # When we are recompiling a single contract,
            # We use the existing DB to get address info.
            DB = rpc.get_db()
        except:
            print "--dbfile value does not exist: {}".format(rpc.DBPATH)
            print __doc__
            sys.exit(1)

    if TRANSLATE is None:
        RPC = rpc.RPC_Client((RPCHOST, RPCPORT), VERBOSITY)
        COINBASE = RPC.eth_coinbase()["result"]
    else:
        DB = rpc.get_db()
Ejemplo n.º 4
0
    -n, --networkid [network ID]:
        Ethereum network ID.  If no network ID is specified, this script
        will attempt to request the current ID from geth.  If no geth
        instance is found, defaults to '2' (Morden testnet).

@authors Chris Calderon ([email protected]) and Jack Peterson ([email protected])

"""
import os
import sys
import getopt
import json
import requests
from pyrpctools import get_db, save_db, ROOT, RPC_Client

DB = get_db()
SOURCE = os.path.join(ROOT, os.pardir, "src")
RPCHOST = "127.0.0.1"
RPCPORT = 8545
DEFAULT_NETWORK_ID = "2"
CONTRACTS_URL = "https://raw.githubusercontent.com/AugurProject/augur-contracts/master/contracts.json"
HERE = os.path.abspath(os.path.dirname(__file__))

def build_for_network_id(network_id):
    new_contracts = get_contracts(None)[str(network_id)]
    with open(os.path.join(HERE, "build.json")) as in_file:
        build = json.load(in_file)
    addresses = {}
    for contract_name, contract_data in build.items():
        if contract_name == "buy&sellShares":
            pretty_contract_name = "buyAndSellShares"