Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Geth ethereum node communication #979

Merged
merged 20 commits into from
May 15, 2019

Conversation

mederic-p
Copy link
Contributor

@mederic-p mederic-p commented May 2, 2019

Issue/Task Number: #693
Closes #693

Overview

This PR refactors the blockchain and eth_blockchain sub-apps and adds the support for the geth adapter.

Changes

  • Rename blockchain to eth_blockchain
  • Rename blockchain_eth to geth_eth_adapter
  • Move wallet generation to eth_blockchain sub-app
  • Add ethereumex and abi dependencies to handle JSON-RPC calls to geth
  • Add genserver handler for {:get_balances, address, contract_addresses, block} that returns a map of contract_address -> balance for the specified wallet address
  • Add default_adapter config that is set to :geth by default except for tests where it's set to :dumb which is a Dumb adapter that mock responses.

Usage

  • Set the url of a JSON-RPC server in eth_geth_adapter/config/dev.exs
  • Have a valid wallet address with an eth balance and optionally a few ERC20 tokens balances.
  • Run the elixir console: iex -S mix
  • Call
EthBlockchain.Balance.get({"0x54e0588607dcec6c0b36fca1154a57814a913591",  ["0x48b91d5f363892592bf836777dc73b54a10b72ae", "0x0000000000000000000000000000000000000000", "0x436dbc182828ccd421238fb622613c953c5e5028", "0xb76fe945f8672b57cc151448e2f52b0f88891c34"]})

(replace the first param with your wallet address and the list of addresses with the actual contract addresses).

Note: the 0x0000000000000000000000000000000000000000 represents the Eth token.

  • Receive a response:
{:ok,
 %{
   "0x0000000000000000000000000000000000000000" => 13155000000000000000000,
   "0x436dbc182828ccd421238fb622613c953c5e5028" => 10000000000,
   "0x48b91d5f363892592bf836777dc73b54a10b72ae" => 999999999999999999999999900,
   "0xb76fe945f8672b57cc151448e2f52b0f88891c34" => 0 
 }}

For future PRs:

  • Refactor response handler/parser if new JSON call need to use them
  • Improve the setting/config setup for the blockchain adapters

@mederic-p mederic-p changed the title [WIP] geth ethereum node communication Geth ethereum node communication May 8, 2019
@mederic-p mederic-p self-assigned this May 8, 2019
@mederic-p mederic-p requested review from unnawut, T-Dnzt and sirn May 8, 2019 09:52
@mederic-p mederic-p added this to the v2.0 milestone May 8, 2019
@mederic-p mederic-p added this to In Progress in eWallet May 9, 2019
Copy link
Contributor

@sirn sirn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll do another pass later today.

setup do
mock_balance = 123

Code.eval_string("""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this and use only dumb adapter?


supervisor = String.to_atom("#{UUID.generate()}")

{:ok, _} =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might worth switching this to EthBlockchainCase. Probably make it return supervisor pid as well? (Since we need to perform the which_children check?)

@@ -0,0 +1,3 @@
use Mix.Config

config :ethereumex, url: "http://localhost:8545", client_type: :http
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should ask Mana-Ethereum people to support {:system, ...} style config 😉

alias Keychain.Repo

setup tags do
:ok = Sandbox.checkout(Repo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the worker shouldn’t access Keychain directly. Instead, let the EthBlockchain pass it to the adapter (so the adapter can be self-contained).

@mederic-p mederic-p requested a review from sirn May 10, 2019 07:16
@mederic-p mederic-p moved this from In Progress to Review in eWallet May 10, 2019
apps/eth_blockchain/lib/eth_blockchain/balance.ex Outdated Show resolved Hide resolved
apps/eth_geth_adapter/lib/eth_geth_adapter/balance.ex Outdated Show resolved Hide resolved
apps/eth_geth_adapter/lib/eth_geth_adapter/balance.ex Outdated Show resolved Hide resolved
docs/design/components.md Show resolved Hide resolved
apps/eth_geth_adapter/lib/eth_geth_adapter/balance.ex Outdated Show resolved Hide resolved
@mederic-p mederic-p requested a review from unnawut May 14, 2019 10:16
Copy link
Contributor

@unnawut unnawut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but let's wait for a few more 👍

@mederic-p mederic-p force-pushed the 693-geth-ethereum-node-communication branch from 2a33613 to 3337d15 Compare May 15, 2019 10:24
@mederic-p mederic-p merged commit 92a9804 into master May 15, 2019
eWallet automation moved this from Review to Done May 15, 2019
@mederic-p mederic-p deleted the 693-geth-ethereum-node-communication branch May 15, 2019 12:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
eWallet
  
5-Done
Development

Successfully merging this pull request may close these issues.

Ethereum Node Communication (with Geth adapter)
4 participants