Skip to content

Commit e1df119

Browse files
authored
Fix #628 & #629 & #621: Store event log index for all records (#630)
* Store eventIndex. * Changed in veDelegation. Removed import of String. * linter. * Removed tx hash. * Revert some tweaks. * added logIndex. * converted to big int. * 0 -> BigInt.zero(). * Added eventIndex to template and OPC. * updated tweak * updated tweak2 * Added eventIndex in tests. * revert. * Added eventIndex for TokenCreated and NFTCreated events. Increase time sleep for graphql request. * Changed position of eventIndex in entity. * Added eventIndex for order events and for dt events. Added new test commands in package.json. * Added eventIndex for NFT Update events. * Added eventIndex for dispenser. * Modified dispenser tests. * Reverted sleep secs. Updated tests. * Updated dispenser tests. Added eventIndex for FRE. * Added eventIndex in df rewards. * Updated Ve with eventIndex. * Updating order id with event index. * Updated @ocean/lib with multichain version. * Updated to number type. * Updated tests for order. * some changes. * Fix dt tests. Added logs for provider fee. Need fix for Simple publish and consume tests. * Problem raised by retrieving order event index in provider fee event handler. * Added function for searching the right order. * Debug order with provider fee. * Removed console logs. * Added debug logs. * Hardcoded eventIndex just for testing. * Paste logs from graph node. * added extra sleep in test. * fixed command. * Added comments. Modified util function for Order Reuse. * Added more logs and other tweaks. * fixed command for docker logs. * Added more logs. * Converted to lowercase. * Removed condition just for test. * Added more logs. Order is not null. * Call getOrder. * Added verification back. * converted to hex and add toString. * Pass toString as param. * Added ethereumjs util. * replaced with ==. * Refactored logic. * Print event index. * added more logs of event index. * Modified tweaks and asserts. * Added log for reuse order. * updates. * Reverted changes. * Added check for eventIndex == 0. * Enhanced the code. Replaced while with for. * Added more logs for reuse test. * added another condition. * Added logs in tests. Removed redundant condition. * Added more logs to test. * Fixed typo. * still debugging * Refactored code. * Getting closer. * Fix tests for orders part. Removed logs. * Removed more logs. * Fix DT tests related to order. * Implemented Publishing Market Fee event handler. Added test. * Added consume market fee handler. Test consume market fee handler. * Fixed tests for fees. Added TODOs. * Generated ID with eventIndex in ficed rate. Added assert errors messages. * Added FRE tests to workflow. * Generated dispenser transaction with event index. * Fixed dispenser tests. * Add event index for NftUpdate entity ID. * Changed IDs for VeDelegation and VeAllocationUpdate. * Added full test suite to workflow. * Fixed nft transfer ID. * print blocks. * test just dt and ending test to see the last block. * Added df test. * Added dispenser test. * Added FRE test. * Added NFT test. * Added simple publish consume test. * Added simple subgraph test. * Added users test. * Added ve test. * Increased sleep time. * commented delegation test. * respect lint * Fixed ending tests. Removed commented code. Brought back test suite. * Print values from failing tests. Updated mappings. * Rollback changes in veDelegation and veUtils. Added more prints for debug in tests. * Removed veDelegation creation record. * Rollback to the approach for veDelegation like it is in main. * Removed prints. Match changes with main. * Removed -1 from last block. * Added prints for eventIndex. Fixed some suggestions. * Fixed veDelegation. * Removed prints.
1 parent c42cd1c commit e1df119

26 files changed

+647
-170
lines changed

.github/workflows/tests.yml

+3
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ jobs:
7474
env:
7575
ADDRESS_FILE: /home/runner/.ocean/ocean-contracts/artifacts/address.json
7676
BARGE_FOLDER: /home/runner/.ocean/
77+
- name: docker logs
78+
run: docker logs ocean_graph-node_1
79+
if: ${{ failure() }}

