-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
996 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ bin | |
|
||
# logs | ||
*.log | ||
|
||
.idea/ |
Large diffs are not rendered by default.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
packages/engine/paima-funnel/src/cde/caranoProjectedNFT.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ChainDataExtensionDatumType, DEFAULT_FUNNEL_TIMEOUT, timeout } from '@paima/utils'; | ||
import type { | ||
CdeCardanoProjectedNFTDatum, | ||
ChainDataExtensionCardanoProjectedNFT, | ||
ChainDataExtensionDatum, | ||
} from '@paima/runtime'; | ||
import { Routes, query } from '@dcspark/carp-client/client/src'; | ||
import {ProjectedNftRangeResponse} from "@dcspark/carp-client/shared/models/ProjectedNftRange"; | ||
|
||
export default async function getCdeData( | ||
url: string, | ||
extension: ChainDataExtensionCardanoProjectedNFT, | ||
fromAbsoluteSlot: number, | ||
toAbsoluteSlot: number, | ||
getBlockNumber: (slot: number) => number | ||
): Promise<ChainDataExtensionDatum[]> { | ||
const events = await timeout( | ||
query(url, Routes.projectedNftEventsRange, { | ||
range: { minSlot: fromAbsoluteSlot, maxSlot: toAbsoluteSlot }, | ||
}), | ||
DEFAULT_FUNNEL_TIMEOUT | ||
); | ||
|
||
return events.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.slot))); | ||
} | ||
|
||
function eventToCdeDatum( | ||
event: ProjectedNftRangeResponse[0], | ||
extension: ChainDataExtensionCardanoProjectedNFT, | ||
blockNumber: number | ||
): CdeCardanoProjectedNFTDatum { | ||
return { | ||
cdeId: extension.cdeId, | ||
cdeDatumType: ChainDataExtensionDatumType.CardanoProjectedNFT, | ||
blockNumber, | ||
payload: { | ||
address: event.address, | ||
asset: event.asset, | ||
amount: event.amount, | ||
status: event.status, | ||
plutusDatum: event.plutusDatum, | ||
}, | ||
scheduledPrefix: extension.scheduledPrefix, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ENV } from '@paima/utils'; | ||
import type { CdeCardanoProjectedNFTDatum } from '@paima/runtime'; | ||
import { createScheduledData, cdeCardanoProjectedNftInsertData } from '@paima/db'; | ||
import type { SQLUpdate } from '@paima/db'; | ||
|
||
export default async function processDatum(cdeDatum: CdeCardanoProjectedNFTDatum): Promise<SQLUpdate[]> { | ||
const cdeId = cdeDatum.cdeId; | ||
const prefix = cdeDatum.scheduledPrefix; | ||
const address = cdeDatum.payload.address; | ||
const amount = cdeDatum.payload.amount; | ||
const asset = cdeDatum.payload.asset; | ||
const status = cdeDatum.payload.status; | ||
const datum = cdeDatum.payload.plutusDatum; | ||
|
||
const scheduledBlockHeight = Math.max(cdeDatum.blockNumber, ENV.SM_START_BLOCKHEIGHT + 1); | ||
const scheduledInputData = `${prefix}|${address}|${asset}|${amount}|${status}|${datum}`; | ||
|
||
const updateList: SQLUpdate[] = [ | ||
createScheduledData(scheduledInputData, scheduledBlockHeight), | ||
[ | ||
cdeCardanoProjectedNftInsertData, | ||
{ | ||
cde_id: cdeId, | ||
address: cdeDatum.payload.address, | ||
asset: cdeDatum.payload.asset, | ||
amount: cdeDatum.payload.amount, | ||
status: cdeDatum.payload.status, | ||
datum: cdeDatum.payload.plutusDatum | ||
}, | ||
], | ||
]; | ||
return updateList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/node-sdk/paima-db/src/sql/cde-cardano-projected-nft.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* @name cdeCardanoGetProjectedNft */ | ||
SELECT * FROM cde_cardano_projected_nft | ||
WHERE address = :address!; | ||
|
||
/* @name cdeCardanoProjectedNftInsertData */ | ||
INSERT INTO cde_cardano_pool_delegation( | ||
cde_id, | ||
address, | ||
asset, | ||
amount, | ||
status, | ||
datum, | ||
) VALUES ( | ||
:cde_id!, | ||
:address!, | ||
:asset! | ||
:amount! | ||
:status! | ||
:datum! | ||
) ON CONFLICT (cde_id, address) DO | ||
UPDATE SET pool = :pool!; | ||
|
||
cde_id: cdeId, | ||
address: cdeDatum.payload.address, | ||
asset: cdeDatum.payload.asset, | ||
amount: cdeDatum.payload.amount, | ||
status: cdeDatum.payload.status, | ||
datum: cdeDatum.payload.plutusDatum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.