Beispiel #1
0
    def put(self, wallet_address):
        data = ApproveRequest.parser.parse_args()
        user = User.query.filter_by(username=data["username"]).first()
        account = getAccount(user, data["password"])

        # approve the request provided in the call body
        approval = approveRequest(account=account, requester=data["requester_address"], address=wallet_address)
        if approval == 1:

            # now that request is approved, get the request detail
            wallet = Wallet_Contract().Wallet(wallet_address)
            request = wallet.functions.requests(data["requester_address"]).call()

            log_activity_successAPI(user=user, request_name="manage_wallet_approve")

            return {
                "wallet_address": wallet_address,
                "request": {
                    "requester_address": request[0],
                    "company_name": request[1],
                    "request_description": request[2],
                    "is_approved": request[3],
                    "is_active": request[4]
                }
            }, 202

        else:
            log_activity_failureAPI(user=user, request_name="manage_wallet_approve")

            # if there is an error return the Solidity error message
            return {"message": approval}, 400
Beispiel #2
0
    def post(self, wallet_address):

        data = WalletRequest.parser.parse_args()
        user = User.query.filter_by(username=data["username"]).first()
        account = getAccount(user, data["password"])

        if wallet_address not in factory.functions.getDeployedWallets().call():
            log_activity_failureAPI(user=user, request_name="request_wallet_data")
            return {"message": "Wallet '{}' is not in the list of deployed wallets".format(wallet_address)}, 400

        wallet = Wallet_Contract().Wallet(wallet_address)

        request = requestData(
                    account=account,
                    wallet=wallet,
                    requester_name=data["requesterName"],
                    request_desc=data["requestDescription"]
                )
        if request == 1:

            log_activity_successAPI(user=user, request_name="request_wallet_data")

            (requester, company_name, request_description,
             is_approved, is_active) = wallet.functions.requests(account.address).call()
            return {"walletAddress": wallet_address,
                    "requester_address": requester,
                    "company_name": company_name,
                    "request_description": request_description,
                    "is_approved": is_approved,
                    "is_active": is_active}, 201

        else:
            log_activity_failureAPI(user=user, request_name="request_wallet_data")
            return {"message": request}
Beispiel #3
0
    def get(self, wallet_address):
        data = ManageWallet.parser.parse_args()
        user = User.query.filter_by(username=data["username"]).first()
        wallet = Wallet_Contract().Wallet(wallet_address)

        if wallet.functions.owner().call() != user.account_address:
            log_activity_successAPI(user=user, request_name="manage_wallet_requests")
            return {"message": "This is only available for the owner of the wallet."}

        # get list of active requests
        request_list = [
            wallet.functions.requests(i).call()
            for i in wallet.functions.getRequests().call()
        ]

        requests = [
            {
                "requester_address": r[0],
                "company_name": r[1],
                "request_description": r[2],
                "is_approved": r[3],
                "is_active": r[4]
            }
            for r in request_list
        ]

        log_activity_successAPI(user=user, request_name="manage_wallet_requests")

        return {"wallet_address": wallet_address,
                "requests": requests}
Beispiel #4
0
def getData_request(account, address):
    walletContract = wc.Wallet(address)

    eventFilter = walletContract.events.WalletData.createFilter(
        fromBlock="latest")

    try:
        transaction = walletContract.functions.getKYCData().buildTransaction({
            'from':
            account.address,
            'nonce':
            w3.eth.getTransactionCount(account.address)
        })
        signed = account.sign_transaction(transaction)
        tx_hash = w3.eth.sendRawTransaction(signed.rawTransaction)
        w3.eth.waitForTransactionReceipt(tx_hash)

    except exceptions.SolidityError as error:
        return str(error)

    while True:
        try:
            event = eventFilter.get_new_entries()[-1]
            data = event.args
            break
        except:
            pass

    return data
Beispiel #5
0
def getRequests(address):
    wallet = wc.Wallet(address)
    requests = wallet.functions.getRequests().call()

    request_data = list()

    for request in requests:
        r = wallet.functions.requests(request).call()

        data = dict()
        data['requester'] = r[0]
        data['name'] = r[1]
        data['description'] = r[2]
        data['approved'] = r[3]
        #data['active'] = r[4]
        data['wallet'] = address
        data['pos'] = len(request_data) - 1

        sub_form = ApproveWalletForm(requester=data['requester']
                                     # request_id = data['id']
                                     )
        data['form'] = sub_form
        request_data.append(data)

    return request_data
