【问题标题】:Cosmos how to get account address from an operator address?Cosmos 如何从运营商地址获取账户地址?
【发布时间】:2022-11-10 12:09:30
【问题描述】:

我的任务是列出所有验证者及其帐户地址。这是 RPC,它可以列出所有验证器,https://buf.build/cosmos/cosmos-sdk/docs/main:cosmos.staking.v1beta1#cosmos.staking.v1beta1.Query.Validators。验证器消息原型如下。我的问题是我如何获得验证者的账户地址,它没有账户地址。有什么建议吗?

message Validator {
  // operator_address defines the address of the validator's operator; bech encoded in JSON.
  string operator_address = 1;
  // consensus_pubkey is the consensus public key of the validator, as a Protobuf Any.
  google.protobuf.Any consensus_pubkey = 2;
  // jailed defined whether the validator has been jailed from bonded status or not.
  bool jailed = 3;
  // status is the validator status (bonded/unbonding/unbonded).
  BondStatus status = 4;
  // tokens define the delegated tokens (incl. self-delegation).
  string tokens = 5;
  // delegator_shares defines total shares issued to a validator's delegators.
  string delegator_shares = 6;
  // description defines the description terms for the validator.
  Description description = 7;
  // unbonding_height defines, if unbonding, the height at which this validator has begun unbonding.
  int64 unbonding_height = 8;
  // unbonding_time defines, if unbonding, the min time for the validator to complete unbonding.
  google.protobuf.Timestamp unbonding_time = 9;
  // commission defines the commission parameters.
  Commission commission = 10;
  // min_self_delegation is the validator's self declared minimum self delegation.
  string min_self_delegation = 11;
}

【问题讨论】:

    标签: go cosmos-sdk


    【解决方案1】:

    经过几个小时的挖掘,我在 cosmos 地址文档https://docs.cosmos.network/main/basics/accounts#addresses 中找到了答案,它说。

    每个帐户都使用地址来标识,地址是从公钥派生的字节序列。

    然后我知道运营商地址是从公钥派生的。但是可以将其转换为公钥吗?答案是肯定的,因为它们都是公共信息,只是表示/格式不同。

    valAddr, _ := sdk.ValAddressFromBech32(v.OperatorAddress)
    accAddr, _ := sdk.AccAddressFromHex(hex.EncodeToString(valAddr.Bytes()))
    fmt.Println(accAddr.String())
    // output: cosmos1q... 
    

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多