Skip to content

Commit

Permalink
fix: decoding event logs if constructor in abi (#159)
Browse files Browse the repository at this point in the history
fix: fixed decoding event logs if constructor in abi
  • Loading branch information
jxom authored Mar 8, 2023
1 parent 1c19e42 commit 574ae22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/polite-wasps-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Fixed issue where decoding error logs would break if constructor was in ABI.
5 changes: 5 additions & 0 deletions src/utils/abi/decodeEventLog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { decodeEventLog } from './decodeEventLog'
test('Transfer()', () => {
const event = decodeEventLog({
abi: [
{
inputs: [],
stateMutability: 'nonpayable',
type: 'constructor',
},
{
inputs: [],
name: 'Transfer',
Expand Down
4 changes: 3 additions & 1 deletion src/utils/abi/decodeEventLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export function decodeEventLog<
>): DecodeEventLogReturnType<TAbi, TEventName, TTopics, TData> {
const [signature, ...argTopics] = topics
const abiItem = (abi as Abi).find(
(x) => signature === getEventSelector(formatAbiItem(x) as EventDefinition),
(x) =>
x.type === 'event' &&
signature === getEventSelector(formatAbiItem(x) as EventDefinition),
)
if (!(abiItem && 'name' in abiItem))
throw new AbiEventSignatureNotFoundError(signature, {
Expand Down

2 comments on commit 574ae22

@vercel
Copy link

@vercel vercel bot commented on 574ae22 Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viem-playground – ./playgrounds/browser

viem-playground.vercel.app
viem-playground-git-main-wagmi-dev.vercel.app
viem-playground-wagmi-dev.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 574ae22 Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.