Skip to content

Commit

Permalink
Merge pull request #68 from ensdomains/fix/get-history-wrapped-names
Browse files Browse the repository at this point in the history
added new domain/resolver events
  • Loading branch information
TateB authored Oct 12, 2022
2 parents b097530 + b37bf7b commit d8d7eee
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 23 deletions.
9 changes: 9 additions & 0 deletions packages/ensjs/src/functions/getHistory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ describe('getHistory', () => {
expect(result).toHaveProperty('registration')
}
})
it('should return the history of a wrapped name', async () => {
const result = await ensInstance.getHistory('wrapped.eth')
expect(result).toBeTruthy()
if (result) {
expect(result).toHaveProperty('domain')
expect(result).toHaveProperty('resolver')
expect(result).toHaveProperty('registration')
}
})
})
84 changes: 61 additions & 23 deletions packages/ensjs/src/functions/getHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import { decodeContenthash } from '../utils/contentHash'
import { labelhash } from '../utils/labels'
import { namehash } from '../utils/normalise'

type DomainEvent = 'NewOwner' | 'NewResolver' | 'Transfer' | 'NewTTL'
type DomainEvent =
| 'NewOwner'
| 'NewResolver'
| 'Transfer'
| 'NewTTL'
| 'WrappedTransfer'
| 'NameWrapped'
| 'NameUnwrapped'
| 'FusesSet'
type RegistrationEvent = 'NameRegistered' | 'NameRenewed' | 'NameTransferred'
type ResolverEvent =
| 'AddrChanged'
Expand All @@ -17,6 +25,7 @@ type ResolverEvent =
| 'ContenthashChanged'
| 'InterfaceChanged'
| 'AuthorisationChanged'
| 'VersionChanged'

type EventTypes = 'Domain' | 'Registration' | 'Resolver'
type EventFormat = {
Expand All @@ -33,6 +42,14 @@ const eventFormat: {
NewResolver: (args: any) => ({ resolver: args.resolver.id.split('-')[0] }),
Transfer: (args: any) => ({ owner: args.owner.id }),
NewTTL: (args: any) => ({ ttl: args.ttl }),
WrappedTransfer: (args: any) => ({ owner: args.owner.id }),
NameWrapped: (args: any) => ({
fuses: args.fuses,
owner: args.owner.id,
expiry: args.expiry,
}),
NameUnwrapped: (args: any) => ({ owner: args.owner.id }),
FusesSet: (args: any) => ({ fuses: args.fuses, expiry: args.expiry }),
},
Registration: {
NameRegistered: (args: any) => ({
Expand Down Expand Up @@ -79,6 +96,7 @@ const eventFormat: {
target: args.target,
isAuthorized: args.isAuthorized,
}),
VersionChanged: (args: any) => ({ version: args.version }),
},
}

Expand Down Expand Up @@ -129,27 +147,46 @@ export async function getHistory(
...on NewTTL {
ttl
}
}
owner {
registrations (where: { id: $labelhash }) {
events {
...on WrappedTransfer {
owner {
id
blockNumber
transactionID
__typename
...on NameRegistered {
registrant {
id
}
expiryDate
}
...on NameRenewed {
expiryDate
}
}
...on NameWrapped {
fuses
expiry
owner {
id
}
}
...on NameUnwrapped {
owner {
id
}
}
...on FusesSet {
fuses
expiry
}
}
registration {
events {
id
blockNumber
transactionID
__typename
...on NameRegistered {
registrant {
id
}
...on NameTransferred {
newOwner {
id
}
expiryDate
}
...on NameRenewed {
expiryDate
}
...on NameTransferred {
newOwner {
id
}
}
}
Expand Down Expand Up @@ -195,6 +232,9 @@ export async function getHistory(
target
isAuthorized
}
...on VersionChanged {
version
}
}
}
}
Expand All @@ -215,9 +255,7 @@ export async function getHistory(

const {
events: domainEvents,
owner: {
registrations: [{ events: registrationEvents }],
},
registration: { events: registrationEvents },
resolver: { events: resolverEvents },
} = domain

Expand Down

0 comments on commit d8d7eee

Please sign in to comment.