Skip to content

Commit a0933fa

Browse files
committed
Handle missing stake in MsgStakeSupplier by fetching the previous stake and adding error handling for missing data.
1 parent 76d3d60 commit a0933fa

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/mappings/pocket/suppliers.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,27 @@ function _handleSupplierStakeMsg(
488488
services: Array<SupplierServiceConfigProps>,
489489
servicesToRemove: Array<string>,
490490
} {
491-
if (!msg.msg.decodedMsg.stake) {
491+
// the MsgStakeSupplier can come without the stake field, so we need to get the previous stake
492+
let stake = msg.msg.decodedMsg.stake;
493+
494+
if (!stake) {
495+
const previousSupplier = record[msg.msg.decodedMsg.operatorAddress]?.supplier;
496+
497+
if (!previousSupplier) {
498+
throw new Error(`[handleSupplierStakeMsg] previous supplier not found for operator address ${msg.msg.decodedMsg.operatorAddress}`);
499+
}
500+
501+
stake = {
502+
amount: previousSupplier.stakeAmount.toString(),
503+
denom: previousSupplier.stakeDenom,
504+
}
505+
}
506+
507+
if (!stake) {
492508
throw new Error(`[handleSupplierStakeMsg] stake not provided in msg`);
493509
}
494510

495-
const {operatorAddress, ownerAddress, services: rawServices, signer, stake} = msg.msg.decodedMsg;
511+
const {operatorAddress, ownerAddress, services: rawServices, signer} = msg.msg.decodedMsg;
496512

497513
const msgId = messageId(msg);
498514

0 commit comments

Comments
 (0)