Skip to content
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

Merged
merged 22 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d8b5c60
Upgrade ensdomains/resolver (dev dep) to 0.2.4
cgewecke Mar 20, 2020
4397656
Add PublicResolver ABI
cgewecke Mar 20, 2020
99b3bef
Select resolver ABI via EIP165 (Supports Interface)
cgewecke Mar 20, 2020
b01ad07
Update ens.js injection tests with additional resolver call
cgewecke Mar 20, 2020
d0d8472
Add error handling for mismatched resolver ABI & method calls
cgewecke Mar 21, 2020
01cc124
Draft: get/set content hash
cgewecke Mar 21, 2020
88b83b9
Fix jshint warnings (where possible)
cgewecke Mar 22, 2020
dd13185
Add "unsupported abi" injection tests for contenthash & setContenthash
cgewecke Mar 22, 2020
d2d40c8
Update contentHash typescript & tests
cgewecke Mar 22, 2020
60c91ac
Update docs for getContentHash / setContentHash
cgewecke Mar 22, 2020
600f1cf
Use single, extended Resolver ABI
cgewecke Apr 7, 2020
b40af90
Call supportsInterface for each method
cgewecke Apr 7, 2020
ba5f85f
Undo contenthash camel-casing (per EIP convention)
cgewecke Apr 7, 2020
5acf997
Add ENS license to decoding utils
cgewecke Apr 7, 2020
beed2cd
Add E2E test for pubkey methods
cgewecke Apr 7, 2020
fbd432f
Fix Registry.js diff
cgewecke Apr 7, 2020
cea4e0d
Update method signatures in docs
cgewecke Apr 7, 2020
d4badc2
Fix web3-eth-ens package-lock.json rebase break
cgewecke Apr 29, 2020
f037c31
Remove extraneous mocha timeout in test/eth.ens.js
cgewecke Apr 29, 2020
a6e19cb
Move interfaceIds to config
cgewecke Apr 29, 2020
efd5cbf
Minimize changes to Resolver ABI
cgewecke Apr 29, 2020
477f504
Merge branch '1.x' into issue/3392-ens-contenthash
ryanio May 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
128 changes: 128 additions & 0 deletions docs/web3-eth-ens.rst
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,134 @@ For further information on the handling of contract events please see :ref:`here

------------------------------------------------------------------------------

getContenthash
=====================

.. code-block:: javascript

web3.eth.ens.getContenthash(ENSName [, callback]);

Returns the content hash object associated with an ENS node.

----------
Parameters
----------

1. ``ENSName`` - ``String``: The ENS name.
2. ``callback`` - ``Function``: (optional) Optional callback

-------
Returns
-------

``Promise<Object>`` - The content hash object associated with an ENS node.

-------
Example
-------

.. code-block:: javascript

web3.eth.ens.getContenthash('ethereum.eth').then(function (result) {
console.log(result);
});
> {
"protocolType": "ipfs",
"decoded": "QmaEBknbGT4bTQiQoe2VNgBJbRfygQGktnaW5TbuKixjYL"
}

------------------------------------------------------------------------------

setContenthash
=====================

.. code-block:: javascript

web3.eth.ens.setContenthash(ENSName, hash [, txConfig ] [, callback]);

Sets the content hash associated with an ENS node.

----------
Parameters
----------

1. ``ENSName`` - ``String``: The ENS name.
2. ``hash`` - ``String``: The content hash to set.
3. ``txConfig`` - ``Object``: (optional) The transaction options as described ::ref::`here <eth-sendtransaction>`
4. ``callback`` - ``Function``: (optional) Optional callback

Emits a ``ContenthashChanged`` event.

Supports the following protocols as valid ``hash`` inputs:

1. ``ipfs://`` - example: ipfs://QmaEBknbGT4bTQiQoe2VNgBJbRfygQGktnaW5TbuKixjYL
2. ``/ipfs/`` - example: /ipfs/QmaEBknbGT4bTQiQoe2VNgBJbRfygQGktnaW5TbuKixjYL
3. ``bzz://`` - example: bzz://d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162
4. ``onion://`` - example: onion://3g2upl4pq6kufc4m
5. ``onion3://`` - exmaple: onion3://p53lf57qovyuvwsc6xnrppyply3vtqm7l6pcobkmyqsiofyeznfu5uqd

-------
Returns
-------

``PromiEvent<TransactionReceipt | TransactionRevertInstructionError>``

-------
Example
-------

.. code-block:: javascript

web3.eth.ens.setContenthash(
'ethereum.eth',
'ipfs://QmaEBknbGT4bTQiQoe2VNgBJbRfygQGktnaW5TbuKixjYL',
{
from: '0x9CC9a2c777605Af16872E0997b3Aeb91d96D5D8c'
}
).then(function (result) {
console.log(result.events);
});
> ContenthashChanged(...)

// Or using the event emitter

web3.eth.ens.setContenthash(
'ethereum.eth',
'ipfs://QmaEBknbGT4bTQiQoe2VNgBJbRfygQGktnaW5TbuKixjYL',
{
from: '0x9CC9a2c777605Af16872E0997b3Aeb91d96D5D8c'
}
)
.on('transactionHash', function(hash){
...
})
.on('confirmation', function(confirmationNumber, receipt){
...
})
.on('receipt', function(receipt){
...
})
.on('error', console.error);

// Or listen to the ContenthashChanged event on the resolver

web3.eth.ens.resolver('ethereum.eth').then(function (resolver) {
resolver.events.ContenthashChanged({fromBlock: 0}, function(error, event) {
console.log(event);
})
.on('data', function(event){
console.log(event);
})
.on('changed', function(event){
// remove event from local database
})
.on('error', console.error);
});


For further information on the handling of contract events please see :ref:`here <contract-events>`.


getMultihash
=====================

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@ensdomains/ens": "^0.4.0",
"@ensdomains/resolver": "^0.1.13",
"@ensdomains/resolver": "^0.2.4",
"@types/bignumber.js": "^4.0.2",
"@types/bn.js": "^4.11.5",
"@types/node": "^12.6.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/web3-core-helpers/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,8 @@ module.exports = {
},
TransactionOutOfGasError: function(receipt) {
return this.TransactionError('Transaction ran out of gas. Please provide more gas:\n' + JSON.stringify(receipt, null, 2), receipt);
},
ResolverMethodMissingError: function(address, name) {
return new Error('The resolver at ' + address + 'does not implement requested method: "' + name + '".');
}
};
1 change: 1 addition & 0 deletions packages/web3-core-helpers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class errors {
static ContractCodeNotStoredError(receipt: object): TransactionError
static TransactionRevertedWithoutReasonError(receipt: object): TransactionError
static TransactionOutOfGasError(receipt: object): TransactionError
static ResolverMethodMissingError(address: string, name: string): Error
}

export class WebsocketProviderBase {
Expand Down
3 changes: 3 additions & 0 deletions packages/web3-core-helpers/types/tests/errors-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ errors.TransactionRevertedWithoutReasonError({});

// $ExpectType TransactionError
errors.TransactionOutOfGasError({});

// $ExpectType Error
errors.ResolverMethodMissingError('0x0000000000000000000000000000000000000001', 'content');