Cosmos 如何从运营商地址获取账户地址?
Cosmos how to get account address from an operator address?
我的任务是列出所有验证者及其帐户地址。这里是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;
}
经过几个小时的挖掘,我在 cosmos 地址文档中找到了答案,https://docs.cosmos.network/master/basics/accounts.html#addresses,它说。
Each account is identified using Address which is a sequence of bytes derived from a public key.
然后我知道运营商地址是从public密钥中导出的。但是是否可以将其转换为 public 密钥?答案是肯定的,因为两者都是public的信息,只有representation/format不同。
valAddr, _ := sdk.ValAddressFromBech32(v.OperatorAddress)
accAddr, _ := sdk.AccAddressFromHex(hex.EncodeToString(valAddr.Bytes()))
fmt.Println(accAddr.String())
// output: cosmos1q...
我的任务是列出所有验证者及其帐户地址。这里是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;
}
经过几个小时的挖掘,我在 cosmos 地址文档中找到了答案,https://docs.cosmos.network/master/basics/accounts.html#addresses,它说。
Each account is identified using Address which is a sequence of bytes derived from a public key.
然后我知道运营商地址是从public密钥中导出的。但是是否可以将其转换为 public 密钥?答案是肯定的,因为两者都是public的信息,只有representation/format不同。
valAddr, _ := sdk.ValAddressFromBech32(v.OperatorAddress)
accAddr, _ := sdk.AccAddressFromHex(hex.EncodeToString(valAddr.Bytes()))
fmt.Println(accAddr.String())
// output: cosmos1q...