-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Projected NFT funnel #259
Projected NFT funnel #259
Changes from 20 commits
09ece57
f30d983
a8f417c
91ba6a5
3788338
96d9449
db32958
acb7964
abd7a38
8972ee0
73d76e0
0248309
1befbef
c00f752
97e3cd5
cf5a740
13f4962
c63fe7c
627d81c
965c624
38e41d8
7197527
f0b3492
d6dbcff
1dc2c32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,7 @@ bin | |
|
||
# logs | ||
*.log | ||
|
||
.idea/ | ||
|
||
packages/engine/paima-rest/src/tsoa/routes.ts | ||
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { | ||
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'; | ||
|
||
export default async function getCdeProjectedNFTData( | ||
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 }, | ||
}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this handle pagination properly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, as long as the range is not too big it will work fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and the request is not split to pages |
||
DEFAULT_FUNNEL_TIMEOUT | ||
); | ||
|
||
return events | ||
.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.actionSlot))) | ||
.filter(e => e != null) | ||
.map(e => e!); | ||
ecioppettini marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
function eventToCdeDatum( | ||
event: ProjectedNftRangeResponse[0], | ||
extension: ChainDataExtensionCardanoProjectedNFT, | ||
blockNumber: number | ||
): CdeCardanoProjectedNFTDatum | null { | ||
if ( | ||
event.actionTxId === null || | ||
event.actionTxId == '' || | ||
event.status === null || | ||
event.status == '' | ||
) { | ||
return null; | ||
} | ||
|
||
return { | ||
cdeId: extension.cdeId, | ||
cdeDatumType: ChainDataExtensionDatumType.CardanoProjectedNFT, | ||
blockNumber, | ||
payload: { | ||
ownerAddress: event.ownerAddress != null ? event.ownerAddress : '', | ||
|
||
actionTxId: event.actionTxId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that games only care about NFTs getting locked and queued to unlock. We don't care if the user ever actually ends up withdrawing their NFT from the lock later. |
||
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, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { ENV } from '@paima/utils'; | ||
import type { CdeCardanoProjectedNFTDatum } from './types.js'; | ||
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; | ||
|
||
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; | ||
} | ||
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't add this to gitingore I think because it will break some other systems that require parsing this file. The real solution would be trying to find out why this file sometimes gets formatted by a tool (possibly prettier) despite being specified in the
.prettierignore
. Runningprettier
on the git repo as expected ignores this file, but it's possiblenx
or some other tool is not respecting this somewhereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but how git relates to these systems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just a file that is not tracked by the repo if it is ignored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would it break anything? otherwise one should always specify all subfolders or do
git rm
on this file which is not very convenient. if we don't need a file in a repo it's better to ignore it imo if it doesn't break thingsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many systems and tools look at git for their behavior. Please let's not waste time arguing about this and just do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed on the call i added back this file since it was not tracked by git and removed it from gitignore