Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(subgraphs): Add creationTransactionHash to lock entity in subgraph #15261

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Lock @entity {
The primary reason for this role is to support additional purchase mechanisms beyond direct key purchases like credit-card purchases.
"""
keyGranters: [Bytes!]!
"transaction hash of the lock's creation"
transactionHash: String!
0xTxbi marked this conversation as resolved.
Show resolved Hide resolved
}

type Key @entity {
Expand Down
3 changes: 2 additions & 1 deletion subgraph/src/unlock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-unused-vars */
/* eslint-disable prefer-const */
import { log, BigInt, ethereum } from '@graphprotocol/graph-ts'
import { log, BigInt } from '@graphprotocol/graph-ts'
import { NewLock, LockUpgraded, GNPChanged } from '../generated/Unlock/Unlock'
import { PublicLock as PublicLockMerged } from '../generated/templates/PublicLock/PublicLock'
import { PublicLock } from '../generated/templates'
Expand Down Expand Up @@ -105,6 +105,7 @@ export function handleNewLock(event: NewLock): void {
lock.createdAtBlock = event.block.number
lock.lastKeyMintedAt = null
lock.lastKeyRenewedAt = null
lock.transactionHash = event.transaction.hash.toHexString()

if (version.le(BigInt.fromI32(8))) {
// prior to v8, add default lock manager
Expand Down
5 changes: 5 additions & 0 deletions subgraph/tests/locks-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export function createNewLockEvent(
): NewLock {
const newLockEvent = changetype<NewLock>(newMockEvent())

// Set a deterministic transaction hash for testing
newLockEvent.transaction.hash = Bytes.fromHexString(
'0x0000000000000000000000000000000000000000000000000000000000000001'
)

newLockEvent.parameters = []

newLockEvent.parameters.push(
Expand Down
6 changes: 6 additions & 0 deletions subgraph/tests/locks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ describe('Describe Locks events', () => {
assert.entityCount('Lock', 1)
assert.fieldEquals('Lock', lockAddress, 'address', lockAddress)
assert.fieldEquals('Lock', lockAddress, 'createdAtBlock', '1')
assert.fieldEquals(
'Lock',
lockAddress,
'transactionHash',
'0x0000000000000000000000000000000000000000000000000000000000000001'
)
assert.fieldEquals('Lock', lockAddress, 'version', '11')
assert.fieldEquals('Lock', lockAddress, 'price', '1000')
assert.fieldEquals('Lock', lockAddress, 'name', 'My lock graph')
Expand Down
Loading