Exemplo n.º 1
0
def signup(username, password) -> Tuple[Enterprise, Signer_Impl]:
    try:
        signer = create_account(username, password)

        enterprise = Enterprise(username=username, password=password)

        contract_addr = deploy_contract("Enterprise", signer=signer)
        enterprise.contract_addr = contract_addr
        enterprise.account_addr = str(signer.keypair.address)
        enterprise.account_pub = str(signer.keypair.public_key)
        enterprise.account_priv = str(signer.keypair.private_key)

        privkey, pubkey = gen_rsakey()
        enterprise.envelope_pub = pubkey
        enterprise.envelope_priv = privkey

        managementAddr = db.session.query(Contracts).filter(
            Contracts.name == "Management").first().addr
        call_contract(managementAddr,
                      "Management",
                      "addEnterprise",
                      args=[
                          username,
                          to_checksum_address(enterprise.account_addr),
                          to_checksum_address(enterprise.contract_addr),
                          enterprise.envelope_pub, ""
                      ])

        db.session.add(enterprise)
        db.session.commit()
    except Exception:
        traceback.print_exc()
        db.session.rollback()
        return None, None
    return enterprise, signer
Exemplo n.º 2
0
def signup(username, password) -> Tuple[Agency, Signer_Impl]:
    try:
        signer = create_account(username, password)

        agency = Agency(username = username, password = password)

        contract_addr = deploy_contract("Agency", signer = signer)
        agency.contract_addr = contract_addr
        agency.account_addr = str(signer.keypair.address)
        agency.account_pub = str(signer.keypair.public_key)
        agency.account_priv = str(signer.keypair.private_key)

        privkey, pubkey = gen_rsakey()
        agency.envelope_pub = pubkey
        agency.envelope_priv = privkey

        managementAddr = db.session.query(Contracts).filter(Contracts.name == "Management").first().addr
        EngineerListAddr = db.session.query(Contracts).filter(Contracts.name == "EngineerList").first().addr
        creditAddr = db.session.query(Contracts).filter(Contracts.name == "Credit").first().addr

        call_contract(contract_addr, "Agency", "setEngListAddr", args = [to_checksum_address(EngineerListAddr)], signer = signer)
        call_contract(contract_addr, "Agency", "setCreditAddr", args = [to_checksum_address(creditAddr)], signer = signer)
        agency.engineer_list_addr = EngineerListAddr

        # call_contract2(managementAddr, "Management", "addAgency", 
        #     args = [
        #         username, 
        #         to_checksum_address(agency.account_addr),
        #         to_checksum_address(agency.contract_addr),
        #         agency.envelope_pub, "" ], signer = signer)

    
        call_contract(managementAddr, "Management", "addAgency", 
            args = [
                username, 
                to_checksum_address(agency.account_addr),
                to_checksum_address(agency.contract_addr),
                agency.envelope_pub, ""], signer = signer)

        db.session.add(agency)
        db.session.commit()
    except Exception:
        traceback.print_exc()
        db.session.rollback()
        return None, None
    return agency, signer
Exemplo n.º 3
0
def audit_arbitrate():
    username = session.get("username", "")
    password = session.get("password", "")
    audit, signer = login(username, password)

    if audit is None:
        return redirect("/audit")

    arbitrate_list = Arbitrate.query.all()

    if request.method == "GET":
        return render_template("audit2-5.html",
                               is_login=True,
                               audit=audit,
                               username=username,
                               arbitrate_list=arbitrate_list)

    ent_addr = request.form.get("ent-addr", "")

    if ent_addr == "":
        return render_template("audit2-5.html",
                               is_login=True,
                               audit=audit,
                               username=username,
                               arbitrate_list=arbitrate_list,
                               fail_msg="企业名称错误")

    enterprise = Enterprise.query.filter(
        Enterprise.username == ent_addr).first()
    if enterprise is None:
        return render_template("audit2-5.html",
                               is_login=True,
                               audit=audit,
                               username=username,
                               arbitrate_list=arbitrate_list,
                               fail_msg="没有该实体")

    if enterprise.license_addr is None or enterprise.license_addr == "":
        return render_template("audit2-5.html",
                               is_login=True,
                               audit=audit,
                               username=username,
                               arbitrate_list=arbitrate_list,
                               fail_msg="该企业暂无证书")

    try:
        arbitrate_addr = deploy_contract(
            "Arbitrate",
            compile=False,
            fn_args=[to_checksum_address(enterprise.contract_addr)],
            signer=signer)

        arbitrate = Arbitrate(addr=arbitrate_addr)
        db.session.add(arbitrate)
        db.session.commit()

        arbitrate_list = Arbitrate.query.all()
    except Exception:
        traceback.print_exc()
        return render_template("audit2-5.html",
                               is_login=True,
                               audit=audit,
                               username=username,
                               arbitrate_list=arbitrate_list,
                               fail_msg="仲裁合约部署失败")

    return render_template("audit2-5.html",
                           is_login=True,
                           audit=audit,
                           username=username,
                           arbitrate_list=arbitrate_list)
Exemplo n.º 4
0
    action='store_true',
    help='Deploys registrar and certificates contracts to the blockchain')
parser.add_argument('--owner',
                    nargs=1,
                    metavar='CONTRACT',
                    help='Prints current owner of the contract')
parser.add_argument('--chown',
                    nargs=2,
                    metavar=('CONTRACT', 'NEW_OWNER'),
                    help='Changes owner of the specified contract')

args = parser.parse_args()

if args.deploy:
    nonce = get_owner_nonce()
    registrar = deploy_contract('registrar', nonce)
    print('KYC Registrar: %s' % registrar['address'])
    set('registrar.registrar', registrar)

    certificates = deploy_contract('certificates', nonce + 1)
    print('Payment Handler: %s' % certificates['address'])
    set('registrar.payments', certificates)

if args.owner:
    contract = args.owner[0]

    if contract == 'registrar':
        print('Admin account: %s' % get_owner())

if args.chown:
    contract = args.chown[0]