mirror of
https://github.com/status-im/EIPs.git
synced 2025-02-21 19:28:08 +00:00
Add 'data' field to Durin OffchainLookup
error. (#4336)
This commit is contained in:
parent
204b2ae595
commit
1eb2678bf8
@ -48,10 +48,12 @@ In step 3, the client calls the original contract with the exact data provided b
|
||||
A Durin-enabled contract must revert with the following error whenever a function that requires offchain data is called:
|
||||
|
||||
```
|
||||
error OffchainLookup(string url, bytes prefix)
|
||||
error OffchainLookup(string url, bytes data, bytes prefix)
|
||||
```
|
||||
|
||||
`url` specifies the URL to a service (known as the gateway) that implements the Durin protocol and can formulate an answer to the original query. `url` can be the empty string `''`, in which case a client-specific default should be used.
|
||||
`url` specifies the URL to a service (known as the gateway) that implements the Durin protocol and can formulate an answer to the query. `url` can be the empty string `''`, in which case a client-specific default should be used.
|
||||
|
||||
`data` specifies the data to call that service with; for simple cases this can be the same as the original call data.
|
||||
|
||||
`prefix` specifies a prefix that the data returned by the gateway at `url` must have. Clients will check this value is a prefix of the data returned by the gateway, and cause the call to fail if it does not match.
|
||||
|
||||
@ -77,7 +79,7 @@ One example of a valid implementation of `balanceOf` would thus be:
|
||||
|
||||
```
|
||||
function balanceOf(address addr) public view returns(uint balance) {
|
||||
revert OffchainLookup(url, abi.encodeWithSelector(Contract.balanceOfWithProof.selector, addr));
|
||||
revert OffchainLookup(url, msg.data, abi.encodeWithSelector(Contract.balanceOfWithProof.selector, addr));
|
||||
}
|
||||
```
|
||||
|
||||
@ -93,7 +95,7 @@ Accepts calldata for a smart contract call, and returns a message (encoded as a
|
||||
##### Parameters
|
||||
1. Object - The call object
|
||||
- to: DATA, 20 Bytes - The address of the contract being called.
|
||||
- data: DATA - The call data for the contract invocation - this must be the same as the data originally sent to the contract function that reverted with `OffchainData`.
|
||||
- data: DATA - The call data for the contract invocation - this must be the value of the `data` field from the `OffchainLookup` error.
|
||||
- abi: DATA - A JSON format ABI for the function being invoked, as specified in the [Solidity ABI encoding specification](https://docs.soliditylang.org/en/latest/abi-spec.html#json).
|
||||
|
||||
##### Returns
|
||||
@ -122,8 +124,8 @@ def durin_call(address, abi, args, default_gateway):
|
||||
try:
|
||||
return address.call(calldata)
|
||||
except OffchainLookup as e:
|
||||
url, prefix = e.url, e.prefix
|
||||
response = json_rpc_call(url or default_gateway, 'durin_call', {'to': address, 'data': calldata, 'abi': abi})
|
||||
url, data, prefix = e.url, e.data, e.prefix
|
||||
response = json_rpc_call(url or default_gateway, 'durin_call', {'to': address, 'data': data, 'abi': abi})
|
||||
if not response.result.startswith(prefix):
|
||||
throw Error("Invalid response prefix")
|
||||
return address.call(response.result)
|
||||
|
Loading…
x
Reference in New Issue
Block a user