package-lock.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
"test-df": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/DFRewards.test.ts'",
3434
"test-dt": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Datatoken.test.ts'",
3535
"test-zend": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/ZEnding.test.ts'",
36+
"test-publish-consume": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/SimplePublishConsume.test.ts'",
37+
"test-nft": "TS_NODE_PROJECT='test/integration/tsconfig.json' mocha --config=test/integration/.mocharc.json --node-env=test --exit 'test/integration/Nft.test.ts'",
3638
"lint": "eslint --ignore-path .gitignore --ext .js --ext .ts --ext .tsx .",
3739
"lint:fix": "eslint --ignore-path .gitignore --ext .js,.ts,.tsx . --fix",
3840
"format": "prettier --ignore-path .gitignore './**/*.{css,yml,js,ts,tsx,json,yaml}' --write",
@@ -72,7 +74,8 @@
7274
"dependencies": {
7375
"@oceanprotocol/contracts": "^1.1.12",
7476
"@oceanprotocol/lib": "^2.7.0",
75-
"cross-fetch": "^3.1.4"
77+
"cross-fetch": "^3.1.4",
78+
"ethereumjs-util": "^7.1.5"
7679
},
7780
"repository": {
7881
"type": "git",

schema.graphql

+24-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type Token @entity {
5252

5353
"datatoken creation transaction id"
5454
tx: String!
55-
55+
eventIndex: Int!
5656
"block number when it was created"
5757
block: Int!
5858

@@ -105,6 +105,7 @@ type Nft @entity{
105105
createdTimestamp: Int!
106106
"nft creation transaction id"
107107
tx: String!
108+
eventIndex: Int!
108109
"block number when it was created"
109110
block: Int
110111

@@ -132,6 +133,7 @@ type OrderReuse @entity {
132133
caller: String!
133134
createdTimestamp: Int!
134135
tx: String!
136+
eventIndex: Int!
135137
block: Int!
136138
providerFee: String
137139
providerFeeValidUntil: BigInt
@@ -141,7 +143,7 @@ type OrderReuse @entity {
141143
}
142144

143145
type Order @entity {
144-
"transaction hash - token address - from address"
146+
"transaction hash - token address - from address - eventIndex"
145147
id: ID!
146148
datatoken: Token!
147149

@@ -167,6 +169,7 @@ type Order @entity {
167169

168170
createdTimestamp: Int!
169171
tx: String!
172+
eventIndex: Int!
170173
block: Int!
171174

172175
lastPriceToken: Token
@@ -220,6 +223,7 @@ type FixedRateExchange @entity {
220223

221224
createdTimestamp: Int!
222225
tx: String!
226+
eventIndex: Int!
223227
block: Int!
224228

225229
"address of the market where the datatoken was created. This address collects market fees."
@@ -246,6 +250,7 @@ type FixedRateExchangeUpdate @entity {
246250
block: Int!
247251
createdTimestamp: Int!
248252
tx: String!
253+
eventIndex: Int!
249254
}
250255

251256
type FixedRateExchangeSwap @entity {
@@ -257,6 +262,7 @@ type FixedRateExchangeSwap @entity {
257262
block: Int!
258263
createdTimestamp: Int!
259264
tx: String!
265+
eventIndex: Int!
260266
oceanFeeAmount: BigDecimal!
261267
marketFeeAmount: BigDecimal!
262268
consumeMarketFeeAmount: BigDecimal!
@@ -285,7 +291,8 @@ type Dispenser @entity {
285291
block: Int!
286292
createdTimestamp: Int!
287293
tx: String!
288-
294+
eventIndex: Int!
295+
289296
dispenses: [DispenserTransaction!] @derivedFrom(field: "dispenser")
290297
}
291298

@@ -298,6 +305,7 @@ type DispenserTransaction @entity {
298305
block: Int!
299306
createdTimestamp: Int!
300307
tx: String!
308+
eventIndex: Int!
301309
}
302310

303311
"utility type"
@@ -385,6 +393,7 @@ type NftUpdate @entity {
385393
block: Int!
386394
timestamp: Int!
387395
tx: String!
396+
eventIndex: Int!
388397
}
389398

390399
type Template @entity{
@@ -406,6 +415,7 @@ type VeAllocateUser @entity{
406415
firstContact: Int!
407416
lastContact: Int!
408417
tx: String!
418+
eventIndex: Int!
409419
veOcean: VeOCEAN!
410420
}
411421

@@ -422,6 +432,7 @@ type VeAllocateId @entity{
422432
firstContact: Int!
423433
lastContact: Int!
424434
tx: String!
435+
eventIndex: Int!
425436
}
426437

427438
# we need to track allocation of user to id
@@ -441,6 +452,7 @@ type VeAllocation @entity {
441452
firstContact: Int!
442453
lastContact: Int!
443454
tx: String!
455+
eventIndex: Int!
444456
}
445457

446458
enum veAllocationUpdateType {
@@ -449,7 +461,7 @@ enum veAllocationUpdateType {
449461
}
450462

451463
type VeAllocationUpdate @entity {
452-
"{tx}-{VeAllocation id}"
464+
"{tx}-{VeAllocation id}-{eventIndex}"
453465
id: ID!
454466

455467
veAllocation: VeAllocation!
@@ -459,10 +471,11 @@ type VeAllocationUpdate @entity {
459471
block: Int!
460472
timestamp: Int!
461473
tx: String!
474+
eventIndex: Int!
462475
}
463476

464477
type VeDelegation @entity {
465-
"id = VeDelegation contract + tokenId"
478+
"id = VeDelegation contract + tokenId"
466479
id: ID!
467480
delegator: VeOCEAN!
468481
receiver: VeOCEAN!
@@ -480,6 +493,7 @@ type VeDelegationUpdate @entity {
480493
block: Int!
481494
timestamp: Int!
482495
tx: String!
496+
eventIndex: Int!
483497
sender: String!
484498
amount: BigDecimal!
485499
cancelTime: BigInt!
@@ -521,6 +535,7 @@ type VeDeposit @entity {
521535
timestamp: BigInt!
522536
block: Int!
523537
tx: String!
538+
eventIndex: Int!
524539
veOcean: VeOCEAN!
525540
totalOceanLocked:BigDecimal!
526541
}
@@ -546,6 +561,7 @@ type VeFeeDistributorCheckPoint @entity {
546561
timestamp: BigInt!
547562
block: Int!
548563
tx: String!
564+
eventIndex: Int!
549565
}
550566

551567
type VeClaim @entity {
@@ -560,6 +576,7 @@ type VeClaim @entity {
560576
timestamp: BigInt!
561577
block: Int!
562578
tx: String!
579+
eventIndex: Int!
563580
veOcean: VeOCEAN!
564581
VeFeeDistributor: VeFeeDistributor!
565582
}
@@ -588,6 +605,7 @@ type DFHistory @entity {
588605
timestamp: BigInt!
589606
block: Int!
590607
tx: String!
608+
eventIndex: Int!
591609
}
592610

593611

@@ -606,6 +624,7 @@ type NftTransferHistory @entity {
606624
oldOwner: User!
607625
newOwner: User!
608626
txId: String
627+
eventIndex: Int!
609628
timestamp: Int!
610629
block: Int!
611630
}

src/mappings/dfRewards.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function handleAllocated(event: Allocated): void {
2626
history.type = 'Allocated'
2727
history.timestamp = event.block.timestamp
2828
history.tx = event.transaction.hash.toHex()
29+
history.eventIndex = event.logIndex.toI32()
2930
history.block = event.block.number.toI32()
3031
history.save()
3132

@@ -55,6 +56,7 @@ export function handleClaimed(event: Claimed): void {
5556
history.type = 'Claimed'
5657
history.timestamp = event.block.timestamp
5758
history.tx = event.transaction.hash.toHex()
59+
history.eventIndex = event.logIndex.toI32()
5860
history.block = event.block.number.toI32()
5961
history.save()
6062

src/mappings/dispenser.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function handleNewDispenser(event: DispenserCreated): void {
4343
dispenser.allowedSwapper = event.params.allowedSwapper.toHex()
4444
dispenser.createdTimestamp = event.block.timestamp.toI32()
4545
dispenser.tx = event.transaction.hash.toHex()
46+
dispenser.eventIndex = event.logIndex.toI32()
4647
dispenser.block = event.block.number.toI32()
4748
dispenser.save()
4849

@@ -57,6 +58,7 @@ export function handleActivate(event: DispenserActivated): void {
5758
)
5859
const dispenser = getDispenser(dispenserID)
5960
dispenser.active = true
61+
dispenser.eventIndex = event.logIndex.toI32()
6062
dispenser.save()
6163
}
6264

@@ -67,6 +69,7 @@ export function handleDeactivate(event: DispenserDeactivated): void {
6769
)
6870
const dispenser = getDispenser(dispenserID)
6971
dispenser.active = false
72+
dispenser.eventIndex = event.logIndex.toI32()
7073
dispenser.save()
7174
}
7275

@@ -76,6 +79,7 @@ export function handleAllowedSwapperChanged(
7679
const dispenserID = getDispenserGraphID(event.address, event.params.datatoken)
7780
const dispenser = getDispenser(dispenserID)
7881
dispenser.allowedSwapper = event.params.newAllowedSwapper.toHex()
82+
dispenser.eventIndex = event.logIndex.toI32()
7983
dispenser.save()
8084
}
8185

@@ -84,10 +88,8 @@ export function handleTokensDispensed(event: TokensDispensed): void {
8488
event.address,
8589
event.params.datatokenAddress
8690
)
87-
const id = event.transaction.hash
88-
.toHexString()
89-
.concat('-')
90-
.concat(dispenserID)
91+
const eventIndex: number = event.logIndex.toI32()
92+
const id = `${event.transaction.hash.toHexString()}-${dispenserID}-${eventIndex}`
9193

9294
const dispenserTransaction = new DispenserTransaction(id)
9395
const dispenser = getDispenser(dispenserID)
@@ -98,6 +100,7 @@ export function handleTokensDispensed(event: TokensDispensed): void {
98100

99101
dispenserTransaction.createdTimestamp = event.block.timestamp.toI32()
100102
dispenserTransaction.tx = event.transaction.hash.toHex()
103+
dispenserTransaction.eventIndex = event.logIndex.toI32()
101104
dispenserTransaction.block = event.block.number.toI32()
102105
const token = getToken(event.params.datatokenAddress, true)
103106
dispenserTransaction.amount = weiToDecimal(
@@ -111,5 +114,6 @@ export function handleOwnerWinthdraw(event: OwnerWithdrawed): void {
111114
const dispenserID = getDispenserGraphID(event.address, event.params.datatoken)
112115
const dispenser = getDispenser(dispenserID)
113116
dispenser.balance = decimal.ZERO
117+
dispenser.eventIndex = event.logIndex.toI32()
114118
dispenser.save()
115119
}

0 commit comments

Comments
 (0)