Skip to content

Add support for include_children to the TransactionRecordQuery class #1512

@manishdait

Description

@manishdait

Problem

Currently, the Python SDK implementation of TransactionRecordQuery supports only the following fields:

self.transaction_id: Optional[TransactionId] = transaction_id

However, 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_children field to TransactionRecordQuery class
class TransactionRecordQuery(Query):
    def __init__(
        ...
        include_children: bool = False,
    ):
        ...
        self.include_children = include_children
  • Create a setter method set_include_children(bool).
  • Update TransactionRecord class to include the childrens field
@dataclass
class TransactionRecord:
    ....
    childrens: List[TransactionRecord] = []
  • Add a function to process the child records form the TransactionRecordQuery response
# 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 include include_child_records field 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

Labels

Blockchain / DLTIssues engineering distributed ledger functionalityenhancementNew feature or requestintermediaterequires some knowledge of the codebase with some defined steps to implement or examples

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions