// SPDX-License-Identifier: MIT pragma solidity >=0.8.4; import "../ResolverBase.sol"; import "./IAddrResolver.sol"; import "./IAddressResolver.sol"; abstract contract SmartBchAddrResolver is IAddrResolver, IAddressResolver, ResolverBase { uint constant private COIN_TYPE_SMARTBCH = 2147493648; mapping(bytes32=>mapping(uint=>bytes)) _addresses; /** * Sets the address 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 a The address to set. */ function setAddr(bytes32 node, address a) virtual external authorised(node) { setAddr(node, COIN_TYPE_SMARTBCH, addressToBytes(a)); } /** * Returns the address associated with an ENS node. * @param node The ENS node to query. * @return The associated address. */ function addr(bytes32 node) virtual override public view returns (address payable) { bytes memory a = addr(node, COIN_TYPE_SMARTBCH); if(a.length == 0) { return payable(0); } return bytesToAddress(a); } function setAddr(bytes32 node, uint coinType, bytes memory a) virtual public authorised(node) { if(coinType == COIN_TYPE_SMARTBCH) { emit AddrChanged(node, bytesToAddress(a)); } emit AddressChanged(node, coinType, a); _addresses[node][coinType] = a; } function addr(bytes32 node, uint coinType) virtual override public view returns(bytes memory) { return _addresses[node][coinType]; } function supportsInterface(bytes4 interfaceID) virtual override public pure returns(bool) { return interfaceID == type(IAddrResolver).interfaceId || interfaceID == type(IAddressResolver).interfaceId || super.supportsInterface(interfaceID); } function bytesToAddress(bytes memory b) internal pure returns(address payable a) { require(b.length == 20); assembly { a := div(mload(add(b, 32)), exp(256, 12)) } } function addressToBytes(address a) internal pure returns(bytes memory b) { b = new bytes(20); assembly { mstore(add(b, 32), mul(a, exp(256, 12))) } } }