Skip to content

Commit ca42208

Browse files
authored
Added handler of EventRelayMiningDifficultyUpdated and bug fixes (#40)
## Summary * Added handler of `EventRelayMiningDifficultyUpdated` * Added `idx` field to Events, Messages and Transactions * Fixed bug with applications when an application was being transferred, and it was re-staked then the transfer info was overwritten * Added unhandled use case when an application was being delegated to a gateway and the gateway was unstaked, the delegate relation wasn't removed * Fixed `numClaimedComputedUnits`, `numEstimatedComputedUnits` and `claimedAmount` of relays entities * Updated `optimizedBulkCreate` util to create a transaction for every batch instead of reuse the transaction of subql to avoid errors when there are too many items to be saved (like in the block 72710)
1 parent a2a276a commit ca42208

File tree

17 files changed

+517
-111
lines changed

17 files changed

+517
-111
lines changed

schema.graphql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ type Transaction @entity {
292292
status: TxStatus! @index
293293
log: String
294294
code: Int!
295+
idx: Int!
295296
codespace: String
296297
timeoutHeight: BigInt @index
297298
# NB: only the first signer!
@@ -302,6 +303,7 @@ type Transaction @entity {
302303

303304
type Message @entity {
304305
id: ID!
306+
idx: Int!
305307
typeUrl: String! @index
306308
json: String
307309
transaction: Transaction!
@@ -311,6 +313,7 @@ type Message @entity {
311313

312314
type Event @entity {
313315
id: ID!
316+
idx: Int!
314317
type: String! @index
315318
kind: EventKind!
316319
attributes: [EventAttribute]!
@@ -444,6 +447,12 @@ type Service @entity {
444447
computeUnitsPerRelay: BigInt!
445448
owner: Account!
446449
addServiceMsgs: [MsgAddService] @derivedFrom(field: "service")
450+
relayMiningDifficultyUpdatedEvents: [EventRelayMiningDifficultyUpdated] @derivedFrom(field: "service")
451+
# data from the last EventRelayMiningDifficultyUpdated event
452+
prevTargetHashHexEncoded: String
453+
newTargetHashHexEncoded: String
454+
prevNumRelaysEma: BigInt
455+
newNumRelaysEma: BigInt
447456
}
448457

449458
type MsgStakeApplication @entity {
@@ -738,6 +747,17 @@ type MsgAddService @entity {
738747
message: Message!
739748
}
740749

750+
type EventRelayMiningDifficultyUpdated @entity {
751+
id: ID!
752+
service: Service!
753+
prevTargetHashHexEncoded: String!
754+
newTargetHashHexEncoded: String!
755+
prevNumRelaysEma: BigInt!
756+
newNumRelaysEma: BigInt!
757+
block: Block!
758+
event: Event!
759+
}
760+
741761
type Gateway @entity {
742762
# id is the address of the gateway
743763
id: ID!

src/mappings/authz/exec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ function _handleAuthzExec(msg: CosmosMessage<AuthzExecMsg>): HandleAuthzExecResu
4242

4343
result.messages.push({
4444
id: authzExecId,
45+
idx: msg.idx,
4546
typeUrl,
4647
json: stringify(msg.msg.decodedMsg),
4748
transactionId: msg.tx.hash,
@@ -85,6 +86,7 @@ function _handleAuthzExec(msg: CosmosMessage<AuthzExecMsg>): HandleAuthzExecResu
8586
// Create a primitive message entity for a sub-message
8687
result.messages.push({
8788
id: subMsgId,
89+
idx: msg.idx,
8890
typeUrl,
8991
json: stringify(decodedMsg),
9092
transactionId: msg.tx.hash,

src/mappings/handlers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
handleMsgCreateClaim,
3333
handleMsgSubmitProof,
3434
} from "./poktroll/relays";
35-
import { handleMsgAddService } from "./poktroll/services";
35+
import { handleEventRelayMiningDifficultyUpdated, handleMsgAddService } from "./poktroll/services";
3636
import {
3737
handleSupplierStakeMsg,
3838
handleSupplierUnbondingBeginEvent,
@@ -126,6 +126,8 @@ export const EventHandlers: Record<string, (events: Array<CosmosEvent>) => Promi
126126
// supplier
127127
"poktroll.supplier.EventSupplierUnbondingBegin": handleSupplierUnbondingBeginEvent,
128128
"poktroll.supplier.EventSupplierUnbondingEnd": handleSupplierUnbondingEndEvent,
129+
// service
130+
"poktroll.service.EventRelayMiningDifficultyUpdated": handleEventRelayMiningDifficultyUpdated,
129131
// gateway
130132
"poktroll.gateway.EventGatewayUnstaked": handleGatewayUnstakeEvent,
131133
"poktroll.gateway.EventGatewayUnbondingBegin": handleEventGatewayUnbondingBegin,
@@ -144,5 +146,4 @@ export const EventHandlers: Record<string, (events: Array<CosmosEvent>) => Promi
144146
"coinbase": noOp,
145147
"transfer": noOp,
146148
"burn": noOp,
147-
"poktroll.service.EventRelayMiningDifficultyUpdated": noOp,
148149
};

0 commit comments

Comments
 (0)