-
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
10 changed files
with
826 additions
and
526 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
103 changes: 57 additions & 46 deletions
103
packages/engine/paima-funnel/src/cde/cardanoProjectedNFT.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 |
---|---|---|
@@ -1,58 +1,69 @@ | ||
import type { | ||
CdeCardanoProjectedNFTDatum, | ||
ChainDataExtensionCardanoProjectedNFT, | ||
ChainDataExtensionDatum, | ||
CdeCardanoProjectedNFTDatum, | ||
ChainDataExtensionCardanoProjectedNFT, | ||
ChainDataExtensionDatum, | ||
} from '@paima/sm'; | ||
import { ChainDataExtensionDatumType, DEFAULT_FUNNEL_TIMEOUT, timeout } from '@paima/utils'; | ||
import { Routes, query } from '@dcspark/carp-client/client/src'; | ||
import type { ProjectedNftRangeResponse } from "@dcspark/carp-client/shared/models/ProjectedNftRange"; | ||
import type { ProjectedNftRangeResponse } from '@dcspark/carp-client/shared/models/ProjectedNftRange'; | ||
|
||
export default async function getCdeProjectedNFTData( | ||
url: string, | ||
extension: ChainDataExtensionCardanoProjectedNFT, | ||
fromAbsoluteSlot: number, | ||
toAbsoluteSlot: number, | ||
getBlockNumber: (slot: number) => number | ||
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.actionSlot))).filter(e => e != null).map(e => e!!); | ||
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.actionSlot))) | ||
.filter(e => e != null) | ||
.map(e => e!!); | ||
} | ||
|
||
function eventToCdeDatum( | ||
event: ProjectedNftRangeResponse[0], | ||
extension: ChainDataExtensionCardanoProjectedNFT, | ||
blockNumber: number | ||
event: ProjectedNftRangeResponse[0], | ||
extension: ChainDataExtensionCardanoProjectedNFT, | ||
blockNumber: number | ||
): CdeCardanoProjectedNFTDatum | null { | ||
if (event.ownerAddress == null || event.actionTxId == null || event.status == null) { | ||
return null; | ||
} | ||
|
||
return { | ||
cdeId: extension.cdeId, | ||
cdeDatumType: ChainDataExtensionDatumType.CardanoProjectedNFT, | ||
blockNumber, | ||
payload: { | ||
ownerAddress: event.ownerAddress!!, | ||
|
||
actionTxId: event.actionTxId, | ||
actionOutputIndex: event.actionOutputIndex || undefined, | ||
|
||
previousTxHash: event.previousTxHash || undefined, | ||
previousTxOutputIndex: event.previousTxOutputIndex || undefined, | ||
|
||
asset: event.asset, | ||
amount: event.amount, | ||
status: event.status, | ||
plutusDatum: event.plutusDatum || "", | ||
|
||
forHowLong: event.forHowLong || undefined, | ||
}, | ||
scheduledPrefix: extension.scheduledPrefix, | ||
}; | ||
if ( | ||
event.ownerAddress === null || | ||
event.ownerAddress == '' || | ||
event.actionTxId === null || | ||
event.actionTxId == '' || | ||
event.status === null || | ||
event.actionTxId == '' | ||
) { | ||
return null; | ||
} | ||
|
||
return { | ||
cdeId: extension.cdeId, | ||
cdeDatumType: ChainDataExtensionDatumType.CardanoProjectedNFT, | ||
blockNumber, | ||
payload: { | ||
ownerAddress: event.ownerAddress != null ? event.ownerAddress : '', | ||
|
||
actionTxId: event.actionTxId, | ||
actionOutputIndex: event.actionOutputIndex != null ? event.actionOutputIndex : undefined, | ||
|
||
previousTxHash: event.previousTxHash != null ? event.previousTxHash : undefined, | ||
previousTxOutputIndex: | ||
event.previousTxOutputIndex != null ? event.previousTxOutputIndex : undefined, | ||
|
||
asset: event.asset, | ||
amount: event.amount, | ||
status: event.status, | ||
plutusDatum: event.plutusDatum != null ? event.plutusDatum : '', | ||
|
||
forHowLong: event.forHowLong != null ? event.forHowLong : undefined, | ||
}, | ||
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
113 changes: 59 additions & 54 deletions
113
packages/engine/paima-sm/src/cde-cardano-projected-nft.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 |
---|---|---|
@@ -1,64 +1,69 @@ | ||
import { ENV } from '@paima/utils'; | ||
import type { CdeCardanoProjectedNFTDatum } from './types'; | ||
import {createScheduledData, cdeCardanoProjectedNftInsertData, cdeCardanoProjectedNftUpdateData} from '@paima/db'; | ||
import { | ||
createScheduledData, | ||
cdeCardanoProjectedNftInsertData, | ||
cdeCardanoProjectedNftUpdateData, | ||
} 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 ownerAddress = cdeDatum.payload.ownerAddress; | ||
const previousTxHash = cdeDatum.payload.previousTxHash; | ||
const previousOutputIndex = cdeDatum.payload.previousTxOutputIndex; | ||
const currentTxHash = cdeDatum.payload.actionTxId; | ||
const currentOutputIndex = cdeDatum.payload.actionOutputIndex; | ||
const amount = cdeDatum.payload.amount; | ||
const asset = cdeDatum.payload.asset; | ||
const status = cdeDatum.payload.status; | ||
const datum = cdeDatum.payload.plutusDatum; | ||
const forHowLong = cdeDatum.payload.forHowLong; | ||
export default async function processDatum( | ||
cdeDatum: CdeCardanoProjectedNFTDatum | ||
): Promise<SQLUpdate[]> { | ||
const cdeId = cdeDatum.cdeId; | ||
const prefix = cdeDatum.scheduledPrefix; | ||
const ownerAddress = cdeDatum.payload.ownerAddress; | ||
const previousTxHash = cdeDatum.payload.previousTxHash; | ||
const previousOutputIndex = cdeDatum.payload.previousTxOutputIndex; | ||
const currentTxHash = cdeDatum.payload.actionTxId; | ||
const currentOutputIndex = cdeDatum.payload.actionOutputIndex; | ||
const amount = cdeDatum.payload.amount; | ||
const asset = cdeDatum.payload.asset; | ||
const status = cdeDatum.payload.status; | ||
const datum = cdeDatum.payload.plutusDatum; | ||
const forHowLong = cdeDatum.payload.forHowLong; | ||
|
||
const scheduledBlockHeight = Math.max(cdeDatum.blockNumber, ENV.SM_START_BLOCKHEIGHT + 1); | ||
const scheduledInputData = `${prefix}|${ownerAddress}|${previousTxHash}|${previousOutputIndex}|${currentTxHash}|${currentOutputIndex}|${status}`; | ||
const scheduledBlockHeight = Math.max(cdeDatum.blockNumber, ENV.SM_START_BLOCKHEIGHT + 1); | ||
const scheduledInputData = `${prefix}|${ownerAddress}|${previousTxHash}|${previousOutputIndex}|${currentTxHash}|${currentOutputIndex}|${asset}|${status}`; | ||
|
||
if (previousTxHash === undefined || previousOutputIndex === undefined) { | ||
const updateList: SQLUpdate[] = [ | ||
createScheduledData(scheduledInputData, scheduledBlockHeight), | ||
[ | ||
cdeCardanoProjectedNftInsertData, | ||
{ | ||
cde_id: cdeId, | ||
owner_address: ownerAddress, | ||
current_tx_hash: currentTxHash, | ||
current_tx_output_index: currentOutputIndex, | ||
asset: asset, | ||
amount: amount, | ||
status: status, | ||
plutus_datum: datum, | ||
for_how_long: forHowLong | ||
}, | ||
], | ||
]; | ||
return updateList; | ||
} | ||
if (previousTxHash === undefined || previousOutputIndex === undefined) { | ||
const updateList: SQLUpdate[] = [ | ||
createScheduledData(scheduledInputData, scheduledBlockHeight), | ||
[ | ||
cdeCardanoProjectedNftUpdateData, | ||
{ | ||
cde_id: cdeId, | ||
owner_address: ownerAddress, | ||
new_tx_hash: currentTxHash, | ||
new_tx_output_index: currentOutputIndex, | ||
previous_tx_hash: previousTxHash, | ||
previous_tx_output_index: previousOutputIndex, | ||
asset: asset, | ||
amount: amount, | ||
status: status, | ||
plutus_datum: datum, | ||
for_how_long: forHowLong | ||
}, | ||
], | ||
createScheduledData(scheduledInputData, scheduledBlockHeight), | ||
[ | ||
cdeCardanoProjectedNftInsertData, | ||
{ | ||
cde_id: cdeId, | ||
owner_address: ownerAddress, | ||
current_tx_hash: currentTxHash, | ||
current_tx_output_index: currentOutputIndex, | ||
asset: asset, | ||
amount: amount, | ||
status: status, | ||
plutus_datum: datum, | ||
for_how_long: forHowLong, | ||
}, | ||
], | ||
]; | ||
return updateList; | ||
|
||
} | ||
const updateList: SQLUpdate[] = [ | ||
createScheduledData(scheduledInputData, scheduledBlockHeight), | ||
[ | ||
cdeCardanoProjectedNftUpdateData, | ||
{ | ||
cde_id: cdeId, | ||
owner_address: ownerAddress, | ||
new_tx_hash: currentTxHash, | ||
new_tx_output_index: currentOutputIndex, | ||
previous_tx_hash: previousTxHash, | ||
previous_tx_output_index: previousOutputIndex, | ||
asset: asset, | ||
amount: amount, | ||
status: status, | ||
plutus_datum: datum, | ||
for_how_long: forHowLong, | ||
}, | ||
], | ||
]; | ||
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
Oops, something went wrong.