Skip to content

Refactor AccountInfo class to use the staking_info #1366

@manishdait

Description

@manishdait

Problem

The current AccountInfo implementation in the SDK partially represents staking data by flattening selected fields from the protobuf StakingInfo message directly into the AccountInfo:

  • staked_account_id
  • staked_node_id
  • decline_staking_reward

However, the protobuf StakingInfo message contains additional fields (e.g. pending_reward, staked_to_me, stake_period_start) that are not represented.

This results in:

  • Loss of staking-related data
  • Inconsistency with other SDKs

Proposed Solution

  • Remove the following fields from AccountInfo:
    • staked_account_id
    • staked_node_id
    • decline_staking_reward
  • Add a single unified field:
    staking_info: Optional[StakingInfo] = None
  • In from_proto Replace manual field extraction with:
     def _from_proto(cls, proto: CryptoGetInfoResponse.AccountInfo) -> "AccountInfo":
          ...
          
          account_info: "AccountInfo" = cls(
            ...,
            staking_info=(
               StakingInfo.from_proto(proto.staking_info)
               if proto.HasField("staking_info")
               else None
             )
          )
  • Updated the to_proto to do same:
    def _to_proto(self) -> CryptoGetInfoResponse.AccountInfo:
          ...
          return CryptoGetInfoResponse.AccountInfo(
              ...,
              staking_info=(
                self.staking_info.to_proto()
                if self.staking_info is not None
                else None
              )
          )
  • Update str/repr to print staking data via the StakingInfo object instead of individual fields
  • Update unit/integration test to verify 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 examplespythonUses Python programming language

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions