-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Add support for ENS contenthash methods #3428
Conversation
ABI is supported in the public resolver (resolver.eth) See line 72: https://etherscan.io/address/0x4976fb03c32e5b8cfe2b6ccb31c09ba78ebaba41#code |
@ricmoo I might misunderstand this but isn't that ABI method similar to In this case we're looking for the ABI of the resolver itself and I wasn't able to see a way of retrieving it. If it is possible it would be the best solution by far though... |
Oh! I see what you mean. We could talk to @Arachnid about adding the ABI to resolver.eth, but I think it would be fine to just hardcode the getters (and maybe the setters) into it; each has an associated EIP. Also, maybe it should be |
@ricmoo Ah yes, that's a good point. |
62591f4
to
b8a0b14
Compare
Have revised per initial review - think this is moving in a better direction...
|
@@ -41,14 +55,15 @@ function ResolverMethodHandler(registry) { | |||
* @param {function} callback | |||
* @returns {Object} | |||
*/ | |||
ResolverMethodHandler.prototype.method = function (ensName, methodName, methodArguments, callback) { | |||
ResolverMethodHandler.prototype.method = function (ensName, methodName, methodArguments, outputFormatter, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outputFormatter addition wouldn't be required.. you can just wrap the promise as on other places :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This ugly handler has to get refactored/removed anyways.. just ping me.. I do have a solution somewhere on a handwritten paper)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow, but yes this could be refactored at some point.
this.parent.registry.getResolver(this.ensName).then(function (resolver) { | ||
self.parent.handleCall(promiEvent, resolver.methods[self.methodName], preparedArguments, callback); | ||
this.parent.registry.getResolver(this.ensName).then(async function (resolver) { | ||
await self.parent.checkInterfaceSupport(resolver, self.methodName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember a discussion I had once with @cgewecke about additional network requests and their impact. Shouldn't this checkInterface
call not also be optional with a strictEns
flag or so? Otherwise, the arguments in the discussion we had are false:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The origin of this design is the discussion beginning in #3392 comment. In this case there are two widely deployed resolvers with different APIs, so there's a strong case for validating the request before-hand.
I think you're alluding here to a debate in #3428 about whether or not to gate revert-with-reason behind an option flag. The ENS module is not subject to the similar considerations AFAIK, personally don't think this will impact people in the same way 🤷
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of just copy it should we probably create an EF package for it with working together with ENS @Arachnid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code comes out of @ensdomains/ui which is relatively large. This seemed like the lightest approach.
@@ -22,6 +22,12 @@ import { TransactionRevertInstructionError } from 'web3-core-helpers'; | |||
import { Eth } from 'web3-eth'; | |||
import { Contract } from 'web3-eth-contract'; | |||
|
|||
export interface ContentHash { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noice! 🎊
7b8d535
to
cea4e0d
Compare
Rebased on bcf248f |
Update: Have made suggested improvements per @nivida's review:
|
Just stumbled across this issue, looking forward to getting this incorporated into web3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Nice comprehensive work @cgewecke.
New tests are passing successfully in CI:
✓ should error when calling "getContent" if resolver does not support it
✓ should error when calling "setContent" if resolver does not support it
✓ getContenthash return object keys are null if no contentHash is set
✓ should get/set an IPFS contenthash (ipfs://)
✓ should get/set an IPFS contenthash (/ipfs/)
✓ should get/set a bzz contenthash
✓ should get/set an onion contenthash
✓ should get/set an onion3 contenthash
✓ setContenthash errors when encoding an invalid contenthash (promise)
✓ setContentHash errors when encoding an invalid contenthash (callback)
Description
Adds
getContenthash
andsetContenthash
methods to the ENS module.Example
As discussed in #3392, there are now two widely used resolver contracts for ENS with different interfaces.
PR adds support for the newer PublicResolver ABI, toggling between the two candidates by making an EIP 165supportsInterface
call for thecontenthash
method before selecting which ABI to use. If the Resolver address associated with the ENS name supports contenthash, the PublicResolver ABI is used, otherwise module defaults to the legacy Resolver ABI.PR updates the ENS Resolver ABI to include contenthash interface as well as deprecated
content
. Makes EIP 165 supportsInterface calls for a subset of resolver methods to verify that the target contract implements them.ENS has a feature that allows nodes to register ABIs on-chain for contract addresses but this does not appear to be implemented for the publicly deployed Resolver contracts themselves.
Running a reverse address check on Etherscan for the mainnet PublicResolver at: 0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41 does not discover an ENS node which might supply an ABI.
Fixes #3392
Type of change
Checklist:
npm run dtslint
with success and extended the tests and types if necessary.npm run test:unit
with success.npm run test:cov
and my test cases do cover all lines and branches of the added code.npm run build-all
and tested the resulting file/'s fromdist
folder in a browser.CHANGELOG.md
file in the root folder.