Exemplo n.º 1
0
def call_contract():
    w3 = Web3(Web3.HTTPProvider(url))
    from_addr = w3.toChecksumAddress(account_addr)
    print(
        timeTrack.functions.getEmployees().call()
    )
    return timeTrack.functions.getEmployees().call()
def call_contract(greeter,account_addr,keypath,password,url):
    w3 = Web3(Web3.HTTPProvider(url))

    from_addr = w3.toChecksumAddress(account_addr)

    # Display the default greeting from the contract
    print('Default contract greeting: {}'.format(
        greeter.functions.greet().call()
    ))

    print('Setting the greeting to Nihao...')
    tx_hash = greeter.functions.setGreeting('Nihao').raw_transact({
        'gas': 300000,
        'from':from_addr,
        'value': 0,
    },keypath,password,42)

    # Wait for transaction to be mined...
    w3.cpc.waitForTransactionReceipt(tx_hash)

    # Display the new greeting value
    print('Updated contract greeting: {}'.format(
        greeter.functions.greet().call()
    ))

    # When issuing a lot of reads, try this more concise reader:
    reader = ConciseContract(greeter)
    assert reader.greet() == "Nihao"

    a = greeter.events.test.createFilter(fromBlock=0,toBlock='latest')
    eventlist = a.get_all_entries()
    print(eventlist)
Exemplo n.º 3
0
def test_local_sendRawTransaction2(userid, serAd):
    web3 = Web3(Web3.HTTPProvider('http://3.1.81.79:8501'))
    with open(
            r'D:\9102Hackthon\workstation\cpchain-windows-4.0-amd64\datadir\keystore'
            + '\\' + serAd) as keyfile:
        encrypted_key = keyfile.read()
    private_key_for_senders_account = web3.cpc.account.decrypt(
        encrypted_key, '123456')
    from_addr = web3.toChecksumAddress('0x' + serAd)  #服务器为发送者
    to_addr = web3.toChecksumAddress('0x' + userid)  #游戏胜利则服务器发送CPC给玩家
    tx_dict = dict(
        type=0,
        nonce=web3.cpc.getTransactionCount(from_addr),
        gasPrice=web3.cpc.gasPrice,  #获得Gas Price
        gas=180000,
        to=to_addr,  #发送给用户
        value=500000000,  #成功则用户CPC加0.000005CPC
        data=b'w',
        chainId=42,
    )
    signed_txn = web3.cpc.account.signTransaction(
        tx_dict,
        private_key_for_senders_account,
    )
    print(web3.cpc.sendRawTransaction(signed_txn.rawTransaction))
Exemplo n.º 4
0
def update_rate():
    cf = Web3(Web3.HTTPProvider(chain))
    client = MongoClient(host=mongoHost, port=port)
    uname = cfg['mongo']['uname']
    pwd = cfg['mongo']['password']
    db = client['cpchain']
    db.authenticate(uname, pwd)
    rnode_collection = client['cpchain']['rnode']
    proposer_collection = client['cpchain']['proposer']
    block_collection = client['cpchain']['blocks']
    txs_collection = client['cpchain']['txs']
    num_collection = client['cpchain']['num']
    spend_time = 60 * 10
    start_timestamp = int(time.time()) - spend_time
    txs_count = txs_collection.find({
        'timestamp': {
            '$gte': start_timestamp
        }
    }).count()
    tps = round(txs_count / spend_time, 2)
    num_collection.update({'type': 'tps'}, {'$set': {'tps': tps}}, upsert=True)
    # update bps
    block_count = block_collection.find({
        'timestamp': {
            '$gte': start_timestamp
        }
    }).count()
    bps = round(block_count / spend_time, 2)
    num_collection.update({'type': 'bps'}, {'$set': {'bps': bps}}, upsert=True)
    client.close()
    log.info('tps: ' + str(tps) + ', bps: ' + str(bps))
Exemplo n.º 5
0
def test_local_sendRawTransaction3(userid, serAd):
    web3 = Web3(Web3.HTTPProvider('http://3.1.81.79:8501'))
    with open(
            r'D:\9102Hackthon\workstation\cpchain-windows-4.0-amd64\datadir\keystore'
            + '\\' + userid) as keyfile:
        encrypted_key = keyfile.read()
    private_key_for_senders_account = web3.cpc.account.decrypt(
        encrypted_key, '123456')
    from_addr = web3.toChecksumAddress('0x' + userid)
    # to_addr = web3.toChecksumAddress('0x'+serAd)  #异常是自己发给自己记录游戏异常
    tx_dict = dict(
        type=0,
        nonce=web3.cpc.getTransactionCount(from_addr),
        gasPrice=web3.cpc.gasPrice,
        gas=90000,
        to=from_addr,
        value=0,
        data=b'',
        chainId=42,
    )
    signed_txn = web3.cpc.account.signTransaction(
        tx_dict,
        private_key_for_senders_account,
    )
    print(web3.cpc.sendRawTransaction(signed_txn.rawTransaction))
