Esempio n. 1
0
def add_server_contract(contract_dir):
    pyopentxs.init()
    decoded_signed_contract = open(contract_dir + "/contract.otc").read()
    server_contract_id = open(contract_dir + "/notaryID").read().strip()
    opentxs.OTAPI_Wrap_AddServerContract(decoded_signed_contract)
    # should be just one known active server now
    server.active = [server_contract_id]
Esempio n. 2
0
def initialize_pyopentxs():
    ''' Initialize the client. If called from the runtests.py wrapper script,
    this will have already been called (along with cleaning the ot config dir)
    but calling it again appears to be harmless.

    '''
    pyopentxs.init()
Esempio n. 3
0
def setup(contract_stream, total_servers=1):
    '''
    Helps create a clean config dir starting from scratch.
    contract_stream is an input stream pointing to a template contract file.
    total_servers is an integer, of how many servers the client should have on file.
    Only the first server will actually exist, the rest will appear as offline.
    '''
    pyopentxs.init()
    server_nym = nym.Nym().create()

    contract = contract_stream.read()
    contract_stream.close()

    server_contract_id, cached_key, decoded_signed_contract \
        = make_server_contract(contract, server_nym)

    walletxml = decode(open(config_dir + "client_data/wallet.xml"))
    cached_key = BeautifulSoup(walletxml).wallet.cachedkey.string.strip()
    signed_contract_file = config_dir + "client_data/contracts/" + server_contract_id
    with closing(open(signed_contract_file)) as f:
        signed_contract = f.read()
    decoded_signed_contract = decode(io.StringIO(signed_contract))

    # copy the credentials to the server
    server_data_dir = config_dir + "server_data/"
    if not os.path.exists(server_data_dir):
        os.mkdir(server_data_dir)
    shutil.copytree(config_dir + "client_data/credentials", server_data_dir + "credentials")
    # remove the client-side data
    shutil.rmtree(config_dir + "client_data")

    # reread the client data (empty)
    pyopentxs.init()
    print("reread client data")
    # since we still don't have programmatic access, just write the info
    # to use later to pipe to the notary process
    output = io.BytesIO()
    writeit = lambda s: output.write(s.encode("utf-8"))
    writeit(server_contract_id + "\n")
    writeit(server_nym._id + "\n")
    writeit(cached_key + "\n~\n~\n")
    writeit(decoded_signed_contract + "\n~\n")

    # the following crashes the process, so we pipe the info manually
    # opentxs.MainFile(None).CreateMainFile(signed_contract, server_contract_id, "", server_nym,
    # cached_key)

    # add the server contract on the client side
    opentxs.OTAPI_Wrap_AddServerContract(decoded_signed_contract)

    # should be just one known active server now
    server.active = [server_contract_id]

    # create any extra fake servers
    for _ in range(total_servers - 1):
        opentxs.OTAPI_Wrap_AddServerContract(
            make_server_contract(contract, nym.Nym().create())[2])

    return output
Esempio n. 4
0
def setup_ot_config():
    '''Replace the OT config dir with clean data, containing only a server
       contract and client/server wallets.  Initialize the client.

    '''
    # copy the clean data directory
    print("hello!!!")
    shutil.rmtree(pyopentxs.config_dir)
    shutil.copytree("../ot-clean-data/.ot", pyopentxs.config_dir)
    pyopentxs.init()
Esempio n. 5
0
def restart():
    process_name = "opentxs-notary"
    pyopentxs.killall(process_name)

    # danger, also kill any goataries,
    # since they occupy the same port
    pyopentxs.killall("notary")

    os.system("%s > %s 2>&1 &" % (process_name, "opentxs-notary.log"))
    print("Started %s process" % process_name)
    pyopentxs.init()
Esempio n. 6
0
def restart():
    process_name = "opentxs-notary"
    pyopentxs.killall(process_name)

    # danger, also kill any goataries,
    # since they occupy the same port
    pyopentxs.killall("notary")

    os.system("%s > %s 2>&1 &" % (process_name, "opentxs-notary.log"))
    print("Started %s process" % process_name)
    pyopentxs.init()
