Skip to content

Commit 20c4955

Browse files
committed
Refactored indexStakeEntity only process successful data, and updated updateMorseClaimableAccounts to handle optional publicKey and new morseAddress field.
1 parent 3475b98 commit 20c4955

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/mappings/indexer.manager.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,26 @@ This function is used to call handlers in order to avoid updating the same entit
378378
for messages it is the path of the decodedMsg to get the entity id
379379
for events it is a function that receives the attributes and returns the entity id
380380
*/
381-
async function indexStakeEntity(data: Array<CosmosEvent | CosmosMessage>, getEntityIdArg: RecordGetId) {
381+
async function indexStakeEntity(allData: Array<CosmosEvent | CosmosMessage>, getEntityIdArg: RecordGetId) {
382+
const allEvents: Array<CosmosEvent> = [], allMsgs: Array<CosmosMessage> = [];
383+
384+
for (const datum of allData) {
385+
if ('event' in datum) {
386+
allEvents.push(datum)
387+
} else {
388+
allMsgs.push(datum)
389+
}
390+
}
391+
392+
const {success: successfulEvents} = filterEventsByTxStatus(allEvents)
393+
394+
const {success: successfulMsgs} = filterMsgByTxStatus(allMsgs)
395+
396+
const data = [
397+
...successfulEvents,
398+
...successfulMsgs,
399+
]
400+
382401
// this is to handle events where more than one stake entity is updated
383402
// like in _handleTransferApplicationEndEvent handler
384403
const entitiesUpdatedAtSameDatum: Array<Array<string>> = [];

src/mappings/pocket/migration.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ function _handleMsgClaimMorseAccount(
6565

6666
export async function updateMorseClaimableAccounts(
6767
items: Array<{
68-
publicKey: Uint8Array
68+
publicKey?: Uint8Array
69+
morseAddress?: string
6970
destinationAddress: string
7071
}>,
7172
): Promise<void> {
7273
const MorseClaimableAccountModel = getStoreModel("MorseClaimableAccount");
7374
const blockHeight = store.context.getHistoricalUnit();
7475

7576
await Promise.all(
76-
items.map(({ destinationAddress, publicKey }) => MorseClaimableAccountModel.model.update(
77+
items.map(({ destinationAddress, morseAddress, publicKey }) => MorseClaimableAccountModel.model.update(
7778
// mark as claimed
7879
{
7980
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -85,9 +86,9 @@ export async function updateMorseClaimableAccounts(
8586
{
8687
hooks: false,
8788
where: {
88-
id: pubKeyToAddress(
89+
id: morseAddress ? morseAddress : pubKeyToAddress(
8990
Ed25519,
90-
publicKey,
91+
publicKey!,
9192
undefined,
9293
true
9394
)

src/mappings/pocket/suppliers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export async function handleMsgClaimMorseSupplier(
484484
...messages.map(_handleMsgClaimMorseSupplier),
485485
updateMorseClaimableAccounts(
486486
messages.map((msg) => ({
487-
publicKey: msg.msg.decodedMsg.morsePublicKey,
487+
morseAddress: msg.msg.decodedMsg.morseNodeAddress,
488488
destinationAddress: msg.msg.decodedMsg.shannonOperatorAddress,
489489
}))
490490
)

0 commit comments

Comments
 (0)