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

decoding RPC for Pools Request doesn't decode Pool automatically #5

Closed
Tracked by #278
pyramation opened this issue Jul 24, 2022 · 2 comments
Closed
Tracked by #278

Comments

@pyramation
Copy link
Collaborator

not sure if this is intended, but decoding RPC for Pools Request doesn't decode Pool automatically.

import { osmosis } from "osmojs";

import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate";
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";

export const main = async () => {

    const tmClient = await Tendermint34Client.connect(RPC_ENDPOINT);
    const QueryClientImpl = osmosis.gamm.v1beta1.QueryClientImpl;
    const client = new QueryClient(tmClient);
    const rpc = createProtobufRpcClient(client);
    const queryService = new QueryClientImpl(rpc);
    const res = await queryService.pools({})

   // THIS WORKS but has to be manually applied
    res.pools.map(({ typeUrl, value }) => {
        console.log(osmosis.gamm.v1beta1.Pool.decode(value));
    })
};

main().then(() => {
    console.log('all done')
})
@pyramation
Copy link
Collaborator Author

pyramation commented Jul 24, 2022

editing the code this also works by editing the QueryPoolsResponse.decode method

First import Pool object deps

var _balancer = require("../pool-models/balancer/balancerPool");

update the decode method

  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseQueryPoolsResponse();

    while (reader.pos < end) {
      var tag = reader.uint32();

      switch (tag >>> 3) {
        case 1:
          // message.pools.push(_any.Any.decode(reader, reader.uint32()));
          message.pools.push(_balancer.Pool.decode(reader, reader.uint32()))
          break;

        case 2:
          message.pagination = _pagination.PageResponse.decode(reader, reader.uint32());
          break;

        default:
          reader.skipType(tag & 7);
          break;
      }
    }

    return message;
  },

@Steven-Chang
Copy link

Looks like decoding works automatically now. This is what the response looks like.

{ '$typeUrl': '/osmosis.gamm.v1beta1.Pool', address: 'osmo1zg4rlhp843nn3jk0uz2kvk4zzvp7wm6qpvlnuv7dnp4jlz9pmpws90duk8', id: Long { low: 82, high: 0, unsigned: true }, poolParams: { swapFee: '2000000000000000', exitFee: '0', smoothWeightChangeParams: undefined }, futurePoolGovernor: '24h', totalShares: { denom: 'gamm/pool/82', amount: '100000000000000000' }, poolAssets: [ [Object], [Object] ], totalWeight: '1073741824000000' },

Any chance you can update https://github.com/cosmology-tech/cosmology/tree/main/packages/core @pyramation ?

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

No branches or pull requests

2 participants