Skip to content

Commit 8821cee

Browse files
authored
Refactored indexStakeEntity to only process successful data (#52)
## Summary * Refactored `indexStakeEntity` to only process successful data * Updated `updateMorseClaimableAccounts` to handle optional `publicKey` and new `morseAddress` field. ## Issue We were unintentionally handling data from failed transactions in `indexStakeEntity` causing errors. Also the update of the morse claimable supplier accounts were not working. ## Type of change Select one or more: - [ ] New feature, functionality or library - [X] Bug fix - [ ] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Sanity Checklist - [X] I have tested my changes using the available tooling - [X] I have commented my code - [X] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable
1 parent 3475b98 commit 8821cee

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)