Skip to content

Commit

Permalink
fix: read contenthash
Browse files Browse the repository at this point in the history
  • Loading branch information
pikonha committed Oct 14, 2024
1 parent 41ff894 commit 0e6f7ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/client/src/db.write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getChainContractAddress,
http,
namehash,
stringToHex,
toHex,
} from 'viem'
import { normalize, packetToBytes } from 'viem/ens'
Expand Down
12 changes: 11 additions & 1 deletion packages/client/src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
namehash,
toHex,
getChainContractAddress,
decodeFunctionResult,
hexToString,
} from 'viem'
import { normalize, packetToBytes } from 'viem/ens'
import { getChain } from './client'
Expand Down Expand Up @@ -84,13 +86,21 @@ const _ = (async () => {
args: [toHex(packetToBytes(publicAddress))],
})) as Address[]

const contentHash = (await client.readContract({
const encodedContentHash = (await client.readContract({
address: resolverAddr,
functionName: 'contenthash',
args: [namehash(publicAddress)],
abi: dbAbi,
})) as Hex

const contentHash = hexToString(
decodeFunctionResult({
abi: dbAbi,
functionName: 'contenthash',
data: encodedContentHash,
}) as Hex,
)

console.log({
twitter,
avatar,
Expand Down
4 changes: 2 additions & 2 deletions packages/gateway/src/handlers/contenthash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hexToString } from 'viem'
import { hexToString, toHex } from 'viem'
import * as ccip from '@blockful/ccip-server'

import {
Expand Down Expand Up @@ -61,7 +61,7 @@ export function withGetContentHash(
const content = await repo.getContentHash({ node })
if (content)
return {
data: [content.value],
data: [toHex(content.value)],
extraData: formatTTL(content.ttl),
}
},
Expand Down

0 comments on commit 0e6f7ad

Please sign in to comment.