当前位置: 首页 > 文档资料 > ENS 中文文档 >

Writing a Resolver

优质
小牛编辑
112浏览
2023-12-01

Resolvers are specified in EIP137. A resolver must implement the following method: EIP137中描述了解析器的详细信息。一个解析器必须实现以下方法:

function supportsInterface(bytes4 interfaceID) constant returns (bool);
1

supportsInterface is defined in EIP165, and allows callers to determine if a resolver supports a particular record type. Record types are specified as a set of one or more methods that a resolver must implement together. Currently defined record types include: supportsInterfaceEIP165中定义,它可以被调用者用来确定一个解析器是否支持某个特定的记录类型。记录类型是指解析器必须一起实现的一个或多个方法的集合。当前定义的记录类型包括:

Record typeFunction(s)Interface IDDefined in
Ethereum addressaddr0x3b3b57deEIP137
ENS Namename0x691f3431EIP181
ABI specificationABI0x2203ab56EIP205
Public keypubkey0xc8690233EIP619
Text recordstext0x59d1d43cEIP634
Content hashcontenthash0xbc1c58d1
记录类型函数接口ID定义文档
:---:---:---:---
以太坊地址addr0x3b3b57deEIP137
ENS域名name0x691f3431EIP181
ABI规范ABI0x2203ab56EIP205
公钥pubkey0xc8690233EIP619
文本记录text0x59d1d43cEIP634
内容散列contenthash0xbc1c58d1

supportsInterface must also return true for the interfaceID value 0x01ffc9a7, which is the interface ID of supportsInterface itself. supportsInterface本身的接口ID为0x01ffc9a7,当interfaceID值为0x01ffc9a7时,supportsInterface也必须返回true。

Additionally, the content interface was used as a defacto standard for Swarm hashes, and has an interface ID of 0xd8389dc5. New implementations should use contenthash instead. 此外,content接口被用作Swarm散列事实上的标准,它的接口ID为0xd8389dc5。现在新的内容散列应该使用contenthash接口来实现。

Example Resolver

解析器示例

A simple resolver that supports only the addr type might look something like this: 一个只支持addr类型的简易解析器,看起来就像这样:

contract SimpleResolver {
    function supportsInterface(bytes4 interfaceID) constant returns (bool) {
        return interfaceID == 0x3b3b57de;
    }

    function addr(bytes32 nodeID) constant returns (address) {
        return address(this);
    }
}
1
2
3
4
5
6
7
8
9

这个简易解析器总是返回自己的地址作为所有查询的结果。尽管解析器采用不同的机制应该返回相同的结果,但实际上解析器可以按照需要采用任何机制来确定返回的结果,并且应该尽可能降低gas费用。