Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amino bigint array #410

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/ast/src/encoding/proto/from-amino/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export const fromAminoJSONMethodFields = (context: ProtoParseContext, name: stri
case 'sfixed32':
return fromAminoJSON.array(args, arrayTypes.sfixed32());
case 'int64':
return fromAminoJSON.array(args, arrayTypes.int64());
return fromAminoJSON.array(args, arrayTypes.int64(args));
case 'sint64':
return fromAminoJSON.array(args, arrayTypes.sint64());
return fromAminoJSON.array(args, arrayTypes.sint64(args));
case 'uint64':
return fromAminoJSON.array(args, arrayTypes.uint64());
return fromAminoJSON.array(args, arrayTypes.uint64(args));
case 'fixed64':
return fromAminoJSON.array(args, arrayTypes.fixed64());
return fromAminoJSON.array(args, arrayTypes.fixed64(args));
case 'sfixed64':
return fromAminoJSON.array(args, arrayTypes.sfixed64());
return fromAminoJSON.array(args, arrayTypes.sfixed64(args));
default:
switch (field.parsedType.type) {
case 'Enum':
Expand Down
24 changes: 12 additions & 12 deletions packages/ast/src/encoding/proto/from-amino/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,23 +610,23 @@ export const arrayTypes = {
return arrayTypes.scalar();
},

long() {
return arrayTypes.scalar();
long(args: FromAminoJSONMethod) {
return TypeLong.getFromStringArray(args.context);
},
uint64() {
return arrayTypes.scalar();
uint64(args: FromAminoJSONMethod) {
return arrayTypes.long(args);
},
int64() {
return arrayTypes.scalar();
int64(args: FromAminoJSONMethod) {
return arrayTypes.long(args);
},
sint64() {
return arrayTypes.scalar();
sint64(args: FromAminoJSONMethod) {
return arrayTypes.long(args);
},
fixed64() {
return arrayTypes.scalar();
fixed64(args: FromAminoJSONMethod) {
return arrayTypes.long(args);
},
sfixed64() {
return arrayTypes.scalar();
sfixed64(args: FromAminoJSONMethod) {
return arrayTypes.long(args);
},
number() {
return arrayTypes.scalar();
Expand Down
2 changes: 1 addition & 1 deletion packages/ast/src/encoding/proto/to-amino/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export const arrayTypes = {
return arrayTypes.number();
},
long(args: ToAminoJSONMethod) {
return arrayTypes.scalar();
return TypeLong.getToStringArray(args.context);
},
int64(args: ToAminoJSONMethod) {
return arrayTypes.long(args);
Expand Down
23 changes: 22 additions & 1 deletion packages/ast/src/utils/type-long-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ export const TypeLong = {
long: t.identifier('Long')
},

fromStringArray: {
bigint: t.callExpression(t.identifier('BigInt'), [t.identifier('e')]),
long: t.identifier('e')
},

toStringArray: {
bigint: t.callExpression(
t.memberExpression(t.identifier('e'), t.identifier('toString')),
[]
),
long: t.identifier('e')
},

uzeroExpressions: {
bigint: t.callExpression(t.identifier('BigInt'), [t.numericLiteral(0)]),
long: t.memberExpression(t.identifier('Long'), t.identifier('UZERO'))
Expand Down Expand Up @@ -68,6 +81,14 @@ export const TypeLong = {
return TypeLong.getNode(ctx, TypeLong.types);
},

getFromStringArray: (ctx: GenericParseContext): t.Expression => {
return TypeLong.getNode(ctx, TypeLong.fromStringArray);
},

getToStringArray: (ctx: GenericParseContext): t.Expression => {
return TypeLong.getNode(ctx, TypeLong.toStringArray);
},

getPropIdentifier: (ctx: GenericParseContext): t.Identifier => {
return TypeLong.getNode(ctx, TypeLong.propIdentifiers);
},
Expand Down Expand Up @@ -103,7 +124,7 @@ export const TypeLong = {
[]
)
);
break;
break;

case 'long':
args.push(arg);
Expand Down
12 changes: 6 additions & 6 deletions packages/ast/types/src/encoding/proto/from-amino/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export declare const arrayTypes: {
string(): t.Identifier;
bool(): t.Identifier;
bytes(args: FromAminoJSONMethod): t.Identifier;
long(): t.Identifier;
uint64(): t.Identifier;
int64(): t.Identifier;
sint64(): t.Identifier;
fixed64(): t.Identifier;
sfixed64(): t.Identifier;
long(args: FromAminoJSONMethod): t.Expression;
uint64(args: FromAminoJSONMethod): t.Expression;
int64(args: FromAminoJSONMethod): t.Expression;
sint64(args: FromAminoJSONMethod): t.Expression;
fixed64(args: FromAminoJSONMethod): t.Expression;
sfixed64(args: FromAminoJSONMethod): t.Expression;
number(): t.Identifier;
uint32(): t.Identifier;
int32(): t.Identifier;
Expand Down
12 changes: 6 additions & 6 deletions packages/ast/types/src/encoding/proto/to-amino/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export declare const arrayTypes: {
sint32(): t.Identifier;
fixed32(): t.Identifier;
sfixed32(): t.Identifier;
long(args: ToAminoJSONMethod): t.Identifier;
int64(args: ToAminoJSONMethod): t.Identifier;
uint64(args: ToAminoJSONMethod): t.Identifier;
sint64(args: ToAminoJSONMethod): t.Identifier;
fixed64(args: ToAminoJSONMethod): t.Identifier;
sfixed64(args: ToAminoJSONMethod): t.Identifier;
long(args: ToAminoJSONMethod): t.Expression;
int64(args: ToAminoJSONMethod): t.Expression;
uint64(args: ToAminoJSONMethod): t.Expression;
sint64(args: ToAminoJSONMethod): t.Expression;
fixed64(args: ToAminoJSONMethod): t.Expression;
sfixed64(args: ToAminoJSONMethod): t.Expression;
bytes(args: ToAminoJSONMethod): t.Identifier;
enum(args: ToAminoJSONMethod): t.CallExpression;
anyType(args: ToAminoJSONMethod): t.ConditionalExpression;
Expand Down
38 changes: 27 additions & 11 deletions packages/test/src/test-lcd-balance.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import { LCDClient } from "@osmonauts/lcd";
import { cosmos } from "./codegen";
import { LCDClient } from '@osmonauts/lcd';
import { cosmos } from './codegen';
import { createRPCQueryClient } from './codegen/cosmos/rpc.query';
import { PageRequest } from './codegen/cosmos/base/query/v1beta1/pagination';

const REST_ENDPOINT = 'https://rest.cosmos.directory/osmosis'
const REST_ENDPOINT = 'https://rest.cosmos.directory/osmosis';

export const main = async () => {
const requestClient = new LCDClient({ restEndpoint: REST_ENDPOINT });
const client = new cosmos.bank.v1beta1.LCDQueryClient({ requestClient });
const pools = await client.allBalances({
address: 'osmo19mywfjzj324w5ukf7ss6jak0dg9hnljfp0rfx4'
})
console.log(pools);
const requestClient = new LCDClient({ restEndpoint: REST_ENDPOINT });
const bankClient = new cosmos.bank.v1beta1.LCDQueryClient({ requestClient });
const pools = await bankClient.allBalances({
address: 'osmo19mywfjzj324w5ukf7ss6jak0dg9hnljfp0rfx4'
})
console.log(pools);

const balance = await bankClient.balance({
address: 'osmo19mywfjzj324w5ukf7ss6jak0dg9hnljfp0rfx4',
denom: 'uatom',
})
console.log(balance);

const authClient = new cosmos.auth.v1beta1.LCDQueryClient({ requestClient });

const accounts = await authClient.accounts({
pagination: PageRequest.fromPartial({})
});

console.log(accounts)
};

main().then(() => {
console.log('all done')
})
console.log('all done');
});
Loading