Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ensdomains/resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
decanus committed Nov 15, 2018
2 parents cdb72d2 + 823a00b commit 59c784a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 48 deletions.
12 changes: 6 additions & 6 deletions contracts/CustodialPublicResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ contract CustodialPublicResolver is PublicResolver {
}

/**
* Sets the multiaddr associated with an ENS node on behalf of someone.
* Sets the contenthash associated with an ENS node on behalf of someone.
* @param node The node to update.
* @param addr The multiaddr to set.
* @param hash The contenthash to set.
* @param signature Signature signed by the node owner.
*/
function setMultiaddrFor(bytes32 node, bytes addr, bytes signature) public {
validateSignature(node, abi.encodePacked(node, addr), signature);
records[node].multiaddr = addr;
emit MultiaddrChanged(node, addr);
function setContenthashFor(bytes32 node, bytes hash, bytes signature) public {
validateSignature(node, abi.encodePacked(node, hash), signature);
records[node].contenthash = hash;
emit ContenthashChanged(node, hash);
}

/**
Expand Down
39 changes: 19 additions & 20 deletions contracts/PublicResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ contract PublicResolver {
bytes4 constant ABI_INTERFACE_ID = 0x2203ab56;
bytes4 constant PUBKEY_INTERFACE_ID = 0xc8690233;
bytes4 constant TEXT_INTERFACE_ID = 0x59d1d43c;
bytes4 constant MULTIADDR_INTERFACE_ID = 0x4cb7724c;
bytes4 constant CONTENTHASH_INTERFACE_ID = 0xbc1c58d1;

event AddrChanged(bytes32 indexed node, address a);
event NameChanged(bytes32 indexed node, string name);
event ABIChanged(bytes32 indexed node, uint256 indexed contentType);
event PubkeyChanged(bytes32 indexed node, bytes32 x, bytes32 y);
event TextChanged(bytes32 indexed node, string indexedKey, string key);
event MultiaddrChanged(bytes32 indexed node, bytes addr);
event ContenthashChanged(bytes32 indexed node, bytes hash);

struct PublicKey {
bytes32 x;
Expand All @@ -34,7 +34,7 @@ contract PublicResolver {
PublicKey pubkey;
mapping(string=>string) text;
mapping(uint256=>bytes) abis;
bytes multiaddr;
bytes contenthash;
}

ENS ens;
Expand Down Expand Up @@ -65,6 +65,17 @@ contract PublicResolver {
emit AddrChanged(node, addr);
}

/**
* Sets the contenthash associated with an ENS node.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param hash The contenthash to set
*/
function setContenthash(bytes32 node, bytes hash) public onlyOwner(node) {
records[node].contenthash = hash;
emit ContenthashChanged(node, hash);
}

/**
* Sets the name associated with an ENS node, for reverse records.
* May only be called by the owner of that node in the ENS registry.
Expand Down Expand Up @@ -115,17 +126,6 @@ contract PublicResolver {
emit TextChanged(node, key, key);
}

/**
* Sets the multiaddr associated with an ENS node.
* May only be called by the owner of that node in the ENS registry.
* @param node The node to update.
* @param addr The multiaddr to set
*/
function setMultiaddr(bytes32 node, bytes addr) public onlyOwner(node) {
records[node].multiaddr = addr;
emit MultiaddrChanged(node, addr);
}

/**
* Returns the text data associated with an ENS node and key.
* @param node The ENS node to query.
Expand Down Expand Up @@ -184,14 +184,13 @@ contract PublicResolver {
return records[node].addr;
}


/**
* Returns the multiaddr associated with an ENS node.
* Returns the contenthash associated with an ENS node.
* @param node The ENS node to query.
* @return The associated multiaddr.
* @return The associated contenthash.
*/
function multiaddr(bytes32 node) public view returns (bytes) {
return records[node].multiaddr;
function contenthash(bytes32 node) public view returns (bytes) {
return records[node].contenthash;
}

/**
Expand All @@ -205,7 +204,7 @@ contract PublicResolver {
interfaceID == ABI_INTERFACE_ID ||
interfaceID == PUBKEY_INTERFACE_ID ||
interfaceID == TEXT_INTERFACE_ID ||
interfaceID == MULTIADDR_INTERFACE_ID ||
interfaceID == CONTENTHASH_INTERFACE_ID ||
interfaceID == INTERFACE_META_ID;
}
}
44 changes: 22 additions & 22 deletions test/TestPublicResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ contract('PublicResolver', function (accounts) {

it('supports known interfaces', async () => {
assert.equal(await resolver.supportsInterface("0x3b3b57de"), true);
assert.equal(await resolver.supportsInterface("0x4cb7724c"), true);
assert.equal(await resolver.supportsInterface("0x691f3431"), true);
assert.equal(await resolver.supportsInterface("0x2203ab56"), true);
assert.equal(await resolver.supportsInterface("0xc8690233"), true);
assert.equal(await resolver.supportsInterface("0x59d1d43c"), true);
assert.equal(await resolver.supportsInterface("0xbc1c58d1"), true);
});

it('does not support a random interface', async () => {
Expand Down Expand Up @@ -333,54 +333,54 @@ contract('PublicResolver', function (accounts) {
});
});

describe('multiaddr', async () => {
describe('contenthash', async () => {

it('permits setting multiaddr by owner', async () => {
await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});
assert.equal(await resolver.multiaddr(node), '0x0000000000000000000000000000000000000000000000000000000000000001');
it('permits setting contenthash by owner', async () => {
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});
assert.equal(await resolver.contenthash(node), '0x0000000000000000000000000000000000000000000000000000000000000001');
});

it('can overwrite previously set multiaddr', async () => {
await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});
assert.equal(await resolver.multiaddr(node), '0x0000000000000000000000000000000000000000000000000000000000000001');
it('can overwrite previously set contenthash', async () => {
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});
assert.equal(await resolver.contenthash(node), '0x0000000000000000000000000000000000000000000000000000000000000001');

await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000002', {from: accounts[0]});
assert.equal(await resolver.multiaddr(node), '0x0000000000000000000000000000000000000000000000000000000000000002');
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000002', {from: accounts[0]});
assert.equal(await resolver.contenthash(node), '0x0000000000000000000000000000000000000000000000000000000000000002');
});

it('can overwrite to same multiaddr', async () => {
await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});
assert.equal(await resolver.multiaddr(node), '0x0000000000000000000000000000000000000000000000000000000000000001');
it('can overwrite to same contenthash', async () => {
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});
assert.equal(await resolver.contenthash(node), '0x0000000000000000000000000000000000000000000000000000000000000001');

await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000002', {from: accounts[0]});
assert.equal(await resolver.multiaddr(node), '0x0000000000000000000000000000000000000000000000000000000000000002');
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000002', {from: accounts[0]});
assert.equal(await resolver.contenthash(node), '0x0000000000000000000000000000000000000000000000000000000000000002');
});

it('forbids setting multiaddr by non-owners', async () => {
it('forbids setting contenthash by non-owners', async () => {
try {
await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[1]});
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[1]});
} catch (error) {
return utils.ensureException(error);
}

assert.fail('setting did not fail');
});

it('forbids writing same multiaddr by non-owners', async () => {
await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});
it('forbids writing same contenthash by non-owners', async () => {
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[0]});

try {
await resolver.setMultiaddr(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[1]});
await resolver.setContenthash(node, '0x0000000000000000000000000000000000000000000000000000000000000001', {from: accounts[1]});
} catch (error) {
return utils.ensureException(error);
}

assert.fail('setting did not fail');
});

it('returns empty when fetching nonexistent multiaddr', async () => {
it('returns empty when fetching nonexistent contenthash', async () => {
assert.equal(
await resolver.multiaddr(node),
await resolver.contenthash(node),
'0x'
);
});
Expand Down

0 comments on commit 59c784a

Please sign in to comment.