Skip to content

Commit

Permalink
Added content-hash support to ENS CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Aug 6, 2019
1 parent 2cc5154 commit 7dfef46
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@types/node": "10.3.2",
"@ethersproject/basex": ">=5.0.0-beta.126",
"ethers": ">5.0.0-beta.0",
"mime-types": "2.1.11",
"scrypt-js": "2.0.4",
Expand Down
57 changes: 42 additions & 15 deletions packages/cli/src.ts/bin/ethers-ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

'use strict';

import { ethers } from 'ethers';
import { ethers } from "ethers";
import { Base58 } from "@ethersproject/basex";

import { ArgParser, CLI, Help, Plugin } from '../cli';

Expand Down Expand Up @@ -45,6 +46,8 @@ const resolverAbi = [
"function setAddr(bytes32 nodehash, address addr) @500000",
"function text(bytes32 nodehash, string key) view returns (string)",
"function setText(bytes32 nodehash, string key, string value) @500000",
"function contenthash(bytes32 nodehash) view returns (bytes)",
"function setContenthash(bytes32 nodehash, bytes contenthash) @500000",
];

const InterfaceID_ERC721 = "0x6ccb2df4";
Expand Down Expand Up @@ -180,9 +183,16 @@ class LookupPlugin extends EnsPlugin {

if (details.Resolver !== ethers.constants.AddressZero) {
let resolver = new ethers.Contract(details.Resolver, resolverAbi, this.provider);
details.address = resolver.addr(nodehash);
details.email = resolver.text(nodehash, "email").catch((error: any) => (""));
details.website = resolver.text(nodehash, "website").catch((error: any) => (""));
details["Address"] = resolver.addr(nodehash);
details["E-mail"] = resolver.text(nodehash, "email").catch((error: any) => (""));
details["Website"] = resolver.text(nodehash, "website").catch((error: any) => (""));
details["Content Hash"] = resolver.contenthash(nodehash).then((hash: string) => {
if (hash === "0x") { return "0x"; }
if (hash.substring(0, 10) === "0xe3010170" && ethers.utils.isHexString(hash, 38)) {
return Base58.encode(ethers.utils.hexDataSlice(hash, 4)) + " (IPFS)";
}
return hash + " (unknown format)";
}, (error: any) => (""));
}

details = await ethers.utils.resolveProperties(details);
Expand Down Expand Up @@ -619,28 +629,43 @@ class SetWebsitePlugin extends TextAccountPlugin {

cli.addPlugin("set-website", SetWebsitePlugin);

/*
// @TODO:
class SetContentHashPlugin extends AccountPlugin {
hash: string;
class SetContentPlugin extends AccountPlugin {
readonly hash: string;
readonly multihash: string;

static getHelp(): Help {
return {
name: "set-content NAME HASH",
help: "Set the content hash record to HASH"
help: "Set the IPFS HASH for NAME"
}
}

async _setValue(key: string, value: string): Promise<void> {
if (key === "hash") {
let bytes = Base58.decode(value);
if (bytes.length !== 34 || bytes[0] !== 18 || bytes[1] !== 32) {
this.throwError("Unsupported IPFS hash");
}

let multihash = ethers.utils.concat([ "0xe3010170", bytes ]);
await super._setValue("multihash", ethers.utils.hexlify(multihash));
}
await super._setValue(key, value);
}

async run(): Promise<void> {
await super.run();
throw new Error("not implemented");
//let resolver = await this.getResolver();
//let tx = resolver.setContenthash(this.nodehash, this.key, this.value);
//this.wait(tx);

this.dump("Set Content Hash: " + this.name, {
Nodehash: this.nodehash,
"Content Hash": this.hash
});

let resolver = await this.getResolver(this.nodehash);
await resolver.setContenthash(this.nodehash, this.multihash);
}
}
cli.addPlugin("set-content", SetContentHashPlugin);
*/
cli.addPlugin("set-content", SetContentPlugin);

class MigrateRegistrarPlugin extends AccountPlugin {
readonly label: string;
Expand Down Expand Up @@ -733,6 +758,8 @@ cli.addPlugin("transfer", TransferPlugin);
* To Do:
* register NAME --registrar
* set-reverse NAME
* renew NAME --duration DAYS
* reclaim NAME --address OWNER
*
* Done:
* migrate-registrar NAME
Expand Down

0 comments on commit 7dfef46

Please sign in to comment.