Skip to content

Commit

Permalink
return two delegation entries only when current is current epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Dec 13, 2023
1 parent f3b3ff0 commit 1526bb7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/node-sdk/paima-utils-backend/src/cde-access-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,18 @@ export async function internalGetCardanoAddressDelegation(
throw new Error('Current epoch table not initialized');
}

return {
currentEpoch: currentEpoch[0].epoch,
events: results.map(r => {
return { pool: r.pool, epoch: r.epoch };
}),
};
if (currentEpoch[0].epoch === results[results.length - 1].epoch) {
return {
currentEpoch: currentEpoch[0].epoch,
events: results.map(r => {
return { pool: r.pool, epoch: r.epoch };
}),
};
} else {
const result = results[results.length - 1];
return {
currentEpoch: currentEpoch[0].epoch,
events: [{ pool: result.pool, epoch: result.epoch }],
};
}
}
5 changes: 5 additions & 0 deletions packages/node-sdk/paima-utils-backend/src/cde-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ export async function getAllOwnedErc6551Accounts(

/**
* Fetch the pool this address is delegating to, if any.
*
* If the last delegation indexed for this address happened during the current
* epoch, this returns both the current delegation and the previous entry.
*
* Otherwise, this will just return a single entry.
*/
export async function getCardanoAddressDelegation(
readonlyDBConn: Pool,
Expand Down

0 comments on commit 1526bb7

Please sign in to comment.