Esempio n. 7
0
def restart():
    # pyopentxs.cleanup()
    print("cleaned up")
    # kill existing processes
    for proc in psutil.process_iter():
        if proc.name() == "opentxs-notary":
            proc.kill()
            psutil.wait_procs([proc], timeout=10)
    print("killed old notaries")
    # start new
    os.system("opentxs-notary > opentxs-notary.log 2>&1 &")
    print("Started notary process")

    # start
    pyopentxs.init()
Esempio n. 8
0
def setup(contract_stream):
    '''
    Helps create a clean config dir starting from scratch.
    '''
    pyopentxs.init()
    server_nym = nym.Nym().create()
    with closing(contract_stream):
        server_contract = server.add(server_nym._id, contract_stream.read())
    walletxml = decode(open(config_dir + "client_data/wallet.xml"))
    cached_key = BeautifulSoup(walletxml).wallet.cachedkey.string.strip()
    signed_contract_file = config_dir + "client_data/contracts/" + server_contract
    with closing(open(signed_contract_file)) as f:
        signed_contract = f.read()
    decoded_signed_contract = decode(io.StringIO(signed_contract))

    # copy the credentials to the server
    server_data_dir = config_dir + "server_data/"
    if not os.path.exists(server_data_dir):
        os.mkdir(server_data_dir)
    shutil.copytree(config_dir + "client_data/credentials",
                    server_data_dir + "credentials")
    # remove the client-side data
    shutil.rmtree(config_dir + "client_data")

    # reread the client data (empty)
    pyopentxs.init()

    # since we still don't have programmatic access, just print the info
    # for easy copying
    print(server_contract)
    print(server_nym._id)
    print(cached_key + "\n~")
    print("\n~")
    print(decoded_signed_contract + "\n~")

    # next line crashes the process
    # opentxs.MainFile(None).CreateMainFile(signed_contract, server_contract, "", server_nym,
    # cached_key)
    # add the server contract on the client side
    opentxs.OTAPI_Wrap_AddServerContract(decoded_signed_contract)

    return decoded_signed_contract
Esempio n. 9
0
def setup(contract_stream):
    '''
    Helps create a clean config dir starting from scratch.
    '''
    pyopentxs.init()
    server_nym = nym.Nym().create()
    with closing(contract_stream):
        server_contract = server.add(server_nym._id, contract_stream.read())
    walletxml = decode(open(config_dir + "client_data/wallet.xml"))
    cached_key = BeautifulSoup(walletxml).wallet.cachedkey.string.strip()
    signed_contract_file = config_dir + "client_data/contracts/" + server_contract
    with closing(open(signed_contract_file)) as f:
        signed_contract = f.read()
    decoded_signed_contract = decode(io.StringIO(signed_contract))

    # copy the credentials to the server
    server_data_dir = config_dir + "server_data/"
    if not os.path.exists(server_data_dir):
        os.mkdir(server_data_dir)
    shutil.copytree(config_dir + "client_data/credentials", server_data_dir + "credentials")
    # remove the client-side data
    shutil.rmtree(config_dir + "client_data")

    # reread the client data (empty)
    pyopentxs.init()

    # since we still don't have programmatic access, just print the info
    # for easy copying
    print(server_contract)
    print(server_nym._id)
    print(cached_key + "\n~")
    print("\n~")
    print(decoded_signed_contract + "\n~")

    # next line crashes the process
    # opentxs.MainFile(None).CreateMainFile(signed_contract, server_contract, "", server_nym,
    # cached_key)
    # add the server contract on the client side
    opentxs.OTAPI_Wrap_AddServerContract(decoded_signed_contract)

    return decoded_signed_contract
