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

[refactor] #2144: redesign client's http workflow, expose internal api #2147

Merged

Conversation

0x009922
Copy link
Contributor

@0x009922 0x009922 commented Apr 25, 2022

Description of the Change

Currently client is built on top of blocking synchronous HTTP client, which is not very flexible for different use cases.

To make it more flexible, I've split some of the APIs into 2 parts:

  1. Preparing transaction/query/other HTTP request in terms of pure data
  2. Handle related HTTP response for this request

I've moved the part of actual doing the request out of this. By the way, current main function are still using the default http implementation, but these parts are moved out from it.

It is done with a new trait - RequestBuilder. I've added several functions to the Client:

  • prepare_query_request(query, pagination), that returns a tuple with a provided RequestBuilder and a special response handler.
  • prepare_transaction_request(tx), same as for queries, but also returns a hash of a transaction.
  • prepare_status_request(), same as above, but simpler.

There are also 3 new structs - QueryResponseHandler, TransactionResponseHandler and StatusResponseHandler. All of them encapsulates the logic of handling an HTTP-response in a correct way.

I haven't touched WebSocket-based logic and some other complex utilities that rely on default HTTP client yet. Anyway it should be refactored as well.

Also I've refactored the http internal module itself.

Issue

Resolves #2144

Benefits

  • Possibility to use iroha_client with custom HTTP transport, even async. Only for queries, transactions and status for now.
  • Usage of trait RequestBuilder allows to build requests in an efficient way. It would be less efficient if build it via callbacks or by returning the exact request structure.
  • Client is still responsible to handle http response
  • You don't need to import anything to handle response, and currently "responders" are a zero-cost abstraction
  • Existing client API hasn't been changed, but has been extended.

Possible Drawbacks

  • Headers are still HashMap<String, String>, which can be optimized in scope of RequestBuilder trate.
  • Response handlers expect Response structure from the http crate. It may be unefficient if custom http implementation returns some other response and user has to transform it first. Maybe it is better to replace Response with some trait.

Usage Examples or Tests

Existing client methods now uses the same API, but with default HTTP client. See how they now work.

0x009922 and others added 18 commits April 21, 2022 13:21
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Co-authored-by: Aleksandr Petrosyan <a-p-petrosyan@yandex.ru>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
@0x009922 0x009922 added iroha2-dev The re-implementation of a BFT hyperledger in RUST Refactor Improvement to overall code quality labels Apr 25, 2022
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
Signed-off-by: 0x009922 <a.marcius26@gmail.com>
@appetrosyan appetrosyan merged commit 4925e69 into hyperledger-iroha:iroha2-dev Apr 28, 2022
@0x009922 0x009922 deleted the task/2144/refactor-client-http branch April 28, 2022 05:45
mversic pushed a commit to mversic/iroha that referenced this pull request May 2, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 4, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…xpose internal api (hyperledger-iroha#2147)

Signed-off-by: 0x009922 <a.marcius26@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…xpose internal api (hyperledger-iroha#2147)

Signed-off-by: 0x009922 <a.marcius26@gmail.com>
appetrosyan pushed a commit to appetrosyan/iroha that referenced this pull request May 12, 2022
…xpose internal api (hyperledger-iroha#2147)

Signed-off-by: 0x009922 <a.marcius26@gmail.com>
mversic pushed a commit to mversic/iroha that referenced this pull request May 13, 2022
mversic pushed a commit to mversic/iroha that referenced this pull request May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST Refactor Improvement to overall code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants