def _load_limit(safe, token): encoded_limit = call(TRANSFER_LIMIT_MODULE, data=_build_get_limit_payload(safe, token)) limit_array = _split_eth_data(encoded_limit[2:]) return { "amount": parse_int_or_hex("0x" + limit_array[0]), "spend": parse_int_or_hex("0x" + limit_array[1]), "resetTimeMin": parse_int_or_hex("0x" + limit_array[2]), "lastTransferMin": parse_int_or_hex("0x" + limit_array[3]), "nonce": parse_int_or_hex("0x" + limit_array[4]) }
def get_limit_transfer_hash(request, safe, token ): if _validate_address(safe): return Response({"error": "invalid safe address (format: <40 hex chars>)"}, 400) if _validate_address(token): return Response({"error": "invalid token address (format: <40 hex chars>)"}, 400) try: limit = _load_limit(safe, token) except RpcException as e: return Response({"error": "Could not fetch limit (%s)" % e}, 400) target = request.data.get("target") if _validate_address(target): return Response({"error": "invalid target address (format: <40 hex chars>)"}, 400) try: amount = parse_int_or_hex(request.data.get("amount")) except Exception: return Response({"error": "invalid amount provided (format: hex or decimal number)"}, 400) try: # account, token, to, amount, paymentToken, payment, nonce transferLimitHash = call(TRANSFER_LIMIT_MODULE, data = _build_get_transfer_hash_payload( safe, token, target, amount, "0x0", 0, limit.get("nonce") )) except RpcException as e: return Response({"error": "Could get transfer limit hash (%s)" % e}, 400) return Response({"hash": transferLimitHash})
def _estimate_transaction_eoa(address, value=0, data=""): data = { "from": sender, "to": address, "value": "0x0" if value == 0 else int_to_hex(value), "data": data } response = rpc_call("eth_estimateGas", [data]) result = response.get("result") if not result: raise RpcException(response.get("error")) return {'estimate': parse_int_or_hex(result)}
def execute_limit_transfer(request, safe, token): if _validate_address(safe): return Response({"error": "invalid safe address (format: <40 hex chars>)"}, 400) if _validate_address(token): return Response({"error": "invalid token address (format: <40 hex chars>)"}, 400) try: limit = _load_limit(safe, token) except RpcException as e: return Response({"error": "Could not fetch limit (%s)" % e}, 400) target = request.data.get("target") if _validate_address(target): return Response({"error": "invalid target address (format: <40 hex chars>)"}, 400) try: amount = parse_int_or_hex(request.data.get("amount")) except Exception: return Response({"error": "invalid amount provided (format: hex or decimal number)"}, 400) try: signature = request.data["signature"] except Exception: return Response({"error": "invalid signature provided (format: hex-string)"}, 400) try: params = _estimate_transaction(TRANSFER_LIMIT_MODULE, data = _build_execute_transfer_limit_payload( safe, token, target, amount, "0x0", 0, signature )) except RpcException as e: return Response({"error": "Could not estimate transfer (%s)" % e}, 400) try: tx_hash = _send_transaction(TRANSFER_LIMIT_MODULE, params, data = _build_execute_transfer_limit_payload( safe, token, target, amount, "0x0", 0, signature )) except RpcException as e: return Response({"error": "Could perform transfer (%s)" % e}, 400) return Response({"hash": tx_hash})
def submit_instant_transfer(request, safe, delegate, token): if _validate_address(safe): return Response({"error": "invalid safe address (format: <40 hex chars>)"}, 400) if _validate_address(delegate): return Response({"error": "invalid delegate address (format: <40 hex chars>)"}, 400) if _validate_address(token): return Response({"error": "invalid token address (format: <40 hex chars>)"}, 400) target = request.data.get("target") if _validate_address(target): return Response({"error": "invalid target address (format: <40 hex chars>)"}, 400) try: amount = parse_int_or_hex(request.data.get("amount")) except Exception: return Response({"error": "invalid amount provided (format: hex or decimal number)"}, 400) try: signature = request.data["signature"] except Exception: return Response({"error": "invalid signature provided (format: hex-string)"}, 400) execution_payload = _build_execute_allowance_transfer_payload( safe, token, target, amount, "0x0", 0, delegate, signature ) try: params = _estimate_transaction(ALLOWANCE_LIMIT_MODULE, data = execution_payload) except RpcException as e: return Response({"error": "Could not estimate transfer with %s (%s)" % (execution_payload, e)}, 400) try: tx_hash = _send_transaction(ALLOWANCE_LIMIT_MODULE, params, data = execution_payload) except RpcException as e: return Response({"error": "Could perform transfer with %s (%s)" % (execution_payload, e)}, 400) return Response({"hash": tx_hash})
def _get_nonce(): return parse_int_or_hex( rpc_result("eth_getTransactionCount", [sender, "pending"]))