Exemplo n.º 6
0
def test_local_sendRawTransaction1(userid, serAd):
    web3 = Web3(Web3.HTTPProvider('http://3.1.81.79:8501'))
    # 玩家的keyfile
    with open(
            r'D:\9102Hackthon\workstation\cpchain-windows-4.0-amd64\datadir\keystore'
            + '\\' + userid) as keyfile:
        encrypted_key = keyfile.read()
    private_key_for_senders_account = web3.cpc.account.decrypt(
        encrypted_key, '123456')
    from_addr = web3.toChecksumAddress('0x' + userid)  ##玩家为发送者
    to_addr = web3.toChecksumAddress('0x' + serAd)  ##游戏失败玩家需发送给CPC给服务器
    tx_dict = dict(
        type=0,
        nonce=web3.cpc.getTransactionCount(from_addr),
        gasPrice=web3.cpc.gasPrice,  #获得Gas Price
        gas=180000,
        to=to_addr,  #发送给服务器地址58d0791b5c4ddb460a89feda48a2ed935fb757ec
        value=300000000,  #失败则用户CPC减0.000003
        data=b'l',
        chainId=42,
    )
    signed_txn = web3.cpc.account.signTransaction(
        tx_dict,
        private_key_for_senders_account,
    )
    print(web3.cpc.sendRawTransaction(signed_txn.rawTransaction))
