Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
fix tx implement
  • Loading branch information
Zetazzz committed Dec 4, 2023
1 parent 2a80474 commit 9746bc3
Show file tree
Hide file tree
Showing 43 changed files with 663 additions and 1,106 deletions.
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,95 @@ main().then(() => {
})
```

## Instant RPC methods

Using instantOps option to expose instant RPC methods.

For example, for this config:
```
instantOps: [
{
className: "OsmosisClaim",
include: {
patterns: ["osmosis.**.*claim*"],
},
},
{
className: "CosmosAuthAccount",
include: {
patterns: [
"cosmos.auth.**.*account*",
"cosmos.auth.**.*Account*",
"cosmos.gov.v1beta1.**",
],
},
nameMapping: {
// name mapping rule for both Msg and Query methods.
// moduleAccounts will be renamed to authModuleAccounts in generated class.
All: {
authModuleAccounts: "cosmos.auth.v1beta1.moduleAccounts",
},
// name mapping rule for Msg methods.
Tx: {
// deposit method under Msg will be renamed to txDeposit in generated class. While deposit method under Query will remain the same.
txDeposit: "cosmos.gov.v1beta1.deposit",
// Same for vote method.
txVote: "cosmos.gov.v1beta1.vote",
},
},
},
],
```

There'll be an extra file generated in the root folder called service-ops.ts:
```
export interface OsmosisClaim extends _OsmosisClaimV1beta1Queryrpc.OsmosisClaim {}
export class OsmosisClaim {
rpc: TxRpc;
init(rpc: TxRpc) {
this.rpc = rpc;
this.claimRecord = _OsmosisClaimV1beta1Queryrpc.createClientImpl(rpc).claimRecord;
this.claimableForAction = _OsmosisClaimV1beta1Queryrpc.createClientImpl(rpc).claimableForAction;
}
}
export interface CosmosAuthAccount extends _CosmosAuthV1beta1Queryrpc.CosmosAuthAccount, _CosmosGovV1beta1Queryrpc.CosmosAuthAccount, _CosmosGovV1beta1Txrpc.CosmosAuthAccount {}
export class CosmosAuthAccount {
rpc: TxRpc;
init(rpc: TxRpc) {
this.rpc = rpc;
this.accounts = _CosmosAuthV1beta1Queryrpc.createClientImpl(rpc).accounts;
this.account = _CosmosAuthV1beta1Queryrpc.createClientImpl(rpc).account;
// moduleAccounts has been renamed to authModuleAccounts as the nameMapping in settings.
this.authModuleAccounts = _CosmosAuthV1beta1Queryrpc.createClientImpl(rpc).moduleAccounts;
this.proposal = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).proposal;
this.proposals = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).proposals;
// vote under Query remains the same.
this.vote = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).vote;
this.votes = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).votes;
this.params = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).params;
// deposit under Query remains the same.
this.deposit = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).deposit;
this.deposits = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).deposits;
this.tallyResult = _CosmosGovV1beta1Queryrpc.createClientImpl(rpc).tallyResult;
this.submitProposal = _CosmosGovV1beta1Txrpc.createClientImpl(rpc).submitProposal;
//same as txDeposite for vote here.
this.txVote = _CosmosGovV1beta1Txrpc.createClientImpl(rpc).vote;
this.voteWeighted = _CosmosGovV1beta1Txrpc.createClientImpl(rpc).voteWeighted;
// deposit method under Msg will be renamed to txDeposit in generated class. While deposit method under Query will remain the same.
this.txDeposit = _CosmosGovV1beta1Txrpc.createClientImpl(rpc).deposit;
}
}
```

## Manually registering types

This example is with `osmosis` module in `osmojs`, but it is the same pattern for any module.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
import { Attribute, AttributeSDKType } from "../../base/v1beta1/attribute";
import { BroadcastTxReq, BroadcastTxRes, TxRpc } from "../../../types";
import { BroadcastTxReq, DeliverTxResponse, 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>>;
signProviderAttributes(request: BroadcastTxReq<MsgSignProviderAttributes>): Promise<DeliverTxResponse>;
/** DeleteProviderAttributes defines a method that deletes provider attributes */
deleteProviderAttributes(request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<BroadcastTxRes<MsgDeleteProviderAttributesResponse>>;
deleteProviderAttributes(request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<DeliverTxResponse>;
}
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>> => {
signProviderAttributes = async (request: BroadcastTxReq<MsgSignProviderAttributes>): Promise<DeliverTxResponse> => {
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
}));
return this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
};
/* DeleteProviderAttributes defines a method that deletes provider attributes */
deleteProviderAttributes = async (request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<BroadcastTxRes<MsgDeleteProviderAttributesResponse>> => {
deleteProviderAttributes = async (request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<DeliverTxResponse> => {
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
}));
return this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
};
}
export const createClientImpl = (rpc: TxRpc) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
import { Attribute, AttributeSDKType } from "../../base/v1beta2/attribute";
import { BroadcastTxReq, BroadcastTxRes, TxRpc } from "../../../types";
import { BroadcastTxReq, DeliverTxResponse, 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>>;
signProviderAttributes(request: BroadcastTxReq<MsgSignProviderAttributes>): Promise<DeliverTxResponse>;
/** DeleteProviderAttributes defines a method that deletes provider attributes */
deleteProviderAttributes(request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<BroadcastTxRes<MsgDeleteProviderAttributesResponse>>;
deleteProviderAttributes(request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<DeliverTxResponse>;
}
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>> => {
signProviderAttributes = async (request: BroadcastTxReq<MsgSignProviderAttributes>): Promise<DeliverTxResponse> => {
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
}));
return this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
};
/* DeleteProviderAttributes defines a method that deletes provider attributes */
deleteProviderAttributes = async (request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<BroadcastTxRes<MsgDeleteProviderAttributesResponse>> => {
deleteProviderAttributes = async (request: BroadcastTxReq<MsgDeleteProviderAttributes>): Promise<DeliverTxResponse> => {
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
}));
return this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
};
}
export const createClientImpl = (rpc: TxRpc) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
import { BroadcastTxReq, BroadcastTxRes, TxRpc } from "../../../types";
import { BroadcastTxReq, DeliverTxResponse, TxRpc } from "../../../types";
import { BinaryReader } from "../../../binary";
import { MsgCreateCertificate, MsgCreateCertificateSDKType, MsgCreateCertificateResponse, MsgCreateCertificateResponseSDKType, MsgRevokeCertificate, MsgRevokeCertificateSDKType, MsgRevokeCertificateResponse, MsgRevokeCertificateResponseSDKType } from "./cert";
/** Msg defines the provider Msg service */
export interface Msg {
/** CreateCertificate defines a method to create new certificate given proper inputs. */
createCertificate(request: BroadcastTxReq<MsgCreateCertificate>): Promise<BroadcastTxRes<MsgCreateCertificateResponse>>;
createCertificate(request: BroadcastTxReq<MsgCreateCertificate>): Promise<DeliverTxResponse>;
/** RevokeCertificate defines a method to revoke the certificate */
revokeCertificate(request: BroadcastTxReq<MsgRevokeCertificate>): Promise<BroadcastTxRes<MsgRevokeCertificateResponse>>;
revokeCertificate(request: BroadcastTxReq<MsgRevokeCertificate>): Promise<DeliverTxResponse>;
}
export class MsgClientImpl implements Msg {
private readonly rpc: TxRpc;
constructor(rpc: TxRpc) {
this.rpc = rpc;
}
/* CreateCertificate defines a method to create new certificate given proper inputs. */
createCertificate = async (request: BroadcastTxReq<MsgCreateCertificate>): Promise<BroadcastTxRes<MsgCreateCertificateResponse>> => {
createCertificate = async (request: BroadcastTxReq<MsgCreateCertificate>): Promise<DeliverTxResponse> => {
const data = [{
typeUrl: MsgCreateCertificate.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 ? MsgCreateCertificateResponse.decode(data.msgResponses[0].value) : undefined
}));
return this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
};
/* RevokeCertificate defines a method to revoke the certificate */
revokeCertificate = async (request: BroadcastTxReq<MsgRevokeCertificate>): Promise<BroadcastTxRes<MsgRevokeCertificateResponse>> => {
revokeCertificate = async (request: BroadcastTxReq<MsgRevokeCertificate>): Promise<DeliverTxResponse> => {
const data = [{
typeUrl: MsgRevokeCertificate.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 ? MsgRevokeCertificateResponse.decode(data.msgResponses[0].value) : undefined
}));
return this.rpc.signAndBroadcast!(request.signerAddress, data, request.fee, request.memo);
};
}
export const createClientImpl = (rpc: TxRpc) => {
Expand Down
Loading

0 comments on commit 9746bc3

Please sign in to comment.