althea-net/guac_rs

Integrate web3 connection

mpapierski opened this issue · 2 comments

Guac needs an ability to query the network. To do that we can use web3. This is separate issue from #20 where actual transactions will be broadcasted through function calls. This issue is more like an API to make #20 to implement.

Integrating web3

The proper way to do this is to probably integrate it into CryptoService.

Example:

CRYPTO.web3().foo().bar()

Initially, web3 could be initialized with $NETWORK_HOST env var, that could default to localhost:8545.

  • Web3 instance in CRYPTO global variable

Additional features:

  • A generic function to poll for events by name. For now its fine to wait for event by name, and there is no immediate need to filter out events by arguments.

Network properties

CryptoService should be aware of important network properties such as:

  • Getting network ID
  • Getting nonce for a given key
  • Getting current gas price
  • Optionally, getting gas limit which could be hardcoded, or made configurable.
  • Getting current balance

Config

As a last step some sort of way to configure global CRYPTO object should be introduced that would be mandatory to call before doing anything. Rita should call it when its starting up and reading config file.

CRYPTO.init(&config)

Doing it as a single step might make it easier to initialize, and improve error handling.

Properties of the Config struct

  • ChannelManager contract address
  • ETH network host

Additional helpers

  • A helper to send transaction that would transparently handle nonce, data.

@mpapierski I don't see anything in here about using infura/other public web3 apis. Not sure this needs to be taken into consideration at this level, but you may not want to take for granted that you have all the methods available that are on a local node. You should test this with infura. Even if we don't use infura we will likely use a similar api.

https://infura.io/docs

@jtremback Interesting project. I'm a little afraid rust-web3 might have problems with authenticating to this APIs (i.e. they need API key as part of URL but rust-web3 is configured with host:port). On the other hand if we'd plan to use infura 100% that would probably make our lifes easier (i.e. little to no configuration etc.)