Skip to content

Commit

Permalink
gatewayUrls + getRecords cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 5, 2024
1 parent 6d34c20 commit 16a97b1
Show file tree
Hide file tree
Showing 10 changed files with 435 additions and 259 deletions.
154 changes: 95 additions & 59 deletions packages/ensjs/src/contracts/universalResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,92 +46,128 @@ export const universalResolverErrors = [
},
] as const

const universalResolverReverse = {
inputs: [
{
name: 'reverseName',
type: 'bytes',
},
],
name: 'reverse',
outputs: [
{ type: 'string', name: 'resolvedName' },
{ type: 'address', name: 'resolvedAddress' },
{ type: 'address', name: 'reverseResolver' },
{ type: 'address', name: 'resolver' },
],
stateMutability: 'view',
type: 'function',
} as const

export const universalResolverReverseSnippet = [
...universalResolverErrors,
universalResolverReverse,
{
...universalResolverReverse,
inputs: [
...universalResolverReverse.inputs,
{
name: 'reverseName',
type: 'bytes',
name: 'gateways',
type: 'string[]',
},
],
name: 'reverse',
outputs: [
{ type: 'string', name: 'resolvedName' },
{ type: 'address', name: 'resolvedAddress' },
{ type: 'address', name: 'reverseResolver' },
{ type: 'address', name: 'resolver' },
],
stateMutability: 'view',
type: 'function',
},
] as const

