Skip to content

Commit

Permalink
Merge pull request #92 from ensdomains/feat/abi-pubkey-support
Browse files Browse the repository at this point in the history
feat: resolver ABI setter/getter support
  • Loading branch information
TateB authored Jan 16, 2023
2 parents 545c08e + 1c0fc78 commit d6a50c8
Show file tree
Hide file tree
Showing 13 changed files with 914 additions and 10 deletions.
202 changes: 202 additions & 0 deletions packages/ensjs/deploy/00_register_legacy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,133 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-await-in-loop */
import { toUtf8Bytes } from '@ethersproject/strings'
import cbor from 'cbor'
import { ethers } from 'hardhat'
import { DeployFunction } from 'hardhat-deploy/types'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import pako from 'pako'
import { labelhash } from '../src/utils/labels'
import { namehash } from '../src/utils/normalise'

const dummyABI = [
{
type: 'event',
anonymous: false,
name: 'ABIChanged',
inputs: [
{
type: 'bytes32',
indexed: true,
},
{
type: 'uint256',
indexed: true,
},
],
},
{
type: 'event',
anonymous: false,
name: 'VersionChanged',
inputs: [
{
type: 'bytes32',
indexed: true,
},
{
type: 'uint64',
},
],
},
{
type: 'function',
name: 'ABI',
constant: true,
stateMutability: 'view',
payable: false,
inputs: [
{
type: 'bytes32',
},
{
type: 'uint256',
},
],
outputs: [
{
type: 'uint256',
},
{
type: 'bytes',
},
],
},
{
type: 'function',
name: 'clearRecords',
constant: false,
payable: false,
inputs: [
{
type: 'bytes32',
},
],
outputs: [],
},
{
type: 'function',
name: 'recordVersions',
constant: true,
stateMutability: 'view',
payable: false,
inputs: [
{
type: 'bytes32',
},
],
outputs: [
{
type: 'uint64',
},
],
},
{
type: 'function',
name: 'setABI',
constant: false,
payable: false,
inputs: [
{
type: 'bytes32',
},
{
type: 'uint256',
},
{
type: 'bytes',
},
],
outputs: [],
},
{
type: 'function',
name: 'supportsInterface',
constant: true,
stateMutability: 'view',
payable: false,
inputs: [
{
type: 'bytes4',
},
],
outputs: [
{
type: 'bool',
},
],
},
]

type Subname = {
label: string
namedOwner: string
Expand All @@ -25,6 +147,10 @@ const names: {
value: string
}[]
contenthash?: string
abi?: {
contentType: 1 | 2 | 4 | 8 | 256
data: object | string
}
}
subnames?: Subname[]
}[] = [
Expand Down Expand Up @@ -106,6 +232,61 @@ const names: {
{ label: 'addr', namedOwner: 'owner2' },
],
},
{
label: 'with-type-1-abi',
namedOwner: 'owner',
namedAddr: 'owner',
records: {
abi: {
contentType: 1,
data: dummyABI,
},
},
},
{
label: 'with-type-2-abi',
namedOwner: 'owner',
namedAddr: 'owner',
records: {
abi: {
contentType: 2,
data: dummyABI,
},
},
},
{
label: 'with-type-4-abi',
namedOwner: 'owner',
namedAddr: 'owner',
records: {
abi: {
contentType: 4,
data: dummyABI,
},
},
},
{
label: 'with-type-8-abi',
namedOwner: 'owner',
namedAddr: 'owner',
records: {
abi: {
contentType: 8,
data: 'https://example.com',
},
},
},
{
label: 'with-type-256-abi',
namedOwner: 'owner',
namedAddr: 'owner',
records: {
abi: {
contentType: 256,
data: dummyABI,
},
},
},
...Array.from({ length: 34 }, (_, i) => ({
label: `${i}-dummy`,
namedOwner: 'owner2',
Expand Down Expand Up @@ -199,6 +380,27 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
)
await setContenthashTx.wait()
}
if (records.abi) {
console.log('ABI')
let data: string | Buffer | Uint8Array
if (records.abi.contentType === 1 || records.abi.contentType === 256) {
data = JSON.stringify(records.abi.data)
} else if (records.abi.contentType === 2) {
data = pako.deflate(JSON.stringify(records.abi.data))
} else if (records.abi.contentType === 4) {
data = cbor.encode(records.abi.data)
} else {
data = records.abi.data as string
}
if (typeof data === 'string') data = toUtf8Bytes(data)
const setABITx = await _publicResolver.setABI(
hash,
records.abi.contentType,
data,
)
console.log(` - ${records.abi.contentType} (tx: ${setABITx.hash})...`)
await setABITx.wait()
}
}

if (subnames) {
Expand Down
3 changes: 2 additions & 1 deletion packages/ensjs/ens-test-env.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = {
deployCommand: 'pnpm hardhat deploy',
scripts: [
{
command: process.env.STATIC_ENS ? 'pnpm test:static' : 'pnpm test',
command:
process.env.STATIC_ENS === 'true' ? 'pnpm test:static' : 'pnpm test',
name: 'jest',
prefixColor: 'yellow.bold',
finishOnExit: true,
Expand Down
3 changes: 3 additions & 0 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@
"@ensdomains/content-hash": "^2.5.7",
"@ensdomains/dnsprovejs": "^0.4.1",
"@ensdomains/dnssecoraclejs": "^0.2.7",
"cbor": "^8.1.0",
"dns-packet": "^5.3.1",
"graphql": "^16.3.0",
"graphql-request": "next",
"idna-uts46-hx": "3.4.0",
"pako": "^2.1.0",
"traverse": "^0.6.6"
},
"devDependencies": {
Expand Down Expand Up @@ -109,6 +111,7 @@
"@typechain/ethers-v5": "^10.1.0",
"@types/bn.js": "^5.1.0",
"@types/jest": "^27.4.1",
"@types/pako": "^2.0.0",
"@types/traverse": "^0.6.32",
"dotenv": "^16.0.0",
"esbuild": "^0.15.6",
Expand Down
Loading

0 comments on commit d6a50c8

Please sign in to comment.