Skip to content

Add StakingInfo class to SDK #1364

@manishdait

Description

@manishdait

Introduce a dedicated StakingInfo SDK to represent the protobuf StakingInfo message in a structured way.
This new class should fully mirror the protobuf representation and provide consistent serialization/deserialization utilities, just like other entities in the SDK.

Protobuf Refrence

message StakingInfo {
    bool decline_reward = 1;
    Timestamp stake_period_start = 2;
    int64 pending_reward = 3;
    int64 staked_to_me = 4;
    oneof staked_id {
        AccountID staked_account_id = 5;
        int64 staked_node_id = 6;
    }
}

The class must have following characteristics:

  • Implemented it as a @dataclass

  • Fully represents all protobuf fields

     # Required Fields
    
     decline_reward: Optional[bool]
     stake_period_start: Optional[Timestamp]
     pending_reward: Optional[Hbar]
     staked_to_me: Optional[Hbar]
     staked_account_id: Optional[AccountId]
     staked_node_id: Optional[int]
  • The class should provide below mwthods:

     @classmethod
     from_proto(cls, proto: basic_types_pb2.StakingInfo) -> StakingInfo
    
     to_proto(self) -> basic_types_pb2.StakingInfo
    
     @classmethod
     from_bytes(cls, data: bytes) -> StakingInfo
    
     to_bytes(self) -> bytes

Proposed Solution

  • Create a class (@dataclass) call StackingInfo located at src/hiero_sdk_python/staking_info.py
  • Add the required fields to the class while preserving oneof semantics for staked_account_id vs staked_node_id.
  • Add the required methods to the class
  • Ensure proper validation while creating the protobuff representation from class and vice versa
  • Ensure proper deserailize and serialize using from/to bytes method
     # eg.
     from_bytes(cls, data: bytes) -> StackingInfo:
        proto = basic_types_pb2.StakingInfo.FromString(data)
        return cls.from_proto(proto)
     
     to_bytes(self) -> bytes:
        return self.to_proto().SerializeToString()
  • Add comprehensive unit tests to validate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Blockchain / DLTIssues engineering distributed ledger functionalityadvancedrequires knowledge of multiple areas in the codebase without defined steps to implement or examplesenhancementNew feature or requestpythonUses Python programming language

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions