Skip to content

Commit

Permalink
Add full support for MultiCoin plugins and automatic detection for EV…
Browse files Browse the repository at this point in the history
…M-compatible coin types (#3888, #4081).
  • Loading branch information
ricmoo committed Jun 13, 2023
1 parent 2318005 commit 84375be
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src.ts/providers/ens-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* @_section: api/providers/ens-resolver:ENS Resolver [about-ens-rsolver]
*/

import { getAddress } from "../address/index.js";
import { ZeroAddress } from "../constants/index.js";
import { Contract } from "../contract/index.js";
import { dnsEncode, namehash } from "../hash/index.js";
import {
hexlify, toBeHex,
hexlify, isHexString, toBeHex,
defineProperties, encodeBase58,
assert, assertArgument, isError,
FetchRequest
Expand Down Expand Up @@ -184,7 +185,7 @@ export class EnsResolver {
"function supportsInterface(bytes4) view returns (bool)",
"function resolve(bytes, bytes) view returns (bytes)",
"function addr(bytes32) view returns (address)",
"function addr(bytes32, uint) view returns (address)",
"function addr(bytes32, uint) view returns (bytes)",
"function text(bytes32, string) view returns (string)",
"function contenthash(bytes32) view returns (bytes)",
], provider);
Expand Down Expand Up @@ -276,6 +277,14 @@ export class EnsResolver {
}
}

// Try decoding its EVM canonical chain as an EVM chain address first
if (coinType >= 0 && coinType < 0x80000000) {
let ethCoinType = coinType + 0x80000000;

const data = await this.#fetch("addr(bytes32,uint)", [ ethCoinType ]);
if (isHexString(data, 20)) { return getAddress(data); }
}

let coinPlugin: null | MulticoinProviderPlugin = null;
for (const plugin of this.provider.plugins) {
if (!(plugin instanceof MulticoinProviderPlugin)) { continue; }
Expand All @@ -294,7 +303,7 @@ export class EnsResolver {
if (data == null || data === "0x") { return null; }

// Compute the address
const address = await coinPlugin.encodeAddress(coinType, data);
const address = await coinPlugin.decodeAddress(coinType, data);

if (address != null) { return address; }

Expand Down

0 comments on commit 84375be

Please # to comment.