diff --git a/packages/ast/src/clients/stargate/__snapshots__/stargate.spec.ts.snap b/packages/ast/src/clients/stargate/__snapshots__/stargate.spec.ts.snap index fb5aaccb0c..f551013b40 100644 --- a/packages/ast/src/clients/stargate/__snapshots__/stargate.spec.ts.snap +++ b/packages/ast/src/clients/stargate/__snapshots__/stargate.spec.ts.snap @@ -17,7 +17,7 @@ exports[`createStargateClient 1`] = ` defaultTypes }); const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, { - registry, + registry: (registry as any), aminoTypes }); return client; @@ -49,7 +49,7 @@ exports[`createStargateClient w/o defaults 1`] = ` aminoTypes } = getSigningOsmosisClientOptions(); const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, { - registry, + registry: (registry as any), aminoTypes }); return client; diff --git a/packages/ast/src/clients/stargate/stargate.ts b/packages/ast/src/clients/stargate/stargate.ts index 7513cd0395..80d443f94a 100644 --- a/packages/ast/src/clients/stargate/stargate.ts +++ b/packages/ast/src/clients/stargate/stargate.ts @@ -176,9 +176,10 @@ export const createStargateClient = ({ name, options, context }: CreateStargateC t.objectExpression([ t.objectProperty( t.identifier('registry'), - t.identifier('registry'), - false, - true + t.tsAsExpression( + t.identifier('registry'), + t.tsAnyKeyword() + ) ), t.objectProperty( t.identifier('aminoTypes'), @@ -194,7 +195,7 @@ export const createStargateClient = ({ name, options, context }: CreateStargateC ] ), - // return + // return t.returnStatement(t.identifier('client')) ] ), @@ -399,7 +400,7 @@ export const createStargateClientOptions = ({ ), // NEW CODE - // return + // return t.returnStatement(t.objectExpression([ t.objectProperty( t.identifier('registry'), diff --git a/packages/ast/src/encoding/proto/from-amino/index.ts b/packages/ast/src/encoding/proto/from-amino/index.ts index 80740a0374..0ca7e43f0b 100644 --- a/packages/ast/src/encoding/proto/from-amino/index.ts +++ b/packages/ast/src/encoding/proto/from-amino/index.ts @@ -198,6 +198,11 @@ export const fromAminoJSONMethod = (context: ProtoParseContext, name: string, pr case 'google.protobuf.Timestamp': [].push.apply(body, fromAminoMessages.timestamp(context, name, proto)); break; + case 'google.protobuf.Any': + case 'Any': + [].push.apply(body, fromAminoMessages.anyType()); + break; + default: } } diff --git a/packages/ast/src/encoding/proto/from-amino/utils.ts b/packages/ast/src/encoding/proto/from-amino/utils.ts index c2a4d286ee..e99f14ad36 100644 --- a/packages/ast/src/encoding/proto/from-amino/utils.ts +++ b/packages/ast/src/encoding/proto/from-amino/utils.ts @@ -704,6 +704,28 @@ export const arrayTypes = { export const fromAminoMessages = { + anyType() { + return [ + t.returnStatement( + t.objectExpression([ + t.objectProperty( + t.identifier('typeUrl'), + t.memberExpression( + t.identifier('object'), + t.identifier('type') + ) + ), + t.objectProperty( + t.identifier('value'), + t.memberExpression( + t.identifier('object'), + t.identifier('value') + ) + ) + ]) + ) + ] + }, timestamp(context: ProtoParseContext, name: string, proto: ProtoType) { context.addUtil('fromJsonTimestamp'); diff --git a/packages/ast/src/encoding/proto/to-amino/index.ts b/packages/ast/src/encoding/proto/to-amino/index.ts index 646b627455..ad83fdfc4e 100644 --- a/packages/ast/src/encoding/proto/to-amino/index.ts +++ b/packages/ast/src/encoding/proto/to-amino/index.ts @@ -194,6 +194,10 @@ export const toAminoJSONMethod = (context: ProtoParseContext, name: string, prot case 'google.protobuf.Timestamp': body.push(toAminoMessages.timestamp(context, name, proto)); break; + case 'google.protobuf.Any': + case 'Any': + [].push.apply(body, toAminoMessages.anyType()) + break; default: } } diff --git a/packages/ast/src/encoding/proto/to-amino/utils.ts b/packages/ast/src/encoding/proto/to-amino/utils.ts index 9864d3ac60..f46c18c4e7 100644 --- a/packages/ast/src/encoding/proto/to-amino/utils.ts +++ b/packages/ast/src/encoding/proto/to-amino/utils.ts @@ -1,6 +1,6 @@ import * as t from '@babel/types'; import { ProtoType } from '@osmonauts/types'; -import { BILLION, TypeLong } from '../../../utils'; +import { BILLION, TypeLong, identifier } from '../../../utils'; import { ProtoParseContext } from '../../context'; import { getFieldNames } from '../../types'; import { getInterfaceToAminoName } from '../implements'; @@ -661,6 +661,48 @@ export const arrayTypes = { export const toAminoMessages = { + anyType(){ + return [ + t.variableDeclaration( + 'const', + [ + t.variableDeclarator( + identifier('obj', t.tsTypeAnnotation(t.tsAnyKeyword())), + t.objectExpression([]) + ) + ] + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier('type') + ), + t.memberExpression( + t.identifier('message'), + t.identifier('typeUrl') + ) + ) + ), + t.expressionStatement( + t.assignmentExpression( + '=', + t.memberExpression( + t.identifier('obj'), + t.identifier('value') + ), + t.memberExpression( + t.identifier('message'), + t.identifier('value') + ) + ) + ), + t.returnStatement( + t.identifier('obj') + ) + ] + }, timestamp(context: ProtoParseContext, name: string, proto: ProtoType) { context.addUtil('fromTimestamp');