Skip to content

Commit

Permalink
Simplify metadata function
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Feb 28, 2024
1 parent 5742319 commit f02616b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 50 deletions.
16 changes: 2 additions & 14 deletions crosschain-resolver/contracts/IMetadataResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,15 @@ interface IMetadataResolver {
* @notice Get metadata about the CCIP Resolver ENSIP 16 https://docs.ens.domains/ens-improvement-proposals/ensip-16-offchain-metadata
* @dev This function provides metadata about the CCIP Resolver, including its name, coin type, GraphQL URL, storage type, and encoded information.
* @param name The domain name in format (dnsEncoded)
* @return coinType The cointype of the chain the target contract locates such as Optimism, Base, Arb, etc
* @return graphqlUrl The GraphQL URL used by the resolver
* @return storageType 0 = EVM, 1 = Non blockchain, 2 = Starknet
* @return storageLocation The storage identifier. For EVM chains, this is the address of the resolver contract.
* @return context. An identifier used by l2 graph indexer for Domain schema id (`context-namehash`) allowing multiple resolver contracts to have own namespace.
*
*/
function metadata(bytes calldata name) external view returns (
uint256 coinType,
string memory graphqlUrl,
uint8 storageType,
bytes memory storageLocation,
bytes memory context
string memory graphqlUrl
);

event MetadataChanged(
bytes name,
uint256 coinType,
string graphqlUrl,
uint8 storageType,
bytes storageLocation,
bytes context
string graphqlUrl
);
}
27 changes: 4 additions & 23 deletions crosschain-resolver/contracts/L1Resolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,9 @@ contract L1Resolver is EVMFetchTarget, ITargetResolver, IMetadataResolver, IExte
require(isAuthorised(node));
targets[node] = target;
emit TargetSet(name, target);
(
,,
uint8 storageType,
bytes memory storageLocation,
bytes memory context
) = metadata(name);
emit MetadataChanged(
name,
l2ResolverCoinType,
graphqlUrl,
storageType,
storageLocation,
context
graphqlUrl
);
}

Expand Down Expand Up @@ -260,23 +250,13 @@ contract L1Resolver is EVMFetchTarget, ITargetResolver, IMetadataResolver, IExte
* @notice Get metadata about the L1 Resolver
* @dev This function provides metadata about the L1 Resolver, including its name, coin type, GraphQL URL, storage type, and encoded information.
* @param name The domain name in format (dnsEncoded)
* @return coinType The cointype of the chain the target contract locates such as Optimism, Base, Arb, etc
* @return graphqlUrl The GraphQL URL used by the resolver
* @return storageType Storage Type (0 for EVM)
* @return storageLocation The storage identifier. For EVM chains, this is the address of the resolver contract.
* @return context. An identifier used by l2 graph indexer for Domain schema id (`context-namehash`) allowing multiple resolver contracts to have own namespace.
*/
function metadata(
bytes calldata name
) public view returns (uint256, string memory, uint8, bytes memory, bytes memory) {
(, address target) = getTarget(name);

) public view returns (string memory) {
return (
l2ResolverCoinType,
graphqlUrl,
uint8(0), // storage Type 0 => EVM
abi.encodePacked(address(target)), // storage location => l2 resolver address
abi.encodePacked(address(target)) // context => l2 resolver address
graphqlUrl
);
}

Expand All @@ -287,6 +267,7 @@ contract L1Resolver is EVMFetchTarget, ITargetResolver, IMetadataResolver, IExte
interfaceId == type(IExtendedResolver).interfaceId ||
interfaceId == type(ITargetResolver).interfaceId ||
interfaceId == type(IMetadataResolver).interfaceId ||
interfaceId == type(IResolverSetter).interfaceId ||
super.supportsInterface(interfaceId);
}

Expand Down
15 changes: 2 additions & 13 deletions crosschain-resolver/test/testResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,27 +313,16 @@ describe('Crosschain Resolver', () => {

describe('Metadata', () => {
it('returns metadata', async () => {
await target.setTarget(encodedname, signerAddress)

const [coinType, graphqlUrl, storageType, storageLocation, context] = await target.metadata(encodedname);
expect(parseInt(coinType)).to.equal(l2ResolverCoinType);
expect(graphqlUrl).to.equal(l2graphqlUrl);
expect(storageType).to.equal(storageType);
expect(ethers.getAddress(storageLocation)).to.equal(signerAddress);
expect(ethers.getAddress(context)).to.equal(signerAddress);
expect(await target.metadata(encodedname)).to.equal(l2graphqlUrl);
});

it('emits a MetadataChanged event', async () => {
const tx = await target.setTarget(encodedname, signerAddress)
await tx.wait()
const logs = await target.queryFilter("MetadataChanged")
const [name, coinType, graphqlUrl, storageType, storageLocation, context] = logs[0].args
const [name, graphqlUrl] = logs[0].args
expect(name).to.equal(encodedname);
expect(parseInt(coinType)).to.equal(l2ResolverCoinType);
expect(graphqlUrl).to.equal(l2graphqlUrl);
expect(storageType).to.equal(storageType);
expect(ethers.getAddress(storageLocation)).to.equal(signerAddress);
expect(ethers.getAddress(context)).to.equal(signerAddress);
});
});
});

0 comments on commit f02616b

Please sign in to comment.