Skip to content

Commit

Permalink
fixed return type of Cosmos_cryptoPubKey_ToAmino
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetazzz committed Nov 15, 2023
1 parent c70a4c2 commit da7a0c1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { Decimal } from "@cosmjs/math";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
import { Pubkey } from "@cosmjs/amino";
export const protobufPackage = "cosmos.staking.v1beta1";
/** BondStatus is the status of a validator. */
export enum BondStatus {
Expand Down Expand Up @@ -3312,6 +3313,6 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: BinaryReader | Uint8
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any) => {
export const Cosmos_cryptoPubKey_ToAmino = (content: Any): Pubkey | null => {
return decodePubkey(content);
};
3 changes: 2 additions & 1 deletion __fixtures__/v-next/outputv2/cosmos/staking/v1beta1/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
import { Decimal } from "@cosmjs/math";
import { Pubkey } from "@cosmjs/amino";
export const protobufPackage = "cosmos.staking.v1beta1";
/** MsgCreateValidator defines a SDK message for creating a new validator. */
export interface MsgCreateValidator {
Expand Down Expand Up @@ -1359,6 +1360,6 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: BinaryReader | Uint8
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any) => {
export const Cosmos_cryptoPubKey_ToAmino = (content: Any): Pubkey | null => {
return decodePubkey(content);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { Decimal } from "@cosmjs/math";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
import { Pubkey } from "@cosmjs/amino";
export const protobufPackage = "cosmos.staking.v1beta1";
/** BondStatus is the status of a validator. */
export enum BondStatus {
Expand Down Expand Up @@ -3052,6 +3053,6 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: BinaryReader | Uint8
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any, useInterfaces: boolean = true) => {
export const Cosmos_cryptoPubKey_ToAmino = (content: Any, useInterfaces: boolean = true): Pubkey | null => {
return decodePubkey(content);
};
3 changes: 2 additions & 1 deletion __fixtures__/v-next/outputv3/cosmos/staking/v1beta1/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
import { Decimal } from "@cosmjs/math";
import { Pubkey } from "@cosmjs/amino";
export const protobufPackage = "cosmos.staking.v1beta1";
/** MsgCreateValidator defines a SDK message for creating a new validator. */
export interface MsgCreateValidator {
Expand Down Expand Up @@ -1229,6 +1230,6 @@ export const Cosmos_cryptoPubKey_InterfaceDecoder = (input: BinaryReader | Uint8
export const Cosmos_cryptoPubKey_FromAmino = (content: AnyAmino) => {
return encodePubkey(content);
};
export const Cosmos_cryptoPubKey_ToAmino = (content: Any, useInterfaces: boolean = true) => {
export const Cosmos_cryptoPubKey_ToAmino = (content: Any, useInterfaces: boolean = true): Pubkey | null => {
return decodePubkey(content);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MsgCreateValidator MsgCreateValidator 1`] = `
"export const Cosmos_cryptoPubKey_ToAmino = (content: Any) => {
"export const Cosmos_cryptoPubKey_ToAmino = (content: Any): Pubkey | null => {
return decodePubkey(content);
};"
`;
Expand Down
13 changes: 8 additions & 5 deletions packages/ast/src/encoding/proto/implements/to-amino.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as t from '@babel/types';
import { ProtoRef, TraverseTypeUrlRef, TypeUrlRef } from '@cosmology/types';
import { slugify } from '@cosmology/utils';
import { identifier } from '../../../utils';
import { arrowFunctionExpression, identifier } from '../../../utils';
import { ProtoParseContext } from "../../context";

const firstUpper = (s: string) => s = s.charAt(0).toUpperCase() + s.slice(1);
Expand All @@ -18,6 +18,7 @@ export const createInterfaceToAmino = (
if (interfaceName === 'cosmos.crypto.PubKey') {
// return a helper!
context.addUtil('decodePubkey');
context.addUtil('Pubkey');
const functionName = getInterfaceToAminoName(interfaceName);

return makeFunctionWrapper(context, functionName, t.returnStatement(
Expand All @@ -27,7 +28,7 @@ export const createInterfaceToAmino = (
t.identifier('content')
]
),
));
), t.tsTypeAnnotation(t.tsUnionType([t.tsTypeReference(t.identifier("Pubkey")), t.tsNullKeyword()])));
}


Expand All @@ -43,15 +44,16 @@ export const createInterfaceToAmino = (
const makeFunctionWrapper = (
context: ProtoParseContext,
functionName: string,
stmt: t.Statement
stmt: t.Statement,
returnType?: t.TSTypeAnnotation
) => {
return t.exportNamedDeclaration(
t.variableDeclaration(
'const',
[
t.variableDeclarator(
t.identifier(functionName),
t.arrowFunctionExpression(
arrowFunctionExpression(
[
identifier(
'content',
Expand Down Expand Up @@ -80,7 +82,8 @@ const makeFunctionWrapper = (
],
t.blockStatement([
stmt
])
]),
returnType
)

)
Expand Down

0 comments on commit da7a0c1

Please sign in to comment.