Skip to content

Commit 1227c73

Browse files
authored
Fixed handling of reason on unbonding events (#45)
Fixed handling of reason on unbonding events for Applications and Suppliers
1 parent b4cdad0 commit 1227c73

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/mappings/poktroll/applications.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ async function _handleApplicationUnbondingBeginEvent(
405405
) {
406406
const msg = event.msg as CosmosMessage<MsgUnstakeApplication>;
407407

408-
let unstakingEndHeight = BigInt(0), sessionEndHeight = BigInt(0), reason = 0;
408+
let unstakingEndHeight = BigInt(0), sessionEndHeight = BigInt(0), reason: number | null = null;
409409

410410
for (const attribute of event.event.attributes) {
411411
if (attribute.key === "unbonding_end_height") {
@@ -429,7 +429,7 @@ async function _handleApplicationUnbondingBeginEvent(
429429
throw new Error(`[handleApplicationUnbondingBeginEvent] sessionEndHeight not found in event`);
430430
}
431431

432-
if (!reason) {
432+
if (reason === null) {
433433
throw new Error(`[handleApplicationUnbondingBeginEvent] reason not found in event`);
434434
}
435435

@@ -462,7 +462,7 @@ async function _handleApplicationUnbondingBeginEvent(
462462
async function _handleApplicationUnbondingEndEvent(
463463
event: CosmosEvent,
464464
) {
465-
let unstakingEndHeight = BigInt(0), sessionEndHeight = BigInt(0), reason = 0,
465+
let unstakingEndHeight = BigInt(0), sessionEndHeight = BigInt(0), reason: number | null = null,
466466
applicationSdk: ApplicationSDKType | undefined;
467467

468468
for (const attribute of event.event.attributes) {
@@ -491,7 +491,7 @@ async function _handleApplicationUnbondingEndEvent(
491491
throw new Error(`[handleApplicationUnbondingEndEvent] sessionEndHeight not found in event`);
492492
}
493493

494-
if (!reason) {
494+
if (reason === null) {
495495
throw new Error(`[handleApplicationUnbondingEndEvent] reason not found in event`);
496496
}
497497

src/mappings/poktroll/suppliers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async function _handleSupplierUnbondingBeginEvent(
209209
"value":"\"55070\"","index":true
210210
},{"key":"mode","value":"EndBlock","index":true}]}
211211
*/
212-
let unbondingHeight: bigint | null = null, sessionEndHeight: bigint | null = null, supplierSdk: SupplierSDKType | null = null, reason = 0;
212+
let unbondingHeight: bigint | null = null, sessionEndHeight: bigint | null = null, supplierSdk: SupplierSDKType | null = null, reason: null | number = null;
213213

214214
for (const attribute of event.event.attributes) {
215215
if (attribute.key === "supplier") {
@@ -252,7 +252,7 @@ async function _handleSupplierUnbondingBeginEvent(
252252
supplier.unstakingEndHeight = unbondingHeight
253253
}
254254

255-
if (!reason) {
255+
if (reason === null) {
256256
// todo: we should do this -> throw new Error(`[handleSupplierUnbondingBeginEvent] reason not found in event`);
257257
// but alpha has still events without this
258258
logger.error(`[handleSupplierUnbondingBeginEvent] reason not found in event`);
@@ -270,7 +270,7 @@ async function _handleSupplierUnbondingBeginEvent(
270270
sessionEndHeight: sessionEndHeight || BigInt(0),
271271
supplierId: operatorAddress,
272272
blockId: getBlockId(event.block),
273-
reason: reason ? getSupplierUnbondingReasonFromSDK(reason) : SupplierUnbondingReason.UNSPECIFIED,
273+
reason: reason !== null ? getSupplierUnbondingReasonFromSDK(reason) : SupplierUnbondingReason.UNSPECIFIED,
274274
eventId,
275275
}).save(),
276276
]);
@@ -279,7 +279,7 @@ async function _handleSupplierUnbondingBeginEvent(
279279
async function _handleSupplierUnbondingEndEvent(
280280
event: CosmosEvent,
281281
) {
282-
let unbondingHeight: bigint | null = null, sessionEndHeight: bigint | null = null, supplierSdk: SupplierSDKType | null = null, reason = 0;
282+
let unbondingHeight: bigint | null = null, sessionEndHeight: bigint | null = null, supplierSdk: SupplierSDKType | null = null, reason: null | number = null;
283283

284284
for (const attribute of event.event.attributes) {
285285
if (attribute.key === "supplier") {
@@ -320,7 +320,7 @@ async function _handleSupplierUnbondingEndEvent(
320320
supplier.unstakingEndBlockId = unbondingHeight
321321
}
322322

323-
if (!reason) {
323+
if (reason === null) {
324324
// todo: we should do this -> throw new Error(`[handleSupplierUnbondingBeginEvent] reason not found in event`);
325325
// but alpha has still events without this
326326
logger.error(`[handleSupplierUnbondingEndEvent] reason not found in event`);
@@ -339,7 +339,7 @@ async function _handleSupplierUnbondingEndEvent(
339339
id: eventId,
340340
unbondingEndHeight: unbondingHeight || BigInt(0),
341341
sessionEndHeight: sessionEndHeight || BigInt(0),
342-
reason: reason ? getSupplierUnbondingReasonFromSDK(reason) : SupplierUnbondingReason.UNSPECIFIED,
342+
reason: reason !== null ? getSupplierUnbondingReasonFromSDK(reason) : SupplierUnbondingReason.UNSPECIFIED,
343343
blockId: getBlockId(event.block),
344344
supplierId: supplierSdk.operator_address,
345345
eventId,

0 commit comments

Comments
 (0)