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

Expose Instant rpc methods #529

Merged
merged 16 commits into from
Dec 3, 2023
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ See [LCD Clients](#lcd-clients) for more info.
| `rpcClients.scoped` | will generate factory of scoped RPC Clients | `undefined` |
| `rpcClients.scopedIsExclusive` | will allow both scoped bundles and all RPC Clients | `true` |
| `rpcClients.enabledServices` | which services to enable | [`Msg`,`Query`,`Service`] |
| `rpcClients.instantOps` | will generate instant rpc operations in the file `service-ops.ts` under root folder, which contains customized classes having selected rpc methods | `undefined` |
| `rpcClients.serviceImplement` | assign implement type of rpc methods, `Query` or `Tx`, by setting patterns under service types. | `undefined` |

See [RPC Clients](#rpc-clients) for more info.

Expand Down
99 changes: 96 additions & 3 deletions __fixtures__/misc/output-impl-interfaces-gen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export interface TelescopeGeneratedCodec<
isAmino?(o: unknown): o is Amino;
encode: (message: T, writer?: IBinaryWriter | any) => IBinaryWriter | any;
decode: (input: IBinaryReader | Uint8Array | any, length?: number) => T;
fromPartial: (object: any) => T;
fromJSON?: (object: unknown) => T;
toJSON?: (message: T) => unknown;
fromPartial: (object: any) => T | any;
fromJSON: (object: any) => T | any;
toJSON: (message: T | any) => any;
fromSDK?: (sdk: SDK) => T;
fromSDKJSON?: (object: any) => SDK;
toSDK?: (message: T) => SDK;
Expand All @@ -55,3 +55,96 @@ export type TelescopeGeneratedType<
> = TelescopeGeneratedCodec<T, SDK, Amino>;

export type GeneratedType = TelescopeGeneratedCodec;

/**
* Coin defines a token with a denomination and an amount.
*
* NOTE: The amount field is an Int which implements the custom method
* signatures required by gogoproto.
*/
export interface Coin {
denom: string;
amount: string;
}

export type EncodeObject = Message<any>;

export interface Message<T> {
typeUrl: string;
value: T;
}

export interface StdFee {
amount: Coin[];
gas: string;
/** The granter address that is used for paying with feegrants */
granter?: string;
/** The fee payer address. The payer must have signed the transaction. */
payer?: string;
}

export interface MsgData {
msgType: string;
data: Uint8Array;
}

/**
* The response after successfully broadcasting a transaction.
* Success or failure refer to the execution result.
*/
export interface DeliverTxResponse {
height: number;
/** The position of the transaction within the block. This is a 0-based index. */
txIndex: number;
/** Error code. The transaction suceeded if and only if code is 0. */
code: number;
transactionHash: string;
events: Event[];
/**
* A string-based log document.
*
* This currently seems to merge attributes of multiple events into one event per type
* (https://github.com/tendermint/tendermint/issues/9595). You might want to use the `events`
* field instead.
*/
rawLog?: string;
/** @deprecated Use `msgResponses` instead. */
data?: MsgData[];
/**
* The message responses of the [TxMsgData](https://github.com/cosmos/cosmos-sdk/blob/v0.46.3/proto/cosmos/base/abci/v1beta1/abci.proto#L128-L140)
* as `Any`s.
* This field is an empty list for chains running Cosmos SDK < 0.46.
*/
msgResponses: Array<{
typeUrl: string;
value: Uint8Array;
}>;
gasUsed: bigint;
gasWanted: bigint;
}

export interface TxRpc {
request(
service: string,
method: string,
data: Uint8Array
): Promise<Uint8Array>;
signAndBroadcast?(
signerAddress: string,
messages: EncodeObject[],
fee: StdFee | "auto" | number,
memo: string
): Promise<DeliverTxResponse>;
}

export interface BroadcastTxReq<T> {
signerAddress: string;
message: T;
fee: number | StdFee | "auto";
memo: string;
}

export interface BroadcastTxRes<T> {
txResponse: DeliverTxResponse;
response?: T;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* eslint-disable */
import { Attribute, AttributeSDKType } from "../../base/v1beta1/attribute";
import { AminoMsg } from "@cosmjs/amino";
import { MsgSignProviderAttributes, MsgSignProviderAttributesSDKType, MsgDeleteProviderAttributes, MsgDeleteProviderAttributesSDKType } from "./audit";
export interface MsgSignProviderAttributesAminoType extends AminoMsg {
type: "akash/audit/testonly-sign-provider-attributes";
value: {
owner: string;
auditor: string;
attributes: {
key: string;
value: string;
}[];
};
}
export interface MsgDeleteProviderAttributesAminoType extends AminoMsg {
type: "akash/audit/testonly-delete-provider-attributes";
value: {
owner: string;
auditor: string;
keys: string[];
};
}
export const AminoConverter = {
"/akash.audit.v1beta1.MsgSignProviderAttributes": {
aminoType: "akash/audit/testonly-sign-provider-attributes",
toAmino: ({
owner,
auditor,
attributes
}: MsgSignProviderAttributes): MsgSignProviderAttributesAminoType["value"] => {
return {
owner,
auditor,
attributes: attributes.map(el0 => ({
key: el0.key,
value: el0.value
}))
};
},
fromAmino: ({
owner,
auditor,
attributes
}: MsgSignProviderAttributesAminoType["value"]): MsgSignProviderAttributes => {
return {
owner,
auditor,
attributes: attributes.map(el0 => ({
key: el0.key,
value: el0.value
}))
};
}
},
"/akash.audit.v1beta1.MsgDeleteProviderAttributes": {
aminoType: "akash/audit/testonly-delete-provider-attributes",
toAmino: ({
owner,
auditor,
keys
}: MsgDeleteProviderAttributes): MsgDeleteProviderAttributesAminoType["value"] => {
return {
owner,
auditor,
keys
};
},
fromAmino: ({
owner,
auditor,
keys
}: MsgDeleteProviderAttributesAminoType["value"]): MsgDeleteProviderAttributes => {
return {
owner,
auditor,
keys
};
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Attribute, AttributeSDKType } from "../../base/v1beta1/attribute";
import { TelescopeGeneratedType } from "../../../types";
import { Registry } from "@cosmjs/proto-signing";
import { MsgSignProviderAttributes, MsgSignProviderAttributesSDKType, MsgDeleteProviderAttributes, MsgDeleteProviderAttributesSDKType } from "./audit";
export const registry: ReadonlyArray<[string, TelescopeGeneratedType<any, any, any>]> = [["/akash.audit.v1beta1.MsgSignProviderAttributes", MsgSignProviderAttributes], ["/akash.audit.v1beta1.MsgDeleteProviderAttributes", MsgDeleteProviderAttributes]];
export const load = (protoRegistry: Registry) => {
registry.forEach(([typeUrl, mod]) => {
protoRegistry.register(typeUrl, mod);
});
};
export const MessageComposer = {
encoded: {
signProviderAttributes(value: MsgSignProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgSignProviderAttributes",
value: MsgSignProviderAttributes.encode(value).finish()
};
},
deleteProviderAttributes(value: MsgDeleteProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgDeleteProviderAttributes",
value: MsgDeleteProviderAttributes.encode(value).finish()
};
}
},
withTypeUrl: {
signProviderAttributes(value: MsgSignProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgSignProviderAttributes",
value
};
},
deleteProviderAttributes(value: MsgDeleteProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgDeleteProviderAttributes",
value
};
}
},
toJSON: {
signProviderAttributes(value: MsgSignProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgSignProviderAttributes",
value: MsgSignProviderAttributes.toJSON(value)
};
},
deleteProviderAttributes(value: MsgDeleteProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgDeleteProviderAttributes",
value: MsgDeleteProviderAttributes.toJSON(value)
};
}
},
fromJSON: {
signProviderAttributes(value: any) {
return {
typeUrl: "/akash.audit.v1beta1.MsgSignProviderAttributes",
value: MsgSignProviderAttributes.fromJSON(value)
};
},
deleteProviderAttributes(value: any) {
return {
typeUrl: "/akash.audit.v1beta1.MsgDeleteProviderAttributes",
value: MsgDeleteProviderAttributes.fromJSON(value)
};
}
},
fromPartial: {
signProviderAttributes(value: MsgSignProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgSignProviderAttributes",
value: MsgSignProviderAttributes.fromPartial(value)
};
},
deleteProviderAttributes(value: MsgDeleteProviderAttributes) {
return {
typeUrl: "/akash.audit.v1beta1.MsgDeleteProviderAttributes",
value: MsgDeleteProviderAttributes.fromPartial(value)
};
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Attribute, AttributeSDKType } from "../../base/v1beta1/attribute";
import { BroadcastTxReq, BroadcastTxRes, TxRpc } from "../../../types";
import { BinaryReader } from "../../../binary";
import { MsgSignProviderAttributes, MsgSignProviderAttributesSDKType, MsgSignProviderAttributesResponse, MsgSignProviderAttributesResponseSDKType, MsgDeleteProviderAttributes, MsgDeleteProviderAttributesSDKType, MsgDeleteProviderAttributesResponse, MsgDeleteProviderAttributesResponseSDKType } from "./audit";
/** Msg defines the provider Msg service */
export interface Msg {
/** SignProviderAttributes defines a method that signs provider attributes */
signProviderAttributes(request: BroadcastTxReq<MsgSignProviderAttributes>): Promise<BroadcastTxRes<MsgSignProviderAttributesResponse>>;
/** DeleteProviderAttributes defines a method that deletes provider attributes */
deleteProviderAttributes(request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<BroadcastTxRes<MsgDeleteProviderAttributesResponse>>;
}
export class MsgClientImpl implements Msg {
private readonly rpc: TxRpc;
constructor(rpc: TxRpc) {
this.rpc = rpc;
}
/* SignProviderAttributes defines a method that signs provider attributes */
signProviderAttributes = async (request: BroadcastTxReq<MsgSignProviderAttributes>): Promise<BroadcastTxRes<MsgSignProviderAttributesResponse>> => {
const data = [{
typeUrl: MsgSignProviderAttributes.typeUrl,
value: request.message
}];
const promise = this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
return promise.then(data => ({
txResponse: data,
response: data && data.msgResponses?.length ? MsgSignProviderAttributesResponse.decode(data.msgResponses[0].value) : undefined
}));
};
/* DeleteProviderAttributes defines a method that deletes provider attributes */
deleteProviderAttributes = async (request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<BroadcastTxRes<MsgDeleteProviderAttributesResponse>> => {
const data = [{
typeUrl: MsgDeleteProviderAttributes.typeUrl,
value: request.message
}];
const promise = this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
return promise.then(data => ({
txResponse: data,
response: data && data.msgResponses?.length ? MsgDeleteProviderAttributesResponse.decode(data.msgResponses[0].value) : undefined
}));
};
}
export const createClientImpl = (rpc: TxRpc) => {
return new MsgClientImpl(rpc);
};
Loading