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

get rid of dynamic code generation #10

Merged
merged 16 commits into from
Oct 15, 2017

Conversation

ayrat555
Copy link
Member

@ayrat555 ayrat555 commented Oct 6, 2017

There are a couple of problems with current implementation:

  1. Signature for api methods is ugly and it's not apparent what parameters every method accepts.
  # map in list
  HttpClient.eth_send_transaction([%{...}]) 

  # list of binaries
  HttpClient.eth_get_storage_at([binary1, binary2, binary3])

  1. It's hard to mock this methods for tests because all methods are dynamically generated by macro.

The solution is to define explicit behaviour with all api methods and then implement this behavour in all client modules.

defmodule Ethereumex.Client.Behaviour do
  @type return_type :: {:ok, map()} | {:error, map()} | {:error, atom()}

  # API methods

  @callback web3_client_version() :: return_type
  @callback web3_sha3(binary()) :: return_type
  @callback net_version() :: return_type
  @callback net_peer_count() :: return_type
  ...

  # actual request

  @callback request(map()) :: return_type

dashbitco/mox#13

@ayrat555 ayrat555 merged commit 1e05b16 into master Oct 15, 2017
@ayrat555 ayrat555 deleted the get_rid_of_dynamic_method_generation branch April 15, 2018 19:33
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.

1 participant