Exemplo n.º 7
0
def init():

    # install_solc('v0.4.25')
    global cpc
    cpc = int(math.pow(10, 18))

    global password
    password = "******"

    global owner
    owner = "0xb3801b8743DEA10c30b0c21CAe8b1923d9625F84"

    global rnode_succeed
    rnode_succeed = "0x4A030EC3ea9A813FBb0aFb79cB175c09ce56B3bE"

    global rnode_failed
    rnode_failed = "0x8FB5ECa33af7757a8d6cE679C3Ad16cCe007fE7f"

    global cf
    cf = Web3(Web3.HTTPProvider('http://127.0.0.1:8521'))

    cf.personal.unlockAccount("0x4A030EC3ea9A813FBb0aFb79cB175c09ce56B3bE", password)
    cf.personal.unlockAccount("0x8FB5ECa33af7757a8d6cE679C3Ad16cCe007fE7f", password)

    global abi
    abi = {'constant': True, 'inputs': [], 'name': 'getRnodeNum', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [{'name': '_period', 'type': 'uint256'}], 'name': 'setPeriod', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [], 'name': 'quitRnode', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [{'name': 'addr', 'type': 'address'}], 'name': 'isContract', 'outputs': [{'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': True, 'inputs': [{'name': '', 'type': 'address'}], 'name': 'Participants', 'outputs': [{'name': 'lockedDeposit', 'type': 'uint256'}, {'name': 'lockedTime', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [{'name': 'threshold', 'type': 'uint256'}], 'name': 'setRnodeThreshold', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [{'name': 'addr', 'type': 'address'}], 'name': 'isRnode', 'outputs': [{'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'rnodeThreshold', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [], 'name': 'joinRnode', 'outputs': [], 'payable': True, 'stateMutability': 'payable', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'getRnodes', 'outputs': [{'name': '', 'type': 'address[]'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'period', 'outputs': [{'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'inputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'constructor'}, {'anonymous': False, 'inputs': [{'indexed': False, 'name': 'who', 'type': 'address'}, {'indexed': False, 'name': 'lockedDeposit', 'type': 'uint256'}, {'indexed': False, 'name': 'lockedTime', 'type': 'uint256'}], 'name': 'NewRnode', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': False, 'name': 'who', 'type': 'address'}], 'name': 'RnodeQuit', 'type': 'event'}
    global bin
    bin = "6080604052603c600155692a5a058fc295ed00000060025534801561002357600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610e04806100736000396000f3006080604052600436106100af576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630b443f42146100b45780630f3a9f65146100df578063113c84981461010c5780631627905514610123578063595aa13d1461017e578063975dd4b2146101dc578063a8f0769714610209578063b7b3e9da14610264578063b892c6da1461028f578063e508bb8514610299578063ef78d4fd14610305575b600080fd5b3480156100c057600080fd5b506100c9610330565b6040518082815260200191505060405180910390f35b3480156100eb57600080fd5b5061010a60048036038101908080359060200190929190505050610340565b005b34801561011857600080fd5b506101216103a5565b005b34801561012f57600080fd5b50610164600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610564565b604051808215151515815260200191505060405180910390f35b34801561018a57600080fd5b506101bf600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610577565b604051808381526020018281526020019250505060405180910390f35b3480156101e857600080fd5b506102076004803603810190808035906020019092919050505061059b565b005b34801561021557600080fd5b5061024a600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610600565b604051808215151515815260200191505060405180910390f35b34801561027057600080fd5b5061027961061d565b6040518082815260200191505060405180910390f35b610297610623565b005b3480156102a557600080fd5b506102ae6108e8565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156102f15780820151818401526020810190506102d6565b505050509050019250505060405180910390f35b34801561031157600080fd5b5061031a6108f9565b6040518082815260200191505060405180910390f35b6000600360010180549050905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561039b57600080fd5b8060018190555050565b6103b93360036108ff90919063ffffffff16565b15156103c457600080fd5b42600154600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154011115151561041957600080fd5b3373ffffffffffffffffffffffffffffffffffffffff166108fc600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001549081150290604051600060405180830381858888f193505050501580156104a1573d6000803e3d6000fd5b506000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001819055506104fe33600361095890919063ffffffff16565b507f602a2a9c94f70293aa2be9077f0b2dc89d388bc293fdbcd968274f43494c380d33604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1565b600080823b905060008111915050919050565b60056020528060005260406000206000915090508060000154908060010154905082565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156105f657600080fd5b8060028190555050565b60006106168260036108ff90919063ffffffff16565b9050919050565b60025481565b61062c33610564565b1515156106c7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602a8152602001807f706c65617365206e6f742075736520636f6e74726163742063616c6c2074686981526020017f732066756e6374696f6e0000000000000000000000000000000000000000000081525060400191505060405180910390fd5b6106db3360036108ff90919063ffffffff16565b1515156106e757600080fd5b60025434101515156106f857600080fd5b61074d34600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000154610bab90919063ffffffff16565b600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000018190555042600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101819055506107ee336003610bc990919063ffffffff16565b507f586bfaa7a657ad9313326c9269639546950d589bd479b3d6928be469d6dc290333600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000154600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010154604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001838152602001828152602001935050505060405180910390a1565b60606108f46003610cf5565b905090565b60015481565b60008260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16905092915050565b60008060008460000160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615156109bb5760009250610ba3565b60008560000160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555084600101805490509150600090505b81811015610b9e578373ffffffffffffffffffffffffffffffffffffffff168560010182815481101515610a5457fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415610b91578460010160018303815481101515610aaf57fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560010182815481101515610aeb57fe5b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508460010160018303815481101515610b4757fe5b9060005260206000200160006101000a81549073ffffffffffffffffffffffffffffffffffffffff021916905584600101805480919060019003610b8b9190610d87565b50610b9e565b8080600101915050610a24565b600192505b505092915050565b6000808284019050838110151515610bbf57fe5b8091505092915050565b60008260000160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615610c285760009050610cef565b60018360000160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908315150217905550826001018290806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050600190505b92915050565b606081600101805480602002602001604051908101604052809291908181526020018280548015610d7b57602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019060010190808311610d31575b50505050509050919050565b815481835581811115610dae57818360005260206000209182019101610dad9190610db3565b5b505050565b610dd591905b80821115610dd1576000816000905550600101610db9565b5090565b905600a165627a7a72305820a61199baf3a5c3a2b980fae962df409a696d87b726b0836a07c747a7173bc5370029"
    global contract_address
    contract_address = "0x37880d44eE800AD4819117c5B498Fb4D4192c5B2"
Exemplo n.º 8
0
def valid_register(request):
    username = request.form["username"]
    password = request.form["password"]
    rpassword = request.form["rpassword"]
    email = request.form["email"]
    gender = request.form["gender"]
    birthday = request.form["birthday"]
    if password != rpassword:
        return '', username, 'Two passwords are not the same!'

    w3 = Web3(Web3.HTTPProvider('http://3.1.81.79:8501'))
    newU_addr = w3.personal.newAccount('asdfg')

    sql = """insert into User (UserName, Gender, Birthday, Password, Email, Address)
    values ('%s','%s','%s','%s','%s','%s');"""
    data = (username, gender, birthday, password, email, newU_addr)

    try:
        expr = sql%data
        cursor.execute(expr)
        cursor.execute("SELECT UserNo FROM User WHERE UserName= '******';" % username)
        row = cursor.fetchall()

        db.commit()
        return row[0][0], username, None
    except:
        db.rollback()
        return '', username, 'This username has been used. Please try another.'
Exemplo n.º 9
0
def main():
    target = ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'ca', 'bank']
    cf = Web3(Web3.HTTPProvider(f'http://127.0.0.1:8499'))
    for i in target:
        with open(f'datadir/{i}/address', 'r') as f:
            addr = f.readline()
            addr = cf.toChecksumAddress(addr)
            balance = cf.fromWei(cf.cpc.getBalance(addr), 'ether')
            print(f'{i}({addr}) => {balance}')
Exemplo n.º 10
0
def call_displayMyHistory():
    w3 = Web3(Web3.HTTPProvider(url))
    from_addr = w3.toChecksumAddress(account_addr)
    print(
        timeTrack.functions.displayMyPunchIns().call()
    )
    print(
        timeTrack.functions.displayMyPunchOuts().call()
    )

    return {"punchIns": timeTrack.functions.displayMyPunchIns().call(), "punchOuts": timeTrack.functions.displayMyPunchOuts().call()}
Exemplo n.º 11
0
def callAddEmployee():
    w3 = Web3(Web3.HTTPProvider(url))
    from_addr = w3.toChecksumAddress(account_addr)
    tx_hash = timeTrack.functions.addEmployee().raw_transact({
        'gas': 300000,
        'from': from_addr,
        'value': 0,
    }, keypath, password, 42)
    # Wait for transaction to be mined...
    w3.cpc.waitForTransactionReceipt(tx_hash)
    return timeTrack.functions.getEmployees().call()
Exemplo n.º 12
0
def callPunchOut():
    w3 = Web3(Web3.HTTPProvider(url))
    from_addr = w3.toChecksumAddress(account_addr)
    tx_hash = timeTrack.functions.doPunchOUT().raw_transact({
        'gas': 300000,
        'from': from_addr,
        'value': 0,
    }, keypath, password, 42)
    # Wait for transaction to be mined...
    w3.cpc.waitForTransactionReceipt(tx_hash)
    return call_displayMyHistory()
Exemplo n.º 13
0
def test_case_1():
    cf = Web3(Web3.HTTPProvider("http://127.0.0.1:8521"))
    cf.cpc.defaultAccount = cf.cpc.accounts[0]
    cf.personal.unlockAccount(cf.cpc.accounts[0], "password")
    config = compile_file()
    contract = cf.cpc.contract(abi=config["abi"], bytecode=config["bin"])
    print("===========deploy contract================")
    estimated_gas = contract.constructor().estimateGas()
    tx_hash = contract.constructor().transact(dict(gas=estimated_gas))
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    address = tx_receipt['contractAddress']
    print("contract address: ", address)
    network_ins = cf.cpc.contract(abi=config["abi"], address=address)
    print("============read config===================")
    host = network_ins.functions.host().call()
    count = network_ins.functions.count().call()
    timeout = network_ins.functions.timeout().call()
    gap = network_ins.functions.gap().call()
    open = network_ins.functions.open().call()
    print("host: ", host)
    print("count: ", count)
    print("timeout: ", timeout)
    print("gap: ", gap)
    print("open: ", open)
    print("============owner set configs=============")
    tx_hash = network_ins.functions.updateHost("google.com").transact(
        {"gas": 8888888})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("set host result: ", tx_receipt["status"])
    tx_hash = network_ins.functions.updateCount(10).transact({"gas": 8888888})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("set count result: ", tx_receipt["status"])
    tx_hash = network_ins.functions.updateTimeout(300).transact(
        {"gas": 8888888})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("set timeout result: ", tx_receipt["status"])
    tx_hash = network_ins.functions.updateGap(10).transact({"gas": 8888888})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("set gap result: ", tx_receipt["status"])
    tx_hash = network_ins.functions.updateOpen(False).transact(
        {"gas": 8888888})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("set open result: ", tx_receipt["status"])
    print("============read config again===============")
    host = network_ins.functions.host().call()
    count = network_ins.functions.count().call()
    timeout = network_ins.functions.timeout().call()
    gap = network_ins.functions.gap().call()
    open = network_ins.functions.open().call()
    print("host: ", host)
    print("count: ", count)
    print("timeout: ", timeout)
    print("gap: ", gap)
    print("open: ", open)
Exemplo n.º 14
0
def callPunchIn():
    w3 = Web3(Web3.HTTPProvider(url))
    from_addr = w3.toChecksumAddress(account_addr)
    tx_hash = timeTrack.functions.doPunchIN().raw_transact({
        'gas': 300000,
        'from': from_addr,
        'value': 0,
    }, keypath, password, 42)
    # Wait for transaction to be mined...
    w3.cpc.waitForTransactionReceipt(tx_hash)
    print("call punch in")
    return timeTrack.functions.displayPunchTime().call()
Exemplo n.º 15
0
def test_campaign(contract_abi, contract_address):
    abi = contract_abi
    address = contract_address
    cf = Web3(Web3.HTTPProvider('http://13.250.201.89:8501'))

    # cf.cpc.defaultAccount = cf.cpc.accounts[0]

    campaign = cf.cpc.contract(abi=abi, address=address)

    withdraw_term = campaign.functions.withdrawTermIdx().call()
    print("withdraw term: ", withdraw_term)
    terms = campaign.functions.termIdx().call()
    print("term: ", terms)
Exemplo n.º 16
0
def check_block(url, start=0, end=0):
    cf = Web3(Web3.HTTPProvider(url))
    found = 0
    for i in range(int(start), int(end) + 1):
        b = cf.cpc.getBlock(i)
        if b is None:
            print("The block #%d does not exist." % i)
        else:
            print(b)
            found += 1

    total = int(end) - int(start) + 1
    print("Scanned %d blocks, found %d blocks, %d blocks do not exist." %
          (total, found, total - found))
Exemplo n.º 17
0
def deploy_contract(interface):
    # init()
    # cf.cpc.defaultAccount = owner
    cf = Web3(Web3.HTTPProvider("http://127.0.0.1:8521"))
    contract = cf.cpc.contract(abi=interface['abi'], bytecode=interface['bin'])

    estimated_gas = contract.constructor().estimateGas()
    tx_hash = contract.constructor().transact(dict(gas=estimated_gas))

    # get tx receipt to get contract address
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    address = tx_receipt['contractAddress']

    # contract = cf.cpc.contract(address=address, abi=interface['abi'])

    return address
def test_local_sendRawTransaction():
    web3 = Web3(Web3.HTTPProvider('http://3.1.81.79:8501'))
    # web3.middleware_stack.inject(geth_poa_middleware, layer=0)
    # change the keypath to your keystore file
    with open(
            '/Users/junchengzhu/go/src/chain/examples/cpchain/data/data21/keystore/key21'
    ) as keyfile:
        encrypted_key = keyfile.read()
    # print(web3.cpc.getBalance(web3.cpc.accounts))
    print(web3.cpc.accounts)
    print('balance:', web3.cpc.getBalance(web3.cpc.accounts[0]))
    print(
        "================================encrypted_key======================\n"
    )
    print(encrypted_key)
    private_key_for_senders_account = web3.cpc.account.decrypt(
        encrypted_key, 'password')
    print("private_key_for_senders_account:")
    print(private_key_for_senders_account)
    print('coinbase:', web3.cpc.coinbase)
    from_addr = web3.toChecksumAddress(
        '0xb3801b8743dea10c30b0c21cae8b1923d9625f84')
    to_addr = web3.toChecksumAddress(
        '0xc05302acebd0730e3a18a058d7d1cb1204c4a092')

    print('gasPrice:', web3.cpc.gasPrice)
    # set chainId to None if you want a transaction that can be replayed across networks
    tx_dict = dict(
        type=0,
        nonce=web3.cpc.getTransactionCount(from_addr),
        gasPrice=web3.cpc.gasPrice,
        gas=90000,
        to=to_addr,
        value=123,
        data=b'',
        chainId=42,
    )
    signed_txn = web3.cpc.account.signTransaction(
        tx_dict,
        private_key_for_senders_account,
    )
    print("signed_txn:")
    print(signed_txn)

    print("sendRawTransaction:")
    print(web3.toHex(signed_txn.rawTransaction))
    print(web3.cpc.sendRawTransaction(signed_txn.rawTransaction))
Exemplo n.º 19
0
def prepare():
    cf = Web3(Web3.HTTPProvider("http://127.0.0.1:8521"))
    print("current account: ", cf.cpc.accounts)
    print("balance of owner: ",
          cf.fromWei(cf.cpc.getBalance(cf.cpc.accounts[0]), "ether"))
    # cf.personal.newAccount("password")
    print("current account: ", cf.cpc.accounts)
    cf.cpc.sendTransaction({
        "from": "0xb3801b8743DEA10c30b0c21CAe8b1923d9625F84",
        "to": "0x4dc8319379E36534b60f5E93C4715d39042723d5",
        "value": cf.toWei(100000, "ether")
    })
    print(
        "balance of owner: ",
        cf.fromWei(
            cf.cpc.getBalance("0x4dc8319379E36534b60f5E93C4715d39042723d5"),
            "ether"))
Exemplo n.º 20
0
def call_display_global():
    w3 = Web3(Web3.HTTPProvider(url))
    from_addr = w3.toChecksumAddress(account_addr)
    print(
        timeTrack.functions.displayTotalPunchInCount().call()
    )
    print(
        timeTrack.functions.displayTotalPunchOutCount().call()
    )
    print(
        timeTrack.functions.displayTotalOvertimeCount().call()
    )
    print(
        timeTrack.functions.displayCurrentMsgSender().call()
    )

    return timeTrack.functions.displayTotalOvertimeCount().call()
Exemplo n.º 21
0
def creat_contract(filepath, url, contact_name, keypath, password,
                   account_addr, gas):
    # Solidity source code
    contract_code_file = open(filepath, "r")
    contract_source_code = contract_code_file.read()
    print(contract_source_code)
    compiled_sol = compile_source(contract_source_code)  # Compiled source code
    contract_interface = compiled_sol[f'<stdin>:{contact_name}']

    # web3.py instance
    w3 = Web3(Web3.HTTPProvider(url))

    # set pre-funded account as sender
    w3.cpc.defaultAccount = w3.cpc.accounts[0]

    # Instantiate and deploy contract
    Greeter = w3.cpc.contract(abi=contract_interface['abi'],
                              bytecode=contract_interface['bin'])

    # Submit the transaction that deploys the contract
    from_addr = w3.toChecksumAddress(account_addr)
    tx_hash = Greeter.constructor().raw_transact(
        {
            # Increase or decrease gas according to contract conditions
            'gas': gas,
            'from': from_addr,
            'value': 0
        },
        keypath,
        password,
        42)

    print('*********', w3.cpc.getTransactionReceipt(tx_hash))

    # Wait for the transaction to be mined, and get the transaction receipt
    tx_receipt = w3.cpc.waitForTransactionReceipt(tx_hash)
    # tx_receipt1 = w3.cpc.waitForTransactionReceipt(tx_hash_raw)
    print(tx_receipt)
    # print(tx_receipt1)

    # Create the contract instance with the newly-deployed address
    greeter = w3.cpc.contract(
        address=tx_receipt.contractAddress,
        abi=contract_interface['abi'],
    )
    return greeter, w3, tx_receipt.contractAddress
Exemplo n.º 22
0
def call_displayMe():
    w3 = Web3(Web3.HTTPProvider(url))
    from_addr = w3.toChecksumAddress(account_addr)
    print(
        timeTrack.functions.displayMyOvertimeCount().call()
    )
    print(
        timeTrack.functions.displayMyPunchDayNum().call()
    )
    print(
        timeTrack.functions.displayMyPunchStatus().call()
    )
    print(
        timeTrack.functions.displayMyAddr().call()
    )

    return {"overtimeCount": timeTrack.functions.displayMyOvertimeCount().call(), "punchStatus": timeTrack.functions.displayMyPunchStatus().call()}
def test_local_sendRawTransaction():
    web3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8501'))
    # web3.middleware_stack.inject(geth_poa_middleware, layer=0)
    # change the keypath to your keystore file
    with open('path/to/your/keystore') as keyfile:
        encrypted_key = keyfile.read()
    # print(web3.cpc.getBalance(web3.cpc.accounts))
    print(web3.cpc.accounts)
    print('balance:', web3.cpc.getBalance(web3.cpc.accounts[0]))
    print(
        "================================encrypted_key======================\n"
    )
    print(encrypted_key)
    private_key_for_senders_account = web3.cpc.account.decrypt(
        encrypted_key, 'password')
    print("private_key_for_senders_account:")
    print(private_key_for_senders_account)
    print('coinbase:', web3.cpc.coinbase)
    from_addr = web3.toChecksumAddress(
        '0xCF1717B7dC2e17a53B0A9762e86C16d785ab9c3e')
    to_addr = web3.toChecksumAddress(
        '0xb3801b8743dea10c30b0c21cae8b1923d9625f84')

    print('gasPrice:', web3.cpc.gasPrice)
    # set chainId to None if you want a transaction that can be replayed across networks
    tx_dict = dict(
        type=0,
        nonce=web3.cpc.getTransactionCount(from_addr),
        gasPrice=web3.cpc.gasPrice,
        gas=900000,
        to=to_addr,
        value=1,
        data=b'',
        chainId=42,
    )
    signed_txn = web3.cpc.account.signTransaction(
        tx_dict,
        private_key_for_senders_account,
    )
    print("signed_txn:")
    print(signed_txn)

    print("sendRawTransaction:")
    print(web3.toHex(signed_txn.rawTransaction))
    print(web3.cpc.sendRawTransaction(signed_txn.rawTransaction))
Exemplo n.º 24
0
def deploy_contract(interface):
    rnode_contract_address = "0x7B4769C7d332105F8Ace1506c322597AEd7DeF59"
    cf = Web3(Web3.HTTPProvider("http://13.250.201.89:8501"))
    contract = cf.cpc.contract(abi=interface['abi'], bytecode=interface['bin'])

    estimated_gas = contract.constructor(
        "0x8f01875F462CBBc956CB9C0392dE6053A31C9C99",
        rnode_contract_address).estimateGas()
    tx_hash = contract.constructor(
        "0x8f01875F462CBBc956CB9C0392dE6053A31C9C99",
        rnode_contract_address).transact(dict(gas=estimated_gas))

    # get tx receipt to get contract address
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    address = tx_receipt['contractAddress']

    # contract = cf.cpc.contract(address=address, abi=interface['abi'])

    return address
Exemplo n.º 25
0
def test_campaign():
    config = compile_file()
    abi = config['abi']
    contract_address = "0x1404Bf355428523F8e51E68Df00A0521e413F98E"

    cf = Web3(Web3.HTTPProvider('http://192.168.123.124:8501'))

    # cf.cpc.defaultAccount = cf.cpc.accounts[0]

    campaign = cf.cpc.contract(abi=abi, address=contract_address)

    terms = campaign.functions.termIdx().call()
    start = terms - 10
    end = terms
    print("total terms: ", terms)
    num_per_term = campaign.functions.numPerRound().call()
    print(num_per_term)
    for term in range(200, 230):
        result = campaign.functions.candidatesOf(term).call()
        print("term: ", term)
        print("number of candidate: ", len(result))
        print(result)
Exemplo n.º 26
0
def test_case_7():
    cf = Web3(Web3.HTTPProvider("http://127.0.0.1:8521"))

    print("========config account=========")
    rnode = "0x6c95FEb59EF0281b3f9fD8Ec5628E1Da1d3Cc6E8"
    civilian = "0x970c18A634B23c95a61746d172C48356DB58D8EC"
    owner = "0xb3801b8743DEA10c30b0c21CAe8b1923d9625F84"
    password = "******"
    cf.personal.unlockAccount(rnode, password)
    cf.personal.unlockAccount(civilian, password)
    cf.personal.unlockAccount(owner, password)
    print("balance of rnode: ", cf.fromWei(cf.cpc.getBalance(rnode), "ether"))
    print("balance of civilian: ", cf.fromWei(cf.cpc.getBalance(civilian), "ether"))
    print("balance of owner: ", cf.fromWei(cf.cpc.getBalance(owner), "ether"))

    print("========deploy rnode contract============")
    config = compile_file()
    contract = cf.cpc.contract(abi=config["abi"], bytecode=config["bin"])
    cf.cpc.defaultAccount = owner
    estimated_gas = contract.constructor().estimateGas()
    tx_hash = contract.constructor().transact(dict(gas=estimated_gas))
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    address = tx_receipt['contractAddress']

    print("========test owner control===============")
    rnode_ins = cf.cpc.contract(abi=config["abi"], address=address)
    print("before set")
    period = rnode_ins.functions.period().call()
    print("period: ", period)
    print("civilian tries to set period")
    cf.cpc.defaultAccount = civilian
    tx_hash = rnode_ins.functions.setPeriod(2).transact({"gas": 829776, "from": civilian, "value": 0})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("result: ", tx_receipt["status"])
    period = rnode_ins.functions.period().call()
    print("period after civilian set: ", period)
    print("owner tries to set period")
    cf.cpc.defaultAccount = owner
    tx_hash = rnode_ins.functions.setPeriod(2).transact({"gas": 829776, "from": owner, "value": 0})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("result: ", tx_receipt["status"])
    period = rnode_ins.functions.period().call()
    print("period after owner set: ", period)

    print("============test version control============")
    print("rnode tries to join rnode with old version")
    cf.cpc.defaultAccount = rnode
    tx_hash = rnode_ins.functions.joinRnode(0).transact({"gas": 829776, "from": rnode, "value": cf.toWei(200001, "ether")})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("result: ", tx_receipt["status"])
    result = rnode_ins.functions.isRnode(rnode).call()
    print("is rnode: ", result)
    print("rnode tries to join rnode with new version")
    tx_hash = rnode_ins.functions.joinRnode(3).transact({"gas": 829776, "from": rnode, "value": cf.toWei(200001, "ether")})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("result: ", tx_receipt["status"])
    result = rnode_ins.functions.isRnode(rnode).call()
    print("is rnode: ", result)

    print("==========test refund===============")
    print("before refund")
    rnodes = rnode_ins.functions.getRnodes().call()
    print(rnodes)
    cf.cpc.defaultAccount = owner
    tx_hash = rnode_ins.functions.refundAll().transact({"gas": 829776, "from": owner, "value": 0})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("result: ", tx_receipt["status"])
    print("after refund")
    rnodes = rnode_ins.functions.getRnodes().call()
    print(rnodes)

    print("===========test enable================")
    enabled = rnode_ins.functions.enabled().call()
    print("before disable: ", enabled)
    print("owner disable the contract")
    cf.cpc.defaultAccount = owner
    tx_hash = rnode_ins.functions.disableContract().transact({"gas": 829776, "from": owner, "value": 0})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("result: ", tx_receipt["status"])
    enabled = rnode_ins.functions.enabled().call()
    print("after disable: ", enabled)
    print("rnode tries to join")
    result = rnode_ins.functions.isRnode(rnode).call()
    print("is rnode: ", result)
    cf.cpc.defaultAccount = rnode
    tx_hash = rnode_ins.functions.joinRnode(3).transact({"gas": 829776, "from": rnode, "value": cf.toWei(200001, "ether")})
    tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash)
    print("result: ", tx_receipt["status"])
    result = rnode_ins.functions.isRnode(rnode).call()
    print("is rnode: ", result)
Exemplo n.º 27
0
from cpc_fusion import Web3
from multiprocessing import Pool, Process


def sendtx():
    print('sending')
    for i in range(30):
        cf.cpc.sendTransaction({
            'to': account2,
            'from': cf.cpc.coinbase,
            'value': int(10),
            'gas': 200000,
            'gasPrice': 234512334421
        })


cf = Web3(Web3.HTTPProvider('http://18.136.195.148:8503'))
cf = Web3(Web3.HTTPProvider('http://127.0.0.1:8501'))

account1 = cf.toChecksumAddress('0xe94b7b6c5a0e526a4d97f9768ad6097bde25c62a')
account2 = cf.toChecksumAddress('0xc05302acebd0730e3a18a058d7d1cb1204c4a092')
# cf.personal.sendTransaction({'to': account2, 'from': cf.cpc.coinbase, 'value': 10})
if __name__ == '__main__':

    print(cf.cpc.blockNumber)

    print('\nunlock:')
    print(cf.personal.unlockAccount(account1, 'password'))
    sendtx()
def web3(geth_process, endpoint_uri):
    wait_for_http(endpoint_uri)
    _web3 = Web3(Web3.HTTPProvider(endpoint_uri))
    return _web3
Exemplo n.º 29
0
def update(data, myaddr):
    # data=json.dumps(data)
    data = str(data)
    # Solidity source code
    contract_source_code = '''
    pragma solidity ^0.4.24;

    contract Dumper {
        string public dumping;
        event test(address who,string a);
        function Dumper() public {
            dumping = '';
        }

        function setDumping(string _dumping) public {
            emit test(msg.sender,_dumping);
            dumping = _dumping;
        }

        function dump() view public returns (string) {
            return dumping;
        }
    }
    '''
    # print(contract_source_code)

    compiled_sol = compile_source(contract_source_code)  # Compiled source code
    contract_interface = compiled_sol['<stdin>:Dumper']

    # web3.py instance
    w3 = Web3(Web3.HTTPProvider('http://3.1.81.79:8501'))

    # set pre-funded account as sender
    w3.cpc.defaultAccount = w3.cpc.accounts[0]

    # Instantiate and deploy contract
    Dumper = w3.cpc.contract(abi=contract_interface['abi'],
                             bytecode=contract_interface['bin'])

    # Submit the transaction that deploys the contract
    # your keypath
    # change the keypath to your keystore file
    keypath = "./UTC--2019-04-20T23-54-49.143706400Z--13af759d94420d097c63d0b4e521d01486b2a4fe"
    # your password
    password = "******"
    # your account address
    from_addr = w3.toChecksumAddress(myaddr)
    tx_hash = Dumper.constructor().raw_transact(
        {
            # Increase or decrease gas according to contract conditions
            'gas': 819776,
            'from': from_addr,
            'value': 0
        },
        keypath,
        password,
        42)
    # tx_hash = Dumper.constructor().transact()

    # print('*********',w3.cpc.getTransactionReceipt(tx_hash_raw))
    # print('*********', w3.cpc.getTransactionReceipt(tx_hash))

    # Wait for the transaction to be mined, and get the transaction receipt
    tx_receipt = w3.cpc.waitForTransactionReceipt(tx_hash)
    # tx_receipt1 = w3.cpc.waitForTransactionReceipt(tx_hash_raw)
    # print(tx_receipt)
    # print(tx_receipt1)

    # Create the contract instance with the newly-deployed address
    dumper = w3.cpc.contract(
        address=tx_receipt.contractAddress,
        abi=contract_interface['abi'],
    )

    # Display the default dumping from the contract
    print('Default contract dumping: {}'.format(
        dumper.functions.dump().call()))

    print('Setting the dumping ...')
    tx_hash = dumper.functions.setDumping(data).raw_transact(
        {
            'gas': 300000,
            'from': from_addr,
            'value': 0,
        }, keypath, password, 42)

    # Wait for transaction to be mined...
    w3.cpc.waitForTransactionReceipt(tx_hash)

    # Display the new dumping value
    print('Updated contract dumping: {}'.format(
        dumper.functions.dump().call()))

    # When issuing a lot of reads, try this more concise reader:
    reader = ConciseContract(dumper)
    assert reader.dump() == data
Exemplo n.º 30
0
import time
import math

campaignConfig = {
    "abi": "[{\"constant\":true,\"inputs\":[],\"name\":\"termLen\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_numOfCampaign\",\"type\":\"uint256\"},{\"name\":\"_cpuNonce\",\"type\":\"uint64\"},{\"name\":\"_cpuBlockNumber\",\"type\":\"uint256\"},{\"name\":\"_memoryNonce\",\"type\":\"uint64\"},{\"name\":\"_memoryBlockNumber\",\"type\":\"uint256\"}],\"name\":\"claimCampaign\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_termIdx\",\"type\":\"uint256\"}],\"name\":\"candidatesOf\",\"outputs\":[{\"name\":\"\",\"type\":\"address[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"termIdx\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"minNoc\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"numPerRound\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"setRewardInterface\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"viewLen\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_maxNoc\",\"type\":\"uint256\"}],\"name\":\"updateMaxNoc\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_minNoc\",\"type\":\"uint256\"}],\"name\":\"updateMinNoc\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"setAdmissionAddr\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_termLen\",\"type\":\"uint256\"}],\"name\":\"updateTermLen\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_viewLen\",\"type\":\"uint256\"}],\"name\":\"updateViewLen\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_candidate\",\"type\":\"address\"}],\"name\":\"candidateInfoOf\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"maxNoc\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"updateCandidateStatus\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_admissionAddr\",\"type\":\"address\"},{\"name\":\"_rewardAddr\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"startTermIdx\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"stopTermIdx\",\"type\":\"uint256\"}],\"name\":\"ClaimCampaign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"candidate\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"payback\",\"type\":\"uint256\"}],\"name\":\"QuitCampaign\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[],\"name\":\"ViewChange\",\"type\":\"event\"}]",
    "address": "0x82104907AA699b2982Fc46f38Fd8C915d03Cdb8d",
}

rewardConfig ={
    "abi":"[{\"constant\":false,\"inputs\":[{\"name\":\"_period\",\"type\":\"uint256\"}],\"name\":\"setPeriod\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"addr\",\"type\":\"address\"}],\"name\":\"isContract\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"bonusPool\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isRNode\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"withdraw\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"nextRound\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"nextRoundStartTime\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferDeposit\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalInvestAmount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"getFreeBalance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"wantRenew\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"newRaise\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"quitRenew\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"isLocked\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isENode\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"startNewRound\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"basicCriteria\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"getLockedBalance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"getTotalBalance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"electionCriteria\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_bonus\",\"type\":\"uint256\"}],\"name\":\"setBonusPool\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"submitDeposit\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isToRenew\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"who\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"SubmitDeposit\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"who\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"WithdrawDeposit\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"who\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"JoinENodes\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"who\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"JoinRNodes\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"who\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"TransferDeposit\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"round\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"lock\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"_bonusPool\",\"type\":\"uint256\"}],\"name\":\"NewRaise\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"who\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"DepositInsufficient\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"_addr\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_iscontinue\",\"type\":\"bool\"}],\"name\":\"ContinuedInvest\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"FundBonusPool\",\"type\":\"event\"}]",
    "address": "0x94576e35a55D6BbF9bB45120bC835a668557eF42",
}



web3 = Web3(Web3.HTTPProvider('http://127.0.0.1:8521'))


campaign = web3.cpc.contract(address=campaignConfig['address'], abi=campaignConfig['abi'])

reward = web3.cpc.contract(address=rewardConfig['address'], abi=rewardConfig['abi'])

Ether = int(math.pow(10, 18))

# plaese ensure address:0xe83a71428655b9f52ff6dc556e2b37043f39f194 have max money to test
def main():
    # start new Raise
    reward.functions.newRaise().transact({
        'gas': 3000000,
        'from': web3.cpc.accounts[0],
    })