-
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
1 parent
b922ca9
commit 1b8c768
Showing
8 changed files
with
208 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type { | ||
CdeCardanoMintBurnDatum, | ||
CdeCardanoTransferDatum, | ||
ChainDataExtensionCardanoMintBurn, | ||
ChainDataExtensionCardanoTransfer, | ||
} from '@paima/sm'; | ||
import { ChainDataExtensionDatumType, DEFAULT_FUNNEL_TIMEOUT, timeout } from '@paima/utils'; | ||
import { Routes, query } from '@dcspark/carp-client/client/src'; | ||
import type { TxAndBlockInfo } from '@dcspark/carp-client/shared/models/TransactionHistory'; | ||
import { Transaction } from '@dcspark/cardano-multiplatform-lib-nodejs'; | ||
import { BlockTxPair } from '@dcspark/carp-client/shared/models/common'; | ||
import { MintBurnHistoryResponse } from 'tmp-carp-client/shared/models/MintBurn'; | ||
|
||
export default async function getCdeData( | ||
url: string, | ||
extension: ChainDataExtensionCardanoMintBurn, | ||
fromAbsoluteSlot: number, | ||
toAbsoluteSlot: number, | ||
getBlockNumber: (slot: number) => number, | ||
// if we are in the presync phase, we don't care about the slots since we | ||
// don't need to deterministically pair this with the evm blocks, so in this | ||
// case we only fetch one page and break. | ||
isPresync: boolean, | ||
untilBlock: string, | ||
// only should be used during the presync phase, to be able to resume from the | ||
// previous point | ||
fromTx: BlockTxPair | undefined, | ||
paginationLimit: number | ||
): Promise<CdeCardanoMintBurnDatum[]> { | ||
let result = [] as CdeCardanoMintBurnDatum[]; | ||
|
||
while (true) { | ||
const events = await timeout( | ||
query(url, Routes.mintBurnHistory, { | ||
policyIds: extension.policyIds, | ||
slotLimits: { | ||
from: fromAbsoluteSlot, | ||
to: toAbsoluteSlot, | ||
}, | ||
limit: paginationLimit, | ||
untilBlock, | ||
after: fromTx, | ||
}), | ||
DEFAULT_FUNNEL_TIMEOUT | ||
); | ||
|
||
if (events.length > 0) { | ||
const last = events[events.length - 1]; | ||
|
||
fromTx = { | ||
tx: last.txId, | ||
block: last.block, | ||
}; | ||
} | ||
|
||
events | ||
.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.actionSlot))) | ||
.forEach(element => { | ||
result.push(element); | ||
}); | ||
|
||
if (events.length === 0 || isPresync) { | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function eventToCdeDatum( | ||
event: MintBurnHistoryResponse[0], | ||
extension: ChainDataExtensionCardanoMintBurn, | ||
blockNumber: number | ||
): CdeCardanoMintBurnDatum { | ||
const cursor: BlockTxPair = { | ||
block: event.block, | ||
tx: event.txId, | ||
}; | ||
|
||
return { | ||
cdeId: extension.cdeId, | ||
cdeDatumType: ChainDataExtensionDatumType.CardanoMintBurn, | ||
blockNumber, | ||
payload: { | ||
txId: event.txId, | ||
metadata: event.metadata, | ||
assets: event.assets, | ||
}, | ||
scheduledPrefix: extension.scheduledPrefix, | ||
paginationCursor: { cursor: JSON.stringify(cursor), finished: false }, | ||
}; | ||
} |
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,21 @@ | ||
import { ENV } from '@paima/utils'; | ||
import { createScheduledData } from '@paima/db'; | ||
import type { SQLUpdate } from '@paima/db'; | ||
import type { CdeCardanoMintBurnDatum } from './types.js'; | ||
|
||
export default async function processDatum( | ||
cdeDatum: CdeCardanoMintBurnDatum | ||
): Promise<SQLUpdate[]> { | ||
const cdeId = cdeDatum.cdeId; | ||
const prefix = cdeDatum.scheduledPrefix; | ||
const txId = cdeDatum.payload.txId; | ||
const assets = JSON.stringify(cdeDatum.payload.assets); | ||
const metadata = cdeDatum.payload.metadata || undefined; | ||
|
||
const scheduledBlockHeight = Math.max(cdeDatum.blockNumber, ENV.SM_START_BLOCKHEIGHT + 1); | ||
const scheduledInputData = `${prefix}|${txId}|${metadata}|${assets}`; | ||
|
||
// TODO: do we really need to always store something in the db? In this case I'm not sure what would be queried. | ||
const updateList: SQLUpdate[] = [createScheduledData(scheduledInputData, scheduledBlockHeight)]; | ||
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