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

GlobalDecoderRegistry, better handling with fields with 'accepted_interface' option #526

Merged
merged 33 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f040578
finished registry
Zetazzz Oct 31, 2023
b00f1bc
apply global registry
Zetazzz Oct 31, 2023
fcc6939
fix fromPartial
Zetazzz Oct 31, 2023
7d7d467
add test and passed
Zetazzz Nov 1, 2023
447fe9c
remove generating impl base code
Zetazzz Nov 1, 2023
1168026
refine TelescopeGeneratedType
Zetazzz Nov 2, 2023
3025477
add helper funcs to global registry
Zetazzz Nov 9, 2023
a1f57a3
finish Global registry
Zetazzz Nov 10, 2023
d0490eb
Merge branch 'main' into impl-interfaces
Zetazzz Nov 10, 2023
2edd71a
Merge branch 'main' into impl-interfaces
Zetazzz Nov 10, 2023
56a5b14
edit type name
Zetazzz Nov 10, 2023
18e930f
Merge branch 'main' into impl-interfaces
Zetazzz Nov 12, 2023
57824da
add registry helper
Zetazzz Nov 13, 2023
9453fce
Merge branch 'main' into impl-interfaces
Zetazzz Nov 13, 2023
cacd3d7
remove ast/types/src
Zetazzz Nov 13, 2023
a74f32c
is method and test
Zetazzz Nov 15, 2023
50ba045
finished coding is method
Zetazzz Nov 15, 2023
2f5e30b
Merge branch 'main' into impl-interfaces
Zetazzz Nov 16, 2023
31f05ec
add isSdk and isAmino
Zetazzz Nov 16, 2023
5957cbf
add isSDK and isAmino
Zetazzz Nov 16, 2023
e011744
edited encode
Zetazzz Nov 16, 2023
9d05373
edited decode
Zetazzz Nov 16, 2023
2e40cbe
edited to and from json
Zetazzz Nov 17, 2023
d613339
fix is logic
Zetazzz Nov 17, 2023
db57e42
finished all helpers
Zetazzz Nov 17, 2023
9bf9f93
add test
Zetazzz Nov 19, 2023
4ded83b
add tests
Zetazzz Nov 19, 2023
61e42fb
fix test for $typeUrl
Zetazzz Nov 19, 2023
e845821
move TelescopeGeneratedCodec to types helper
Zetazzz Nov 19, 2023
f3bc51a
make is method optional
Zetazzz Nov 19, 2023
36456c0
update readme
Zetazzz Nov 19, 2023
c8ab3a7
fixed types and typo
Zetazzz Nov 19, 2023
d26e799
remove test sample code
Zetazzz Nov 19, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage
packages/**/build
packages/**/main
packages/**/module
launch.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ telescope({
| option | description | defaults |
| ----------------------------------------- | -------------------------------------------------------------- | ---------- |
| `interfaces.enabled` | enables converters convert between Any type and specific implemented interfaces. | `true` |
| `interfaces.useGlobalDecoderRegistry` | enables GlobalDecoderRegistry and related functions. Highly recommended to enable when dealing with fields with 'accepted_interface' option. Please see 'packages/telescope/__tests__/impl-interfaces.test.ts' for usage. | `false` |
| `interfaces.useUseInterfacesParams` | decides if add `useInterfaces` argument to `decode` and `toAmino` functions. | `false` |
| `interfaces.useByDefault` | decides if interface decoders are used by default (default for `useInterfaces` argument to `decode` and `toAmino` functions). | `true` |
| `interfaces.useByDefaultRpc` | decides if interface decoders are used by default by the RPC clients. | `true` |
Expand Down
8 changes: 8 additions & 0 deletions __fixtures__/misc/output-impl-interfaces-gen/akash/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as _0 from "./deployment/v1beta1/authz";
export namespace akash {
export namespace deployment {
export const v1beta1 = {
..._0
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { Coin, CoinAmino, CoinSDKType } from "../../../cosmos/base/v1beta1/coin";
import { BinaryReader, BinaryWriter } from "../../../binary";
import { isSet, DeepPartial } from "../../../helpers";
import { GlobalDecoderRegistry } from "../../../registry";
export const protobufPackage = "akash.deployment.v1beta1";
/**
* DepositDeploymentAuthorization allows the grantee to deposit up to spend_limit coins from
* the granter's account for a deployment.
*/
export interface DepositDeploymentAuthorization {
/**
* SpendLimit is the amount the grantee is authorized to spend from the granter's account for
* the purpose of deployment.
*/
spendLimit: Coin;
}
export interface DepositDeploymentAuthorizationProtoMsg {
typeUrl: "/akash.deployment.v1beta1.DepositDeploymentAuthorization";
value: Uint8Array;
}
/**
* DepositDeploymentAuthorization allows the grantee to deposit up to spend_limit coins from
* the granter's account for a deployment.
*/
export interface DepositDeploymentAuthorizationAmino {
/**
* SpendLimit is the amount the grantee is authorized to spend from the granter's account for
* the purpose of deployment.
*/
spend_limit?: CoinAmino;
}
export interface DepositDeploymentAuthorizationAminoMsg {
type: "/akash.deployment.v1beta1.DepositDeploymentAuthorization";
value: DepositDeploymentAuthorizationAmino;
}
/**
* DepositDeploymentAuthorization allows the grantee to deposit up to spend_limit coins from
* the granter's account for a deployment.
*/
export interface DepositDeploymentAuthorizationSDKType {
spend_limit: CoinSDKType;
}
function createBaseDepositDeploymentAuthorization(): DepositDeploymentAuthorization {
return {
spendLimit: Coin.fromPartial({})
};
}
export const DepositDeploymentAuthorization = {
typeUrl: "/akash.deployment.v1beta1.DepositDeploymentAuthorization",
is(o: any): o is DepositDeploymentAuthorization {
return o && (o.$typeUrl === DepositDeploymentAuthorization.typeUrl || Coin.is(o.spendLimit));
},
isSDK(o: any): o is DepositDeploymentAuthorizationSDKType {
return o && (o.$typeUrl === DepositDeploymentAuthorization.typeUrl || Coin.isSDK(o.spend_limit));
},
isAmino(o: any): o is DepositDeploymentAuthorizationAmino {
return o && (o.$typeUrl === DepositDeploymentAuthorization.typeUrl || Coin.isAmino(o.spend_limit));
},
encode(message: DepositDeploymentAuthorization, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
if (message.spendLimit !== undefined) {
Coin.encode(message.spendLimit, writer.uint32(10).fork()).ldelim();
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): DepositDeploymentAuthorization {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseDepositDeploymentAuthorization();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.spendLimit = Coin.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromJSON(object: any): DepositDeploymentAuthorization {
const obj = createBaseDepositDeploymentAuthorization();
if (isSet(object.spendLimit)) obj.spendLimit = Coin.fromJSON(object.spendLimit);
return obj;
},
toJSON(message: DepositDeploymentAuthorization): unknown {
const obj: any = {};
message.spendLimit !== undefined && (obj.spendLimit = message.spendLimit ? Coin.toJSON(message.spendLimit) : undefined);
return obj;
},
fromPartial(object: DeepPartial<DepositDeploymentAuthorization>): DepositDeploymentAuthorization {
const message = createBaseDepositDeploymentAuthorization();
if (object.spendLimit !== undefined && object.spendLimit !== null) {
message.spendLimit = Coin.fromPartial(object.spendLimit);
}
return message;
},
fromSDK(object: DepositDeploymentAuthorizationSDKType): DepositDeploymentAuthorization {
return {
spendLimit: object.spend_limit ? Coin.fromSDK(object.spend_limit) : undefined
};
},
fromSDKJSON(object: any): DepositDeploymentAuthorizationSDKType {
return {
spend_limit: isSet(object.spend_limit) ? Coin.fromSDKJSON(object.spend_limit) : undefined
};
},
toSDK(message: DepositDeploymentAuthorization): DepositDeploymentAuthorizationSDKType {
const obj: any = {};
message.spendLimit !== undefined && (obj.spend_limit = message.spendLimit ? Coin.toSDK(message.spendLimit) : undefined);
return obj;
},
fromAmino(object: DepositDeploymentAuthorizationAmino): DepositDeploymentAuthorization {
return {
spendLimit: object?.spend_limit ? Coin.fromAmino(object.spend_limit) : undefined
};
},
toAmino(message: DepositDeploymentAuthorization): DepositDeploymentAuthorizationAmino {
const obj: any = {};
obj.spend_limit = message.spendLimit ? Coin.toAmino(message.spendLimit) : undefined;
return obj;
},
fromAminoMsg(object: DepositDeploymentAuthorizationAminoMsg): DepositDeploymentAuthorization {
return DepositDeploymentAuthorization.fromAmino(object.value);
},
fromProtoMsg(message: DepositDeploymentAuthorizationProtoMsg): DepositDeploymentAuthorization {
return DepositDeploymentAuthorization.decode(message.value);
},
toProto(message: DepositDeploymentAuthorization): Uint8Array {
return DepositDeploymentAuthorization.encode(message).finish();
},
toProtoMsg(message: DepositDeploymentAuthorization): DepositDeploymentAuthorizationProtoMsg {
return {
typeUrl: "/akash.deployment.v1beta1.DepositDeploymentAuthorization",
value: DepositDeploymentAuthorization.encode(message).finish()
};
}
};
GlobalDecoderRegistry.register(DepositDeploymentAuthorization.typeUrl, DepositDeploymentAuthorization);
Loading