-
Notifications
You must be signed in to change notification settings - Fork 185
Labels
Blockchain / DLTIssues engineering distributed ledger functionalityIssues engineering distributed ledger functionalityenhancementNew feature or requestNew feature or requestintermediaterequires some knowledge of the codebase with some defined steps to implement or examplesrequires some knowledge of the codebase with some defined steps to implement or examples
Description
Problem
Currently, the Python SDK implementation of TransactionRecordQuery supports only the following fields:
self.transaction_id: Optional[TransactionId] = transaction_idHowever, it does not expose support for requesting child transaction record, which are already supported at the Protobuff level and in other SDKs (e.g., JavaScript).
Expected Behavior:
The query should allow user to optionally request for child transaction record executed as part of a parent transaction.
Eg:
query = (
TransactionRecordQuery()
.set_transaction_id(tx_id)
.set_include_child(True) #True/False
)Solution
- Add support for an
include_childrenfield toTransactionRecordQueryclass
class TransactionRecordQuery(Query):
def __init__(
...
include_children: bool = False,
):
...
self.include_children = include_children- Create a setter method
set_include_children(bool). - Update
TransactionRecordclass to include thechildrensfield
@dataclass
class TransactionRecord:
....
childrens: List[TransactionRecord] = []- Add a function to process the child records form the
TransactionRecordQueryresponse
# Example func that convert the child_transaction_records to TransactionRecord list and then return
def _map_record_list(self, proto_records: List[transaction_get_record_pb2.TransactionGetRecordResponse]) -> List[TransactionRecord]:
records: List[TransactionRecord] = []
for record in proto_records:
records.append(TransactionRecord._from_proto(record, self.transaction_id))
return records- Update
_make_request()function of TransactionRecordQuery to includeinclude_child_recordsfield while creating the proto. - Update the
_from_proto()method of TransactionRecord and_execute()method of TransactionRecordQuery class:
# TransactionReceipt
@classmethod
def _from_proto(cls, proto: transaction_record_pb2.TransactionRecord, transaction_id: Optional[TransactionId] = None, childrens: Optional[List[TransactionRecord]] = []) -> 'TransactionRecord':
....
return cls(
........,
childrens=childrens
)
# TransactionGetReceiptQuery
def execute(self, client: Client) -> TransactionRecord:
...
childrens = self._map_record_list(response.child_transaction_records)
return TransactionRecord._from_proto(response.transactionGetRecord.transactionRecord, self.transaction_id, childrens=childrens)- Create a example for demonstrating and using these new field
- Update/Add unit and integration test for the changes
Metadata
Metadata
Assignees
Labels
Blockchain / DLTIssues engineering distributed ledger functionalityIssues engineering distributed ledger functionalityenhancementNew feature or requestNew feature or requestintermediaterequires some knowledge of the codebase with some defined steps to implement or examplesrequires some knowledge of the codebase with some defined steps to implement or examples