Skip to content

Conversation

@Zetazzz
Copy link
Contributor

@Zetazzz Zetazzz commented Nov 28, 2023

Using instantOps option to expose instant RPC methods.

    rpcClients?: {
        instantOps?: {
            className: string,
            include: {
              patterns?: string[];
            },
            nameMapping?:{
              [key: string]: string;
            }
        }[];
    };

For example, for this config:

    instantOps: [
      {
        className: "OsmosisClaim",
        include: {
          patterns: ["osmosis.**.*claim*"],
        },
      },
      {
        className: "CosmosAuthAccount",
        include: {
          patterns: ["cosmos.auth.**.*account*", "cosmos.auth.**.*Account*"],
        },
        nameMapping: {
          authModuleAccounts: "cosmos.auth.v1beta1.moduleAccounts",

        },
      },
    ],

There'll be an extra file generated in the root folder called service-ops.ts:

import { Rpc } from "./helpers";
import * as _OsmosisClaimV1beta1Queryrpc from "./osmosis/claim/v1beta1/query.rpc.Query";
import * as _CosmosAuthV1beta1Queryrpc from "./cosmos/auth/v1beta1/query.rpc.Query";
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 {}
export class CosmosAuthAccount {
  rpc: TxRpc;
  init(rpc: TxRpc) {
    this.rpc = rpc;
    this.accounts = _CosmosAuthV1beta1Queryrpc.createClientImpl(rpc).accounts;
    this.account = _CosmosAuthV1beta1Queryrpc.createClientImpl(rpc).account;
    this.authModuleAccounts = _CosmosAuthV1beta1Queryrpc.createClientImpl(rpc).moduleAccounts;
  }
}

And using serviceImplement option to assign implement type of rpc methods, Query or Tx, by setting patterns under service types.
For example, for this config:

    serviceImplement: {
      Msg: {
        type: "Tx",
      },
    },

All methods under Msg will be implemented like this:

  deposit = async (request: BroadcastTxReq<MsgDeposit>): Promise<BroadcastTxRes<MsgDepositResponse>> => {
    const data = [{
      typeUrl: MsgDeposit.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 ? MsgDepositResponse.decode(data.msgResponses[0].value) : undefined
    }));
  };

@Zetazzz Zetazzz merged commit 94ee573 into main Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants