soramitsu / iroha-helpers

Some functions which will help you to interact with Hyperledger Iroha
Apache License 2.0
11 stars 10 forks source link

payloadQuery[capitalizedKeyName] is not a function #24

Open MillerAdulu opened 5 years ago

MillerAdulu commented 5 years ago

I am trying to get the example code running and I keep encountering the error above each time I call getAccountDetail. I tried to trace the problem in the code base and my findings were as follows:

var addQuery = function addQuery(query, queryName, params) {
var payloadQuery = new Queries[(0, _util.capitalize)(queryName)]();

console.log(params)
//{ accountId: 'new@test',   key: 'jason', writerId: 'admin@test', paginationMeta: { pageSize: 100, firstRecordId: { writer: 'admin@test', key: 'jason' } } }
//These parameters are OK and everything is coming in fine.

for (var _i = 0, _Object$entries = Object.entries(params); _i < _Object$entries.length; _i++) {
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
      key = _Object$entries$_i[0],
      value = _Object$entries$_i[1];

  var capitalizedKeyName = "set".concat((0, _util.capitalize)(key));
  console.log(capitalizedKeyName)
//This is now where the issue lies
//All the keys of the object are being mapped properly except for setPaginationMeta hence the if statement fails and jumps to the else condition which returns the error above

  if (capitalizedKeyName === 'setPaginationMeta') {

I am using this for a school project and would highly appreciate some assistance. There's no way to bypass this in the code so I am stuck and cannot proceed until it's resolved.

Thanks in advance.

Package version: 0.7.1

Pobepto commented 5 years ago

Hi! Are you trying to run code in example file?

MillerAdulu commented 5 years ago

Yes I am. Here is the code I am using specifically because the methods accept different parameters which the example doesn't show.

import { credentials } from 'grpc';
import {
  QueryService_v1Client,
  CommandService_v1Client,
} from 'iroha-helpers/lib/proto/endpoint_grpc_pb';
import { commands, queries } from 'iroha-helpers';

const IROHA_ADDRESS = 'localhost:50051';
const adminPriv = 'f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70';

const commandService = new CommandService_v1Client(
  IROHA_ADDRESS,
  credentials.createInsecure(),
);

const queryService = new QueryService_v1Client(
  IROHA_ADDRESS,
  credentials.createInsecure(),
);
return Promise.all([
        commands.setAccountDetail({
          privateKeys: [adminPriv],
          creatorAccountId: 'admin@test',
          quorum: 1,
          commandService,
          timeoutLimit: 50000
        }, {
          accountId: 'new@test',
          key: 'jason',
          value: 'statham'
        }),
        queries.getAccountDetail({
          privateKey: adminPriv,
          creatorAccountId: 'admin@test',
          queryService,
          timeoutLimit: 5000
        }, {
          accountId: 'new@test',
          key: 'jason',
          writerId: 'admin@test',
          pageSize: 100,
// Tried the admin#test variation from the documentation and it still doesn't work
          paginationWriter: "admin@test",
          paginationKey: "jason"
        }      )
      ])
        .then(a => {
          console.log(a);
          return a;
        })
        .catch(e => {
          console.error(e);
          return e})

  }
djose1512 commented 4 years ago

Hello, also and tried to execute the getAccountDetail command without success, I think it is a problem in the definition of the proto service, I try to pass all the parameters as well as the only existing parameter in the example and it just does not work. and debugged the queryHelper and index files but could not find the root problem.

vudknguyen commented 4 years ago

I'm having the same issue

iroha-helpers@0.7.1

TypeError: payloadQuery[capitalizedKeyName] is not a function at Object.addQuery (/workspace/iroha/js-test/node_modules/iroha-helpers/lib/queryHelper.js:74:39) at Object.getAccountDetail (/workspace/iroha/js-test/node_modules/iroha-helpers/lib/queries/index.js:312:58) at Object.<anonymous> (/workspace/iroha/js-test/index.js:18:4) at Module._compile (internal/modules/cjs/loader.js:959:30) at loader (/workspace/iroha/js-test/node_modules/babel-register/lib/node.js:144:5) at Object.require.extensions.<computed> [as .js] (/workspace/iroha/js-test/node_modules/babel-register/lib/node.js:154:7) at Module.load (internal/modules/cjs/loader.js:815:32) at Function.Module._load (internal/modules/cjs/loader.js:727:14) at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10) at Object.<anonymous> (/workspace/iroha/js-test/node_modules/babel-cli/lib/_babel-node.js:154:22)

2hoursleep commented 4 years ago

Hi All. I had the same issue but managed to get it working like this for my use case, one of which is being able to create, sign and store a transaction or query offline and submit once a user has got connectivity.

Just to clarify to all. queries (and transactions) already "wraps" around queryHelper, and provides it the proper parameters, so like mentioned above I needed a way to build up queries and transactions.

Please note that I am not submitting my query via the normal grpc method as I needed client signed messages to be sent to an "oracle" service that validates / inspects requests and submits them to a trusted iroha peer(s).

Apologies if the below is not written in the best way but its just to showcase the example.

First queryHelper's addQuery function takes 3 arguments. With the op first example

1st A blank query, this uses an emptyQuery (blocks empty query is the other option if I'm not mistaken). 2nd. the Iroha Query Name. My example uses 'getAccount' but the original poster's query with params do work. 3rd query params. Needs the minimum required fields to function ofcourse. for getAccount only accountId is required.

I am making use of Vue


import { queryHelper } from 'iroha-helpers'

var blankQuery = queryHelper.emptyQuery()
var baseQuery = queryHelper.addQuery(blankQuery, 'getAccount', { accountId: form.userAccount }) // userAccount e.g. admin@iroha
var metaQuery = queryHelper.addMeta(baseQuery, { creatorAccountId: this.form.userAccount }) // View inspect queries file to see more examples
var signedQuery = queryHelper.sign(metaQuery, this.form.private_key) // Private key from a form to test
var payload = signedQuery.toObject() // turns signed query into json object

you can submit signedQuery to the grpc service. the last var payload transforms the signed query into a JSON object that you can log to inspect the contents.

I hope this makes sense, please let me know if I need to clarify a bit more.