This is an automated email from the ASF dual-hosted git repository.
apratim pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-resilientdb-graphql.git
The following commit(s) were added to refs/heads/main by this push:
new 125b1b4 Removed mutations and queries that are no longer supported
125b1b4 is described below
commit 125b1b4bd5699d1a92a6a209694fa45943adda32
Author: apratimshukla6 <[email protected]>
AuthorDate: Wed Nov 20 12:43:51 2024 -0800
Removed mutations and queries that are no longer supported
---
app.py | 95 --------------------------------------------------------
filter.py | 104 --------------------------------------------------------------
2 files changed, 199 deletions(-)
diff --git a/app.py b/app.py
index bdeece0..744b6cb 100644
--- a/app.py
+++ b/app.py
@@ -10,7 +10,6 @@ import strawberry
import typing
import ast
from typing import Optional, List
-from filter import filter_by_keys
from flask import Flask
from flask_cors import CORS
@@ -46,53 +45,6 @@ class PrepareAsset:
recipientPublicKey: str
asset: str
[email protected]
-class UpdateAsset:
- id: str
- operation: typing.Optional["str"]
- amount: typing.Optional["int"]
- signerPublicKey: str
- signerPrivateKey: str
- recipientPublicKey: typing.Optional["str"]
- asset: typing.Optional["str"]
-
[email protected]
-class FilterKeys:
- ownerPublicKey: Optional[str]
- recipientPublicKey: Optional[str]
-
[email protected]
-class Keys:
- publicKey: str
- privateKey: str
-
-def update(data):
- record = db.transactions.retrieve(data.id)
- prepared_token_tx = db.transactions.prepare(
- operation=record["operation"] if data.operation == "" else data.operation,
- signers=data.signerPublicKey,
- recipients=[([record["outputs"][0]["condition"]["details"]["public_key"]
if data.recipientPublicKey == "" else data.recipientPublicKey],
record["outputs"][0]["amount"] if data.amount == "" else data.amount)],
- asset=record["asset"] if data.asset == "" else
ast.literal_eval(data.asset),
- )
-
- # fulfill the tnx
- fulfilled_token_tx = db.transactions.fulfill(prepared_token_tx,
private_keys=data.signerPrivateKey)
-
- id = db.transactions.send_commit(fulfilled_token_tx)[4:] # Extract ID
- data = db.transactions.retrieve(txid=id)
- payload = RetrieveTransaction(
- id=data["id"],
- version=data["version"],
- amount=data["outputs"][0]["amount"],
- uri=data["outputs"][0]["condition"]["uri"],
- type=data["outputs"][0]["condition"]["details"]["type"],
- publicKey=data["outputs"][0]["condition"]["details"]["public_key"],
- operation=data["operation"],
- metadata=data["metadata"],
- asset=str(data["asset"])
- )
- return payload
-
@strawberry.type
class Query:
@strawberry.field
@@ -111,32 +63,6 @@ class Query:
asset=str(data["asset"])
)
return payload
-
- @strawberry.field
- def getFilteredTransactions(self, filter: Optional[FilterKeys]) ->
List[RetrieveTransaction]:
- url = f"{protocol}{db_root_url}{fetch_all_endpoint}"
- if filter.ownerPublicKey != None:
- filter.ownerPublicKey = filter.ownerPublicKey if
filter.ownerPublicKey.strip() else None
- if filter.recipientPublicKey != None:
- filter.recipientPublicKey = filter.recipientPublicKey if
filter.recipientPublicKey.strip() else None
- json_data = filter_by_keys(url, filter.ownerPublicKey,
filter.recipientPublicKey)
- records = []
- for data in json_data:
- try:
- records.append(RetrieveTransaction(
- id=data["id"],
- version=data["version"],
- amount=data["outputs"][0]["amount"],
- uri=data["outputs"][0]["condition"]["uri"],
- type=data["outputs"][0]["condition"]["details"]["type"],
-
publicKey=data["outputs"][0]["condition"]["details"]["public_key"],
- operation=data["operation"],
- metadata=data["metadata"],
- asset=str(data["asset"])
- ))
- except Exception as e:
- print(e)
- return records
@strawberry.type
class Mutation:
@@ -157,27 +83,6 @@ class Mutation:
id=id
)
return payload
-
- @strawberry.mutation
- def updateTransaction(self, data: UpdateAsset) -> RetrieveTransaction:
- return update(data)
-
- @strawberry.mutation
- def updateMultipleTransaction(self, data: List[UpdateAsset]) ->
List[RetrieveTransaction]:
- result = []
- for transaction in data:
- result.append(update(transaction))
- return result
-
- @strawberry.mutation
- def generateKeys(self) -> Keys:
- keys = generate_keypair()
- payload = Keys(
- publicKey=keys.public_key,
- privateKey=keys.private_key
- )
- return payload
-
schema = strawberry.Schema(query=Query, mutation=Mutation)
diff --git a/filter.py b/filter.py
deleted file mode 100644
index ce96e9e..0000000
--- a/filter.py
+++ /dev/null
@@ -1,104 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-
-import requests
-import json
-
-def fix_json_with_commas(mixed_content):
- # Manually parsing the JSON objects by counting braces
- json_objects = []
- brace_count = 0
- current_json = ''
- in_json = False
-
- for char in mixed_content:
- if char == '{':
- if brace_count == 0:
- in_json = True
- current_json = char
- else:
- current_json += char
- brace_count += 1
- elif char == '}':
- brace_count -= 1
- if brace_count == 0 and in_json:
- current_json += char
- json_objects.append(current_json)
- in_json = False
- else:
- current_json += char
- elif in_json:
- current_json += char
-
- # Combine all JSON blocks into a valid JSON array string
- combined_json = '[' + ','.join(json_objects) + ']'
- return combined_json
-
-def get_json_objects_by_public_key(json_data, owner_public_key=None,
recipient_public_key=None):
- matching_objects = []
- for obj in json_data:
- try:
- # Check if the necessary fields are present
- if 'inputs' in obj and 'outputs' in obj:
- if owner_public_key is not None and recipient_public_key is
not None:
- if owner_public_key in obj['inputs'][0]['owners_before']
and recipient_public_key in obj['outputs'][0]['public_keys']:
- matching_objects.append(obj)
- elif owner_public_key is None and recipient_public_key is not
None:
- if recipient_public_key in
obj['outputs'][0]['public_keys']:
- matching_objects.append(obj)
- elif owner_public_key is not None and recipient_public_key is
None:
- if owner_public_key in obj['inputs'][0]['owners_before']:
- matching_objects.append(obj)
- else:
- matching_objects.append(obj) # Append all if no keys
specified
- except Exception as e:
- print(f"Error processing JSON object: {e}")
- return matching_objects
-
-def get_json_data(url, ownerPublicKey=None, recipientPublicKey=None):
- try:
- response = requests.get(url)
- # Check if the request was successful (status code 200)
- if response.status_code == 200:
- # Parse the JSON data from the response
- json_text = fix_json_with_commas(response.text)
- json_data = json.loads(json_text)
- if ownerPublicKey == None and recipientPublicKey == None:
- matching_objects = get_json_objects_by_public_key(json_data,
None, None)
- return matching_objects
- elif ownerPublicKey == None and recipientPublicKey != None:
- matching_objects = get_json_objects_by_public_key(json_data,
None, recipientPublicKey)
- return matching_objects
- elif ownerPublicKey != None and recipientPublicKey == None:
- matching_objects = get_json_objects_by_public_key(json_data,
ownerPublicKey, None)
- return matching_objects
- else:
- # Get all JSON objects that match the given publicKey
- matching_objects = get_json_objects_by_public_key(json_data,
ownerPublicKey, recipientPublicKey)
- return matching_objects
- else:
- print(f"Error: Unable to retrieve data from {url}. Status code:
{response.status_code}")
- return None
-
- except requests.exceptions.RequestException as e:
- print(f"Error: {e}")
- return None
-
-def filter_by_keys(url, ownerPublicKey, recipientPublicKey):
- json_data = get_json_data(url, ownerPublicKey, recipientPublicKey)
- return json_data