Skip to content

Commit

Permalink
fix registry compile error
Browse files Browse the repository at this point in the history
fix amino any type compile error
  • Loading branch information
Zetazzz committed Jun 29, 2023
1 parent 8ee82a3 commit 6ce29d8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`createStargateClient 1`] = `
defaultTypes
});
const client = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer, {
registry,
registry: (registry as any),
aminoTypes
});
return client;
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions packages/ast/src/clients/stargate/stargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -194,7 +195,7 @@ export const createStargateClient = ({ name, options, context }: CreateStargateC
]
),

// return
// return
t.returnStatement(t.identifier('client'))
]
),
Expand Down Expand Up @@ -399,7 +400,7 @@ export const createStargateClientOptions = ({
),

// NEW CODE
// return
// return
t.returnStatement(t.objectExpression([
t.objectProperty(
t.identifier('registry'),
Expand Down
5 changes: 5 additions & 0 deletions packages/ast/src/encoding/proto/from-amino/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
}
Expand Down
22 changes: 22 additions & 0 deletions packages/ast/src/encoding/proto/from-amino/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
4 changes: 4 additions & 0 deletions packages/ast/src/encoding/proto/to-amino/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
}
Expand Down
44 changes: 43 additions & 1 deletion packages/ast/src/encoding/proto/to-amino/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit 6ce29d8

Please sign in to comment.