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

feat: add full support of Query API (pre-rc.20) #201

Merged

Conversation

0x009922
Copy link
Contributor

Queries

Context

Existing Query API implementation in Iroha JS is not complete:

  • It doesn't account for "Live Queries". Iroha by default returns query results as batches, and clients must make subsequent requests with the given query_id and cursor retrieve more results.
  • It doesn't support pagination and sorting parameters.

Solution

The new API looks like this:

// iterable query
const domains = client
  .query(pre, datamodel.QueryBox('FindDomains'), {
    // optional params
    start: 10,
    limit: 20,
    sortByMetadataKey: 'sorting-key'
  })
  .then((response) => response.as('Iter').all())

// singular query
const transaction = client
  .query(pre, datamodel.QueryBox(
    'FindTransactionByHash', 
    datamodel.FindTransactionByHash({ hash: ... })
  ))
  .then((response) => response.as('Value').enum.as('TransactionQueryOutput'))

The response is a enumeration of possible query responses:

  • Iter for iterable query response. This is a live query, and it contains a handle to fetch subsequent batches of data. As in the example above, there is a helper method .all(): Promise<Value[]> that simply fetches all batches and collects them into a single array.
  • Value for singular query response. This is returned by queries that return only a single result.
  • Failure with decoded ValidationFail reason.

computeTransactionHash

While investigating #200, I found that the transaction hash emitted by pipeline events is different from the hash used for querying transactions: the first is HashOf<TransactionPayload>, and the second is HashOf<SignedTransaction>.

To reduce this ambiguity for SDK users, I soft-deprecated computeTransactionHash and added new helpers: computeTransactionPayloadHash and computeSignedTransactionHash.

@0x009922 0x009922 added enhancement iroha2 package: client Related to Client package(-s) labels Jan 21, 2025
@0x009922 0x009922 self-assigned this Jan 21, 2025
@0x009922
Copy link
Contributor Author

Guess we don't have proper CI for now...

I swear I have run the checks locally!

@0x009922 0x009922 merged commit a780a96 into hyperledger-iroha:main Jan 21, 2025
1 check passed
@matisalimbene matisalimbene mentioned this pull request Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement iroha2 package: client Related to Client package(-s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant