Skip to content

Commit

Permalink
Merge pull request #451 from cosmology-tech/pubkey-logic
Browse files Browse the repository at this point in the history
Pubkey logic
  • Loading branch information
Zetazzz committed Aug 18, 2023
2 parents 189e40d + ec04dc5 commit 078f8d1
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 319 deletions.
19 changes: 5 additions & 14 deletions __fixtures__/output1/cosmos/staking/v1beta1/tx.amino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Description, DescriptionSDKType, CommissionRates, CommissionRatesSDKTyp
import { Any, AnySDKType } from "../../../google/protobuf/any";
import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import { Timestamp, TimestampSDKType } from "../../../google/protobuf/timestamp";
import { AminoMsg, decodeBech32Pubkey, encodeBech32Pubkey } from "@cosmjs/amino";
import { fromBase64, toBase64 } from "@cosmjs/encoding";
import { AminoMsg, Pubkey } from "@cosmjs/amino";
import { decodePubkey, encodePubkey } from "@cosmjs/proto-signing";
import { Long } from "../../../helpers";
import { MsgCreateValidator, MsgCreateValidatorSDKType, MsgEditValidator, MsgEditValidatorSDKType, MsgDelegate, MsgDelegateSDKType, MsgBeginRedelegate, MsgBeginRedelegateSDKType, MsgUndelegate, MsgUndelegateSDKType } from "./tx";
export interface MsgCreateValidatorAminoType extends AminoMsg {
Expand All @@ -24,10 +24,7 @@ export interface MsgCreateValidatorAminoType extends AminoMsg {
min_self_delegation: string;
delegator_address: string;
validator_address: string;
pubkey: {
type_url: string;
value: Uint8Array;
};
pubkey: Pubkey;
value: {
denom: string;
amount: string;
Expand Down Expand Up @@ -111,10 +108,7 @@ export const AminoConverter = {
min_self_delegation: minSelfDelegation,
delegator_address: delegatorAddress,
validator_address: validatorAddress,
pubkey: {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(pubkey).value)
},
pubkey: decodePubkey(pubkey)!,
value: {
denom: value.denom,
amount: Long.fromValue(value.amount).toString()
Expand Down Expand Up @@ -146,10 +140,7 @@ export const AminoConverter = {
minSelfDelegation: min_self_delegation,
delegatorAddress: delegator_address,
validatorAddress: validator_address,
pubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(pubkey.value)
}, "cosmos"),
pubkey: encodePubkey(pubkey),
value: {
denom: value.denom,
amount: value.amount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Description, DescriptionSDKType, CommissionRates, CommissionRatesSDKTyp
import { Any, AnySDKType } from "../../../google/protobuf/any";
import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import { Timestamp, TimestampSDKType } from "../../../google/protobuf/timestamp";
import { AminoMsg, decodeBech32Pubkey, encodeBech32Pubkey } from "@cosmjs/amino";
import { fromBase64, toBase64 } from "@cosmjs/encoding";
import { AminoMsg, Pubkey } from "@cosmjs/amino";
import { decodePubkey, encodePubkey } from "@cosmjs/proto-signing";
import { MsgCreateValidator, MsgCreateValidatorSDKType, MsgEditValidator, MsgEditValidatorSDKType, MsgDelegate, MsgDelegateSDKType, MsgBeginRedelegate, MsgBeginRedelegateSDKType, MsgUndelegate, MsgUndelegateSDKType } from "./tx";
export interface MsgCreateValidatorAminoType extends AminoMsg {
type: "cosmos-sdk/MsgCreateValidator";
Expand All @@ -23,10 +23,7 @@ export interface MsgCreateValidatorAminoType extends AminoMsg {
min_self_delegation: string;
delegator_address: string;
validator_address: string;
pubkey: {
type_url: string;
value: Uint8Array;
};
pubkey: Pubkey;
value: {
denom: string;
amount: string;
Expand Down Expand Up @@ -110,10 +107,7 @@ export const AminoConverter = {
min_self_delegation: minSelfDelegation,
delegator_address: delegatorAddress,
validator_address: validatorAddress,
pubkey: {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(pubkey).value)
},
pubkey: decodePubkey(pubkey)!,
value: {
denom: value.denom,
amount: value.amount
Expand Down Expand Up @@ -145,10 +139,7 @@ export const AminoConverter = {
minSelfDelegation: min_self_delegation,
delegatorAddress: delegator_address,
validatorAddress: validator_address,
pubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(pubkey.value)
}, "cosmos"),
pubkey: encodePubkey(pubkey),
value: {
denom: value.denom,
amount: value.amount
Expand Down
23 changes: 5 additions & 18 deletions __fixtures__/v-next/outputv2/cosmos/staking/v1beta1/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { Duration, DurationAmino, DurationSDKType } from "../../../google/protob
import { Coin, CoinAmino, CoinSDKType } from "../../base/v1beta1/coin";
import { Long, isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import * as _m0 from "protobufjs/minimal";
import { toBase64, fromBase64 } from "@cosmjs/encoding";
import { encodeBech32Pubkey, decodeBech32Pubkey } from "@cosmjs/amino";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
export const protobufPackage = "cosmos.staking.v1beta1";
/** BondStatus is the status of a validator. */
export enum BondStatus {
Expand Down Expand Up @@ -1484,10 +1483,7 @@ export const Validator = {
fromAmino(object: ValidatorAmino): Validator {
return {
operatorAddress: object.operator_address,
consensusPubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(object.consensus_pubkey.value)
}, "cosmos"),
consensusPubkey: object?.consensus_pubkey ? encodePubkey(object.consensus_pubkey) : undefined,
jailed: object.jailed,
status: isSet(object.status) ? bondStatusFromJSON(object.status) : -1,
tokens: object.tokens,
Expand All @@ -1502,10 +1498,7 @@ export const Validator = {
toAmino(message: Validator): ValidatorAmino {
const obj: any = {};
obj.operator_address = message.operatorAddress;
obj.consensus_pubkey = message.consensusPubkey ? {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(message.consensusPubkey).value)
} : undefined;
obj.consensus_pubkey = message.consensusPubkey ? decodePubkey(message.consensusPubkey) : undefined;
obj.jailed = message.jailed;
obj.status = message.status;
obj.tokens = message.tokens;
Expand Down Expand Up @@ -3290,14 +3283,8 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: _m0.Reader | Uint8Ar
}
};
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(content.value)
}, "cosmos");
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any) => {
return {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(content).value)
};
return decodePubkey(content);
};
23 changes: 5 additions & 18 deletions __fixtures__/v-next/outputv2/cosmos/staking/v1beta1/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Coin, CoinAmino, CoinSDKType } from "../../base/v1beta1/coin";
import { Timestamp } from "../../../google/protobuf/timestamp";
import * as _m0 from "protobufjs/minimal";
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { toBase64, fromBase64 } from "@cosmjs/encoding";
import { encodeBech32Pubkey, decodeBech32Pubkey } from "@cosmjs/amino";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
export const protobufPackage = "cosmos.staking.v1beta1";
/** MsgCreateValidator defines a SDK message for creating a new validator. */
export interface MsgCreateValidator {
Expand Down Expand Up @@ -414,10 +413,7 @@ export const MsgCreateValidator = {
minSelfDelegation: object.min_self_delegation,
delegatorAddress: object.delegator_address,
validatorAddress: object.validator_address,
pubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(object.pubkey.value)
}, "cosmos"),
pubkey: object?.pubkey ? encodePubkey(object.pubkey) : undefined,
value: object?.value ? Coin.fromAmino(object.value) : undefined
};
},
Expand All @@ -428,10 +424,7 @@ export const MsgCreateValidator = {
obj.min_self_delegation = message.minSelfDelegation;
obj.delegator_address = message.delegatorAddress;
obj.validator_address = message.validatorAddress;
obj.pubkey = message.pubkey ? {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(message.pubkey).value)
} : undefined;
obj.pubkey = message.pubkey ? decodePubkey(message.pubkey) : undefined;
obj.value = message.value ? Coin.toAmino(message.value) : undefined;
return obj;
},
Expand Down Expand Up @@ -1344,14 +1337,8 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: _m0.Reader | Uint8Ar
}
};
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(content.value)
}, "cosmos");
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any) => {
return {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(content).value)
};
return decodePubkey(content);
};
23 changes: 5 additions & 18 deletions __fixtures__/v-next/outputv3/cosmos/staking/v1beta1/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { Duration, DurationAmino, DurationSDKType } from "../../../google/protob
import { Coin, CoinAmino, CoinSDKType } from "../../base/v1beta1/coin";
import { Long, isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import * as _m0 from "protobufjs/minimal";
import { toBase64, fromBase64 } from "@cosmjs/encoding";
import { encodeBech32Pubkey, decodeBech32Pubkey } from "@cosmjs/amino";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
export const protobufPackage = "cosmos.staking.v1beta1";
/** BondStatus is the status of a validator. */
export enum BondStatus {
Expand Down Expand Up @@ -1484,10 +1483,7 @@ export const Validator = {
fromAmino(object: ValidatorAmino): Validator {
return {
operatorAddress: object.operator_address,
consensusPubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(object.consensus_pubkey.value)
}, "cosmos"),
consensusPubkey: object?.consensus_pubkey ? encodePubkey(object.consensus_pubkey) : undefined,
jailed: object.jailed,
status: isSet(object.status) ? bondStatusFromJSON(object.status) : -1,
tokens: object.tokens,
Expand All @@ -1502,10 +1498,7 @@ export const Validator = {
toAmino(message: Validator): ValidatorAmino {
const obj: any = {};
obj.operator_address = message.operatorAddress;
obj.consensus_pubkey = message.consensusPubkey ? {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(message.consensusPubkey).value)
} : undefined;
obj.consensus_pubkey = message.consensusPubkey ? decodePubkey(message.consensusPubkey) : undefined;
obj.jailed = message.jailed;
obj.status = message.status;
obj.tokens = message.tokens;
Expand Down Expand Up @@ -3290,14 +3283,8 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: _m0.Reader | Uint8Ar
}
};
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(content.value)
}, "cosmos");
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any) => {
return {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(content).value)
};
return decodePubkey(content);
};
23 changes: 5 additions & 18 deletions __fixtures__/v-next/outputv3/cosmos/staking/v1beta1/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Coin, CoinAmino, CoinSDKType } from "../../base/v1beta1/coin";
import { Timestamp, TimestampAmino, TimestampSDKType } from "../../../google/protobuf/timestamp";
import * as _m0 from "protobufjs/minimal";
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { toBase64, fromBase64 } from "@cosmjs/encoding";
import { encodeBech32Pubkey, decodeBech32Pubkey } from "@cosmjs/amino";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
export const protobufPackage = "cosmos.staking.v1beta1";
/** MsgCreateValidator defines a SDK message for creating a new validator. */
export interface MsgCreateValidator {
Expand Down Expand Up @@ -414,10 +413,7 @@ export const MsgCreateValidator = {
minSelfDelegation: object.min_self_delegation,
delegatorAddress: object.delegator_address,
validatorAddress: object.validator_address,
pubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(object.pubkey.value)
}, "cosmos"),
pubkey: object?.pubkey ? encodePubkey(object.pubkey) : undefined,
value: object?.value ? Coin.fromAmino(object.value) : undefined
};
},
Expand All @@ -428,10 +424,7 @@ export const MsgCreateValidator = {
obj.min_self_delegation = message.minSelfDelegation;
obj.delegator_address = message.delegatorAddress;
obj.validator_address = message.validatorAddress;
obj.pubkey = message.pubkey ? {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(message.pubkey).value)
} : undefined;
obj.pubkey = message.pubkey ? decodePubkey(message.pubkey) : undefined;
obj.value = message.value ? Coin.toAmino(message.value) : undefined;
return obj;
},
Expand Down Expand Up @@ -1344,14 +1337,8 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: _m0.Reader | Uint8Ar
}
};
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(content.value)
}, "cosmos");
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any) => {
return {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(content).value)
};
return decodePubkey(content);
};
19 changes: 5 additions & 14 deletions __fixtures__/v-next/outputv4/cosmos/staking/v1beta1/tx.amino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Description, DescriptionSDKType, CommissionRates, CommissionRatesSDKTyp
import { Any, AnySDKType } from "../../../google/protobuf/any";
import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import { Timestamp, TimestampSDKType } from "../../../google/protobuf/timestamp";
import { AminoMsg, decodeBech32Pubkey, encodeBech32Pubkey } from "@cosmjs/amino";
import { fromBase64, toBase64 } from "@cosmjs/encoding";
import { AminoMsg, Pubkey } from "@cosmjs/amino";
import { decodePubkey, encodePubkey } from "@cosmjs/proto-signing";
import { MsgCreateValidator, MsgCreateValidatorSDKType, MsgEditValidator, MsgEditValidatorSDKType, MsgDelegate, MsgDelegateSDKType, MsgBeginRedelegate, MsgBeginRedelegateSDKType, MsgUndelegate, MsgUndelegateSDKType } from "./tx";
export interface MsgCreateValidatorAminoType extends AminoMsg {
type: "cosmos-sdk/MsgCreateValidator";
Expand All @@ -23,10 +23,7 @@ export interface MsgCreateValidatorAminoType extends AminoMsg {
min_self_delegation: string;
delegator_address: string;
validator_address: string;
pubkey: {
type_url: string;
value: Uint8Array;
};
pubkey: Pubkey;
value: {
denom: string;
amount: string;
Expand Down Expand Up @@ -110,10 +107,7 @@ export const AminoConverter = {
min_self_delegation: minSelfDelegation,
delegator_address: delegatorAddress,
validator_address: validatorAddress,
pubkey: {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(pubkey).value)
},
pubkey: decodePubkey(pubkey)!,
value: {
denom: value.denom,
amount: value.amount
Expand Down Expand Up @@ -145,10 +139,7 @@ export const AminoConverter = {
minSelfDelegation: min_self_delegation,
delegatorAddress: delegator_address,
validatorAddress: validator_address,
pubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(pubkey.value)
}, "cosmos"),
pubkey: encodePubkey(pubkey),
value: {
denom: value.denom,
amount: value.amount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ exports[`cosmos/staking/v1beta1/tx AminoConverter 1`] = `
min_self_delegation: minSelfDelegation,
delegator_address: delegatorAddress,
validator_address: validatorAddress,
pubkey: {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: fromBase64(decodeBech32Pubkey(pubkey).value)
},
pubkey: decodePubkey(pubkey)!,
value: {
denom: value.denom,
amount: Long.fromValue(value.amount).toString()
Expand Down Expand Up @@ -64,10 +61,7 @@ exports[`cosmos/staking/v1beta1/tx AminoConverter 1`] = `
minSelfDelegation: min_self_delegation,
delegatorAddress: delegator_address,
validatorAddress: validator_address,
pubkey: encodeBech32Pubkey({
type: "tendermint/PubKeySecp256k1",
value: toBase64(pubkey.value)
}, "cosmos"),
pubkey: encodePubkey(pubkey),
value: {
denom: value.denom,
amount: value.amount
Expand Down
Loading

0 comments on commit 078f8d1

Please sign in to comment.