Beispiel #6
0
    def get(self, wallet_address):
        if wallet_address not in factory.functions.getDeployedWallets().call():
            return {"message": "Wallet '{}' is not in the list of deployed wallets".format(wallet_address)}, 400

        wallet = Wallet_Contract().Wallet(wallet_address)
        (manager, owner, data_request_fee,
         pending_requests, approved_requests) = wallet.functions.getWalletDetails().call()

        return {
            "walletAddress": wallet_address,
            "manager": manager,
            "owner": owner,
            "data_request_feee": str(w3.fromWei(data_request_fee, 'ether')) + ' ether',
            "pending_request_count": pending_requests,
            "approved_request_count": approved_requests,
        }, 200
Beispiel #7
0
def approveRequest(account, requester, address):
    walletContract = wc.Wallet(address)
    transaction = walletContract.functions.approveRequest(
        requester).buildTransaction({
            'nonce':
            w3.eth.getTransactionCount(account.address),
            'from':
            account.address
        })

    try:
        signed = account.sign_transaction(transaction)
        tx_hash = w3.eth.sendRawTransaction(signed.rawTransaction)
        w3.eth.waitForTransactionReceipt(tx_hash)

        return 1

    except exceptions.SolidityError as error:
        return str(error)
Beispiel #8
0
def getRequestsMade_Active(wallet_address, user_accountAddress):
    wallet = wc.Wallet(wallet_address)
    requests = wallet.functions.getApprovedRequests().call(
    )  # get active requests
    active_requests = wallet.functions.getRequests().call()

    if (user_accountAddress in requests) or (user_accountAddress
                                             in active_requests):
        r = wallet.functions.requests(user_accountAddress).call()
        if r[4]:  # check to see if the request is active

            data = dict()
            data['wallet'] = wallet_address
            data['requester'] = r[0]
            data['description'] = r[2]
            data['approved'] = r[3]
            data['active'] = r[4]

            return data
Beispiel #9
0
def home():
    wallets = factory.functions.getDeployedWallets().call()
    # remove unused wallets - will eventually fix
    wallets.remove('0x662A8010753931832BC5d38e6e42a78D38373ECF')
    wallets.remove('0x4b884576df9313210105BFDb2647319906949d90')

    form = WalletSearchForm()

    data = {"process_requests": 0, "pending_requests": 0}

    for wallet in wallets:
        walletContract = Wallet_Contract().Wallet(wallet)
        walletData = walletContract.functions.getWalletDetails().call()
        data["process_requests"] += walletData[4]
        data["pending_requests"] += walletData[3]

    factoryData = factory.functions.getFactoryData().call()
    data["createFee"] = w3.fromWei(factoryData[0], 'ether')
    data["requestFee"] = w3.fromWei(factoryData[1], 'ether')
    data["wallets"] = len(wallets)

    return render_template("home.html", wallets=wallets, form=form, data=data)
Beispiel #10
0
def getRequests_WalletData(wallet_address, user_accountAddress):
    wallet = wc.Wallet(wallet_address)
    requests = wallet.functions.getApprovedRequests().call(
    )  # get active requests
    active_requests = wallet.functions.getRequests().call()

    if (user_accountAddress in requests) or (user_accountAddress
                                             in active_requests):
        r = wallet.functions.requests(user_accountAddress).call()
        data = dict()
        data['requester'] = r[0]
        data['description'] = r[2]
        data['approved'] = r[3]
        data['active'] = r[4]
        data['wallet'] = wallet_address

        form = GetWalletDataForm(wallet=wallet_address,
                                 requester=data['requester'])

        data['form'] = form

        return data
Beispiel #11
0
def getRequestsCounts(user_accountAddress):
    data = {
        "approved": 0,
        "pending": 0,
        "expense": 0,
    }

    deployedWallets = factory.functions.getDeployedWallets().call()
    for wallet_address in deployedWallets:
        wallet = wc.Wallet(wallet_address)
        approved_requests_count = wallet.functions.getApprovedRequests().call(
        ).count(user_accountAddress)
        pending_requests_count = wallet.functions.getRequests().call().count(
            user_accountAddress)

        expense = (w3.fromWei(
            wallet.functions.serviceCost().call(),
            'ether')) * (approved_requests_count + pending_requests_count)

        data["approved"] += approved_requests_count
        data["pending"] += pending_requests_count
        data["expense"] += expense

    return data
Beispiel #12
0
def getMyWalletData(user_accountAddress):
    wallet_address = factory.functions.walletOwners(user_accountAddress).call()

    wallet = wc.Wallet(wallet_address)
    details = wallet.functions.getWalletDetails().call()
    return createWalletDict(*details)
Beispiel #13
0
def getWalletEventData(address, tx_hash):
    walletContract = wc.Wallet(address)
    eventFilter = walletContract.events.WalletData.createFilter(
        fromBlock="latest")
    event = eventFilter.get_new_entries()
    return event