Exemplo n.º 1
0
def send():
    """
    sends many transactions to contract.
    choose algorithm depending on 2nd CLI argument.
    """
    print("\nCurrent blockNumber = ", w3.eth.blockNumber)
    transactions_count = int(sys.argv[1])

    # choose algorithm depending on 2nd CLI argument:
    if sys.argv[2] == "accounts":
        num_accounts = 20
        if len(sys.argv) == 4:
            try:
                num_accounts = int(sys.argv[3])
            except:
                pass
        accounts = init_accounts(w3, num_accounts)
        init_account_balances(w3, accounts)
        accounts = create_signed_transactions(transactions_count, accounts)
        init_experiment_data()
        txs = broadcast_transactions(transactions_count, accounts)
    else:
        print("Nope. Choice '%s'" % sys.argv[2], "not recognized.")
        exit()

    print("%d transaction hashes recorded" % len(txs))
    return txs
Exemplo n.º 2
0
    recreates SimpleStorage contract object when given address on chain, and ABI
    """
    return w3.eth.contract(address=contract_address, abi=abi)


def save_address(contract_address):
    """
    Save contract address, to use on measure_tps.py
    """
    json.dump({"address": contract_address}, open(FILE_CONTRACT_ADDRESS, 'w'))


def init_contract(w3):
    """
    initialise contract object from address, stored in disk file by deploy.py
    """
    contract_address, abi, _ = load_contract(
        file_abi=FILE_CONTRACT_ABI,
        file_bin=FILE_CONTRACT_BIN,
        file_address=FILE_CONTRACT_ADDRESS)
    contract = w3.eth.contract(address=contract_address, abi=abi)
    return contract


if __name__ == '__main__':
    global w3
    w3 = init_web3(RPCaddress=RPC_NODE_SEND)
    # Init the first account to deploy contract
    account = init_accounts(w3, 1).get(0)
    deploy(account)
                'nonce': n + 2,
            }))
        txs[tx_hash] = raw_tx
        hashes.append(tx_hash)
    cli.sendTransactions(txs)

    ret_accounts = [0] * len(accounts)
    receipts = wait_for_receipts(cli, hashes)
    for i in range(len(hashes)):
        receipt = receipts[hashes[i]]
        if receipt['status'] != 1:
            ret_accounts[int(i / 2 + count)] = accounts[i + count]
            print(receipt)
            continue
        processed_receipt = kitty_core_contract.processReceipt(receipt)
        if 'Transfer' in processed_receipt:
            ret_accounts[int(i / 2)] = accounts[i + count]
            ret_accounts[int(i / 2 + count * 2)] = accounts[int(i / 2)]
            print(processed_receipt)
    return ret_accounts, kitties


users = init_accounts(private_key)
kitties = buy(users)
print(kitties)
n = 2
while True:
    users, kitties = transfer(users, kitties, n)
    n += 2
    time.sleep(10)