const universalResolverResolve = {
inputs: [
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes',
},
],
name: 'resolve',
outputs: [
{
name: 'data',
type: 'bytes',
},
{
name: 'resolver',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
} as const

export const universalResolverResolveSnippet = [
...universalResolverErrors,
universalResolverResolve,
{
...universalResolverResolve,
inputs: [
...universalResolverResolve.inputs,
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes',
name: 'gateways',
type: 'string[]',
},
],
name: 'resolve',
outputs: [
{
name: 'data',
type: 'bytes',
},
{
name: 'resolver',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
},
] as const

const universalResolverResolveArray = {
inputs: [
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes[]',
},
],
name: 'resolve',
outputs: [
{
components: [
{
name: 'success',
type: 'bool',
},
{
name: 'returnData',
type: 'bytes',
},
],
name: '',
type: 'tuple[]',
},
{
name: '',
type: 'address',
},
],
stateMutability: 'view',
type: 'function',
} as const

export const universalResolverResolveArraySnippet = [
...universalResolverErrors,
universalResolverResolveArray,
{
...universalResolverResolveArray,
inputs: [
...universalResolverResolveArray.inputs,
{
name: 'name',
type: 'bytes',
},
{
name: 'data',
type: 'bytes[]',
},
],
name: 'resolve',
outputs: [
{
components: [
{
name: 'success',
type: 'bool',
},
{
name: 'returnData',
type: 'bytes',
},
],
name: '',
type: 'tuple[]',
},
{
name: '',
type: 'address',
name: 'gateways',
type: 'string[]',
},
],
stateMutability: 'view',
type: 'function',
},
] as const

Expand Down
15 changes: 12 additions & 3 deletions packages/ensjs/src/functions/public/getAbiRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ import _getAbi, {
} from './_getAbi.js'
import universalWrapper from './universalWrapper.js'

export type GetAbiRecordParameters = Prettify<InternalGetAbiParameters>
export type GetAbiRecordParameters = Prettify<
InternalGetAbiParameters & {
/** Batch gateway URLs to use for resolving CCIP-read requests. */
gatewayUrls?: string[]
}
>

export type GetAbiRecordReturnType = Prettify<InternalGetAbiReturnType>

const encode = (
client: ClientWithEns,
{ name }: Omit<GetAbiRecordParameters, 'strict'>,
{ name, gatewayUrls }: Omit<GetAbiRecordParameters, 'strict'>,
): SimpleTransactionRequest => {
const prData = _getAbi.encode(client, { name })
return universalWrapper.encode(client, { name, data: prData.data })
return universalWrapper.encode(client, {
name,
data: prData.data,
gatewayUrls,
})
}

const decode = async (
Expand Down
19 changes: 16 additions & 3 deletions packages/ensjs/src/functions/public/getAddressRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@ import _getAddr, {
} from './_getAddr.js'
import universalWrapper from './universalWrapper.js'

export type GetAddressRecordParameters = Prettify<InternalGetAddrParameters>
export type GetAddressRecordParameters = Prettify<
InternalGetAddrParameters & {
/** Batch gateway URLs to use for resolving CCIP-read requests. */
gatewayUrls?: string[]
}
>

export type GetAddressRecordReturnType = Prettify<InternalGetAddrReturnType>

const encode = (
client: ClientWithEns,
{ name, coin }: Omit<GetAddressRecordParameters, 'strict' | 'bypassFormat'>,
{
name,
coin,
gatewayUrls,
}: Omit<GetAddressRecordParameters, 'strict' | 'bypassFormat'>,
): SimpleTransactionRequest => {
const prData = _getAddr.encode(client, { name, coin })
return universalWrapper.encode(client, { name, data: prData.data })
return universalWrapper.encode(client, {
name,
data: prData.data,
gatewayUrls,
})
}

const decode = async (
Expand Down
16 changes: 12 additions & 4 deletions packages/ensjs/src/functions/public/getContentHashRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ import _getContentHash, {
} from './_getContentHash.js'
import universalWrapper from './universalWrapper.js'

export type GetContentHashRecordParameters =
Prettify<InternalGetContentHashParameters>
export type GetContentHashRecordParameters = Prettify<
InternalGetContentHashParameters & {
/** Batch gateway URLs to use for resolving CCIP-read requests. */
gatewayUrls?: string[]
}
>

export type GetContentHashRecordReturnType =
Prettify<InternalGetContentHashReturnType>

const encode = (
client: ClientWithEns,
{ name }: Omit<GetContentHashRecordParameters, 'strict'>,
{ name, gatewayUrls }: Omit<GetContentHashRecordParameters, 'strict'>,
): TransactionRequestWithPassthrough => {
const prData = _getContentHash.encode(client, { name })
return universalWrapper.encode(client, { name, data: prData.data })
return universalWrapper.encode(client, {
name,
data: prData.data,
gatewayUrls,
})
}

const decode = async (
Expand Down
34 changes: 27 additions & 7 deletions packages/ensjs/src/functions/public/getName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type GetNameParameters = {
allowMismatch?: boolean
/** Whether or not to throw decoding errors */
strict?: boolean
/** Batch gateway URLs to use for resolving CCIP-read requests. */
gatewayUrls?: string[]
}

export type GetNameReturnType = {
Expand All @@ -42,22 +44,40 @@ export type GetNameReturnType = {

const encode = (
client: ClientWithEns,
{ address }: Pick<GetNameParameters, 'address'>,
{ address, gatewayUrls }: Omit<GetNameParameters, 'allowMismatch' | 'strict'>,
): TransactionRequestWithPassthrough => {
const reverseNode = `${address.toLowerCase().substring(2)}.addr.reverse`
const to = getChainContractAddress({
client,
contract: 'ensUniversalResolver',
})
const args = [toHex(packetToBytes(reverseNode))] as const

return {
to,
data: encodeFunctionData({
abi: universalResolverReverseSnippet,
functionName: 'reverse',
args,
}),
passthrough: { address, args },
...(gatewayUrls?.length
? {
data: encodeFunctionData({
abi: universalResolverReverseSnippet,
functionName: 'reverse',
args: [...args, gatewayUrls] as const,
}),
passthrough: {
args: [...args, gatewayUrls],
address: to,
},
}
: {
data: encodeFunctionData({
abi: universalResolverReverseSnippet,
functionName: 'reverse',
args,
}),
passthrough: {
args,
address: to,
},
}),
}
}

Expand Down
Loading

0 comments on commit 16a97b1

Please sign in to comment.