Skip to content

Commit

Permalink
expose cde utils get cardano delegation function
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Oct 31, 2023
1 parent a1831ef commit 9b76490
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/paima-sdk/paima-utils-backend/src/cde-access-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
cdeGenericGetRangeData,
cdeErc6551GetOwnedAccounts,
cdeErc6551GetOwner,
cdeCardanoPoolGetAddressDelegation,
} from '@paima/db';
import type { OwnedNftsResponse, GenericCdeDataUnit, TokenIdPair } from './types';

Expand Down Expand Up @@ -177,3 +178,15 @@ export async function internalGetAllOwnedErc6551Accounts(
);
return results.map(row => row.account_created);
}

export async function internalGetCardanoAddressDelegation(
readonlyDBConn: Pool,
address: string
): Promise<string | null> {
const results = await cdeCardanoPoolGetAddressDelegation.run({ address }, readonlyDBConn);
if (results.length === 0) {
return null;
}

return results[0].pool;
}
11 changes: 11 additions & 0 deletions packages/paima-sdk/paima-utils-backend/src/cde-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
internalGetGenericDataBlockheightRange,
internalGetErc6551AccountOwner,
internalGetAllOwnedErc6551Accounts,
internalGetCardanoAddressDelegation,
} from './cde-access-internals';
import type { OwnedNftsResponse, GenericCdeDataUnit, TokenIdPair } from './types';

Expand Down Expand Up @@ -156,3 +157,13 @@ export async function getAllOwnedErc6551Accounts(
if (cdeId === null) return [];
return await internalGetAllOwnedErc6551Accounts(readonlyDBConn, cdeId, nft);
}

/**
* Fetch the pool this address is delegating to, if any.
*/
export async function getCardanoAddressDelegation(
readonlyDBConn: Pool,
address: string
): Promise<string | null> {
return await internalGetCardanoAddressDelegation(readonlyDBConn, address);
}

0 comments on commit 9b76490

Please sign in to comment.