Esempio n. 10
0
def setup(contract_stream, total_servers=1):
    '''
    Helps create a clean config dir starting from scratch.
    contract_stream is an input stream pointing to a template contract file.
    total_servers is an integer, of how many servers the client should have on file.
    Only the first server will actually exist, the rest will appear as offline.
    '''
    pyopentxs.init()
    server_nym = nym.Nym().create()

    contract = contract_stream.read()
    contract_stream.close()

    server_contract_id, cached_key, decoded_signed_contract \
        = make_server_contract(contract, server_nym)

    walletxml = decode(open(config_dir + "client_data/wallet.xml"))
    cached_key = BeautifulSoup(walletxml).wallet.cachedkey.string.strip()
    signed_contract_file = config_dir + "client_data/contracts/" + server_contract_id
    with closing(open(signed_contract_file)) as f:
        signed_contract = f.read()
    decoded_signed_contract = decode(io.StringIO(signed_contract))

    # copy the credentials to the server
    server_data_dir = config_dir + "server_data/"
    if not os.path.exists(server_data_dir):
        os.mkdir(server_data_dir)
    shutil.copytree(config_dir + "client_data/credentials",
                    server_data_dir + "credentials")
    # remove the client-side data
    shutil.rmtree(config_dir + "client_data")

    # reread the client data (empty)
    pyopentxs.init()
    print("reread client data")
    # since we still don't have programmatic access, just write the info
    # to use later to pipe to the notary process
    output = io.BytesIO()
    writeit = lambda s: output.write(s.encode("utf-8"))
    writeit(server_contract_id + "\n")
    writeit(server_nym._id + "\n")
    writeit(cached_key + "\n~\n~\n")
    writeit(decoded_signed_contract + "\n~\n")

    # the following crashes the process, so we pipe the info manually
    # opentxs.MainFile(None).CreateMainFile(signed_contract, server_contract_id, "", server_nym,
    # cached_key)

    # add the server contract on the client side
    opentxs.OTAPI_Wrap_AddServerContract(decoded_signed_contract)

    # should be just one known active server now
    server.active = [server_contract_id]

    # create any extra fake servers
    for _ in range(total_servers - 1):
        opentxs.OTAPI_Wrap_AddServerContract(
            make_server_contract(contract,
                                 nym.Nym().create())[2])

    return output
Esempio n. 11
0
def fresh_setup():
    restart_opentxs_notary()
    pyopentxs.init()
Esempio n. 12
0

def restart_opentxs_notary():
    '''opentxs-notary must be on the PATH'''
    # kill existing processes
    for proc in psutil.process_iter():
        if proc.name() == "opentxs-notary":
            proc.kill()
            psutil.wait_procs([proc], timeout=10)

    create_fresh_ot_config()

    # start new
    os.system("opentxs-notary > opentxs-notary.log 2>&1 &")

    # wait for ready
    # doesn't seem to be necessary
    # time.sleep(2)


def fresh_setup():
    restart_opentxs_notary()
    pyopentxs.init()


if __name__ == "__main__":
    restart_opentxs_notary()
    pyopentxs.init()
    pytest.main(sys.argv[1:])
    pyopentxs.cleanup()
Esempio n. 13
0
def install_ot_config():
    # copy the clean data directory
    if os.path.exists(pyopentxs.config_dir):
        shutil.rmtree(pyopentxs.config_dir)
    shutil.copytree("../ot-clean-data/.ot", pyopentxs.config_dir)


def restart_opentxs_notary():
    '''opentxs-notary must be on the PATH'''
    # kill existing processes
    for proc in psutil.process_iter():
        if proc.name() == "opentxs-notary":
            proc.kill()
            psutil.wait_procs([proc], timeout=10)

    create_fresh_ot_config()
    install_ot_config()

    # start new
    os.system("opentxs-notary > opentxs-notary.log 2>&1 &")

    # wait for ready
    time.sleep(2)


if __name__ == "__main__":
    restart_opentxs_notary()
    pyopentxs.init()
    pytest.main(sys.argv[1:])
    pyopentxs.cleanup()