omni / poa-bridge

POA <-> Ethereum bridge for self transfers of POA native token to POA20 (ERC20 representation). Not supported. Use TokenBridge instead
https://github.com/poanetwork/token-bridge
GNU General Public License v3.0
79 stars 38 forks source link

Use JMESPath to retrieve a gas-price value from the Oracle JSON. #83

Open DrPeterVanNostrand opened 6 years ago

DrPeterVanNostrand commented 6 years ago

Currently, a static JSON schema is expected to be returned from the gas-price Oracle:

{
    "block_number": u64,
    "block_time": f64,
    "instant": f64,
    "standard": f64,
    "slow": f64,
    "fast": f64,
    "health": bool
}

We should allow users the ability to configure their bridge such that they can query a gas-price Oracle which returns a JSON schema differing from the above schema. This should be implemented using JMESPath expressions.

A new config option home/foreign.gas_price_oracle_expr should be added to account for the User's JMESPath expression.

Something similar to the following psuedo-code should be added to GasPriceStream's impl Stream.

let json_str = /* Use hyper to GET the Oracle's data, then string-ify the response body */
let resp_json = jmespath::Variable::from_json(json_str).map_err(|_| ... )?;
let gas_price = config.<home/foreign>.gas_price_expr
        .search(resp_json).unwrap_or(config.<home/foreign>.default_gas_price);