Skip to content

Commit

Permalink
Merge pull request #274 from PaimaStudios/egostkin/projected-nft-spli…
Browse files Browse the repository at this point in the history
…t-asset

Make policy id and asset name separate
  • Loading branch information
gostkin authored Dec 21, 2023
2 parents d6dbcff + 7197527 commit 1dc2c32
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
4 changes: 3 additions & 1 deletion packages/engine/paima-funnel/src/cde/cardanoProjectedNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default async function getCdeProjectedNFTData(
const events = await timeout(
query(url, Routes.projectedNftEventsRange, {
range: { minSlot: fromAbsoluteSlot, maxSlot: toAbsoluteSlot },
address: undefined,
}),
DEFAULT_FUNNEL_TIMEOUT
);
Expand Down Expand Up @@ -55,7 +56,8 @@ function eventToCdeDatum(
previousTxOutputIndex:
event.previousTxOutputIndex != null ? event.previousTxOutputIndex : undefined,

asset: event.asset,
policyId: event.policyId,
assetName: event.assetName,
amount: event.amount,
status: event.status,
plutusDatum: event.plutusDatum != null ? event.plutusDatum : '',
Expand Down
11 changes: 7 additions & 4 deletions packages/engine/paima-sm/src/cde-cardano-projected-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ export default async function processDatum(
const currentTxHash = cdeDatum.payload.actionTxId;
const currentOutputIndex = cdeDatum.payload.actionOutputIndex;
const amount = cdeDatum.payload.amount;
const asset = cdeDatum.payload.asset;
const policyId = cdeDatum.payload.policyId;
const assetName = cdeDatum.payload.assetName;
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}`;
const scheduledInputData = `${prefix}|${ownerAddress}|${previousTxHash}|${previousOutputIndex}|${currentTxHash}|${currentOutputIndex}|${policyId}|${assetName}|${status}`;

if (previousTxHash === undefined || previousOutputIndex === undefined) {
const updateList: SQLUpdate[] = [
Expand All @@ -36,7 +37,8 @@ export default async function processDatum(
owner_address: ownerAddress,
current_tx_hash: currentTxHash,
current_tx_output_index: currentOutputIndex,
asset: asset,
policy_id: policyId,
asset_name: assetName,
amount: amount,
status: status,
plutus_datum: datum,
Expand All @@ -57,7 +59,8 @@ export default async function processDatum(
new_tx_output_index: currentOutputIndex,
previous_tx_hash: previousTxHash,
previous_tx_output_index: previousOutputIndex,
asset: asset,
policy_id: policyId,
asset_name: assetName,
amount: amount,
status: status,
plutus_datum: datum,
Expand Down
3 changes: 2 additions & 1 deletion packages/engine/paima-sm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ interface CdeDatumCardanoProjectedNFTPayload {
previousTxHash: string | undefined;
previousTxOutputIndex: number | undefined;

asset: string;
policyId: string;
assetName: string;
amount: string;
status: string;
plutusDatum: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/node-sdk/paima-db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Specific game databases do not need to contain these tables, as they will be cre

To re-generate the queries, you will need a database running with the same connection info as [the config](./pgtypedconfig.json) and then run `npm run compile`.

Before running `npm compile`, you will need to initialize the DB using `sudo -u postgres psql -d postgres -a -f migrations/up.sql`
Before running `npm run compile`, you will need to initialize the DB using `sudo -u postgres psql -d postgres -a -f migrations/up.sql`
3 changes: 2 additions & 1 deletion packages/node-sdk/paima-db/migrations/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ CREATE TABLE cde_cardano_projected_nft (
previous_tx_output_index INTEGER,
current_tx_hash TEXT NOT NULL,
current_tx_output_index INTEGER,
asset TEXT NOT NULL,
policy_id TEXT NOT NULL,
asset_name TEXT NOT NULL,
amount BIGINT NOT NULL,
status TEXT NOT NULL,
plutus_datum TEXT NOT NULL,
Expand Down
8 changes: 5 additions & 3 deletions packages/node-sdk/paima-db/src/paima-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ CREATE TABLE cde_cardano_projected_nft (
previous_tx_output_index INTEGER,
current_tx_hash TEXT NOT NULL,
current_tx_output_index INTEGER,
asset TEXT NOT NULL,
policy_id TEXT NOT NULL,
asset_name TEXT NOT NULL,
amount BIGINT NOT NULL,
status TEXT NOT NULL,
plutus_datum TEXT NOT NULL,
Expand All @@ -306,11 +307,12 @@ const TABLE_DATA_CDE_CARDANO_PROJECTED_NFT: TableData = {
['previous_tx_output_index', 'integer', 'YES', ''],
['current_tx_hash', 'text', 'NO', ''],
['current_tx_output_index', 'integer', 'YES', ''],
['asset', 'text', 'NO', ''],
['policy_id', 'text', 'NO', ''],
['asset_name', 'text', 'NO', ''],
['amount', 'bigint', 'NO', ''],
['status', 'text', 'NO', ''],
['plutus_datum', 'text', 'NO', ''],
['for_how_long', 'bigint', 'NO', ''],
['for_how_long', 'bigint', 'YES', ''],
]),
serialColumns: ['id'],
creationQuery: QUERY_CREATE_TABLE_CDE_CARDANO_PROJECTED_NFT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export interface ICdeCardanoGetProjectedNftParams {
/** 'CdeCardanoGetProjectedNft' return type */
export interface ICdeCardanoGetProjectedNftResult {
amount: string;
asset: string;
asset_name: string;
cde_id: number;
current_tx_hash: string;
current_tx_output_index: number | null;
for_how_long: string | null;
id: number;
owner_address: string;
plutus_datum: string;
policy_id: string;
previous_tx_hash: string | null;
previous_tx_output_index: number | null;
status: string;
Expand All @@ -45,13 +46,14 @@ export const cdeCardanoGetProjectedNft = new PreparedQuery<ICdeCardanoGetProject
/** 'CdeCardanoProjectedNftInsertData' parameters type */
export interface ICdeCardanoProjectedNftInsertDataParams {
amount: NumberOrString;
asset: string;
asset_name: string;
cde_id: number;
current_tx_hash: string;
current_tx_output_index: number;
for_how_long: NumberOrString;
owner_address: string;
plutus_datum: string;
policy_id: string;
status: string;
}

Expand All @@ -64,7 +66,7 @@ export interface ICdeCardanoProjectedNftInsertDataQuery {
result: ICdeCardanoProjectedNftInsertDataResult;
}

const cdeCardanoProjectedNftInsertDataIR: any = {"usedParamSet":{"cde_id":true,"owner_address":true,"current_tx_hash":true,"current_tx_output_index":true,"asset":true,"amount":true,"status":true,"plutus_datum":true,"for_how_long":true},"params":[{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":214,"b":221}]},{"name":"owner_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":237,"b":251}]},{"name":"current_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":267,"b":283}]},{"name":"current_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":299,"b":323}]},{"name":"asset","required":true,"transform":{"type":"scalar"},"locs":[{"a":339,"b":345}]},{"name":"amount","required":true,"transform":{"type":"scalar"},"locs":[{"a":361,"b":368}]},{"name":"status","required":true,"transform":{"type":"scalar"},"locs":[{"a":384,"b":391}]},{"name":"plutus_datum","required":true,"transform":{"type":"scalar"},"locs":[{"a":407,"b":420}]},{"name":"for_how_long","required":true,"transform":{"type":"scalar"},"locs":[{"a":436,"b":449}]}],"statement":"INSERT INTO cde_cardano_projected_nft(\n cde_id,\n owner_address,\n current_tx_hash,\n current_tx_output_index,\n asset,\n amount,\n status,\n plutus_datum,\n for_how_long\n) VALUES (\n :cde_id!,\n :owner_address!,\n :current_tx_hash!,\n :current_tx_output_index!,\n :asset!,\n :amount!,\n :status!,\n :plutus_datum!,\n :for_how_long!\n )"};
const cdeCardanoProjectedNftInsertDataIR: any = {"usedParamSet":{"cde_id":true,"owner_address":true,"current_tx_hash":true,"current_tx_output_index":true,"policy_id":true,"asset_name":true,"amount":true,"status":true,"plutus_datum":true,"for_how_long":true},"params":[{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":234,"b":241}]},{"name":"owner_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":257,"b":271}]},{"name":"current_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":287,"b":303}]},{"name":"current_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":319,"b":343}]},{"name":"policy_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":359,"b":369}]},{"name":"asset_name","required":true,"transform":{"type":"scalar"},"locs":[{"a":385,"b":396}]},{"name":"amount","required":true,"transform":{"type":"scalar"},"locs":[{"a":412,"b":419}]},{"name":"status","required":true,"transform":{"type":"scalar"},"locs":[{"a":435,"b":442}]},{"name":"plutus_datum","required":true,"transform":{"type":"scalar"},"locs":[{"a":458,"b":471}]},{"name":"for_how_long","required":true,"transform":{"type":"scalar"},"locs":[{"a":487,"b":500}]}],"statement":"INSERT INTO cde_cardano_projected_nft(\n cde_id,\n owner_address,\n current_tx_hash,\n current_tx_output_index,\n policy_id,\n asset_name,\n amount,\n status,\n plutus_datum,\n for_how_long\n) VALUES (\n :cde_id!,\n :owner_address!,\n :current_tx_hash!,\n :current_tx_output_index!,\n :policy_id!,\n :asset_name!,\n :amount!,\n :status!,\n :plutus_datum!,\n :for_how_long!\n )"};

/**
* Query generated from SQL:
Expand All @@ -74,7 +76,8 @@ const cdeCardanoProjectedNftInsertDataIR: any = {"usedParamSet":{"cde_id":true,"
* owner_address,
* current_tx_hash,
* current_tx_output_index,
* asset,
* policy_id,
* asset_name,
* amount,
* status,
* plutus_datum,
Expand All @@ -84,7 +87,8 @@ const cdeCardanoProjectedNftInsertDataIR: any = {"usedParamSet":{"cde_id":true,"
* :owner_address!,
* :current_tx_hash!,
* :current_tx_output_index!,
* :asset!,
* :policy_id!,
* :asset_name!,
* :amount!,
* :status!,
* :plutus_datum!,
Expand All @@ -98,13 +102,14 @@ export const cdeCardanoProjectedNftInsertData = new PreparedQuery<ICdeCardanoPro
/** 'CdeCardanoProjectedNftUpdateData' parameters type */
export interface ICdeCardanoProjectedNftUpdateDataParams {
amount: NumberOrString;
asset: string;
asset_name: string;
cde_id: number;
for_how_long: NumberOrString;
new_tx_hash: string;
new_tx_output_index: number;
owner_address: string;
plutus_datum: string;
policy_id: string;
previous_tx_hash: string;
previous_tx_output_index: number;
status: string;
Expand All @@ -122,7 +127,7 @@ export interface ICdeCardanoProjectedNftUpdateDataQuery {
result: ICdeCardanoProjectedNftUpdateDataResult;
}

const cdeCardanoProjectedNftUpdateDataIR: any = {"usedParamSet":{"owner_address":true,"previous_tx_hash":true,"previous_tx_output_index":true,"new_tx_hash":true,"new_tx_output_index":true,"status":true,"plutus_datum":true,"for_how_long":true,"cde_id":true,"asset":true,"amount":true},"params":[{"name":"owner_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":57,"b":71}]},{"name":"previous_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":97,"b":114},{"a":412,"b":429}]},{"name":"previous_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":148,"b":173},{"a":465,"b":490}]},{"name":"new_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":198,"b":210}]},{"name":"new_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":243,"b":263}]},{"name":"status","required":true,"transform":{"type":"scalar"},"locs":[{"a":279,"b":286}]},{"name":"plutus_datum","required":true,"transform":{"type":"scalar"},"locs":[{"a":308,"b":321}]},{"name":"for_how_long","required":true,"transform":{"type":"scalar"},"locs":[{"a":343,"b":356}]},{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":377,"b":384}]},{"name":"asset","required":true,"transform":{"type":"scalar"},"locs":[{"a":508,"b":514}]},{"name":"amount","required":true,"transform":{"type":"scalar"},"locs":[{"a":533,"b":540}]}],"statement":"UPDATE cde_cardano_projected_nft\nSET\n owner_address = :owner_address!,\n previous_tx_hash = :previous_tx_hash!,\n previous_tx_output_index = :previous_tx_output_index!,\n current_tx_hash = :new_tx_hash!,\n current_tx_output_index = :new_tx_output_index!,\n status = :status!,\n plutus_datum = :plutus_datum!,\n for_how_long = :for_how_long!\nWHERE\n cde_id = :cde_id!\n AND current_tx_hash = :previous_tx_hash!\n AND current_tx_output_index = :previous_tx_output_index!\n AND asset = :asset!\n AND amount = :amount!\nRETURNING previous_tx_hash, previous_tx_output_index"};
const cdeCardanoProjectedNftUpdateDataIR: any = {"usedParamSet":{"owner_address":true,"previous_tx_hash":true,"previous_tx_output_index":true,"new_tx_hash":true,"new_tx_output_index":true,"status":true,"plutus_datum":true,"for_how_long":true,"cde_id":true,"policy_id":true,"asset_name":true,"amount":true},"params":[{"name":"owner_address","required":true,"transform":{"type":"scalar"},"locs":[{"a":57,"b":71}]},{"name":"previous_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":97,"b":114},{"a":412,"b":429}]},{"name":"previous_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":148,"b":173},{"a":465,"b":490}]},{"name":"new_tx_hash","required":true,"transform":{"type":"scalar"},"locs":[{"a":198,"b":210}]},{"name":"new_tx_output_index","required":true,"transform":{"type":"scalar"},"locs":[{"a":243,"b":263}]},{"name":"status","required":true,"transform":{"type":"scalar"},"locs":[{"a":279,"b":286}]},{"name":"plutus_datum","required":true,"transform":{"type":"scalar"},"locs":[{"a":308,"b":321}]},{"name":"for_how_long","required":true,"transform":{"type":"scalar"},"locs":[{"a":343,"b":356}]},{"name":"cde_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":377,"b":384}]},{"name":"policy_id","required":true,"transform":{"type":"scalar"},"locs":[{"a":512,"b":522}]},{"name":"asset_name","required":true,"transform":{"type":"scalar"},"locs":[{"a":545,"b":556}]},{"name":"amount","required":true,"transform":{"type":"scalar"},"locs":[{"a":575,"b":582}]}],"statement":"UPDATE cde_cardano_projected_nft\nSET\n owner_address = :owner_address!,\n previous_tx_hash = :previous_tx_hash!,\n previous_tx_output_index = :previous_tx_output_index!,\n current_tx_hash = :new_tx_hash!,\n current_tx_output_index = :new_tx_output_index!,\n status = :status!,\n plutus_datum = :plutus_datum!,\n for_how_long = :for_how_long!\nWHERE\n cde_id = :cde_id!\n AND current_tx_hash = :previous_tx_hash!\n AND current_tx_output_index = :previous_tx_output_index!\n AND policy_id = :policy_id!\n AND asset_name = :asset_name!\n AND amount = :amount!\nRETURNING previous_tx_hash, previous_tx_output_index"};

/**
* Query generated from SQL:
Expand All @@ -141,7 +146,8 @@ const cdeCardanoProjectedNftUpdateDataIR: any = {"usedParamSet":{"owner_address"
* cde_id = :cde_id!
* AND current_tx_hash = :previous_tx_hash!
* AND current_tx_output_index = :previous_tx_output_index!
* AND asset = :asset!
* AND policy_id = :policy_id!
* AND asset_name = :asset_name!
* AND amount = :amount!
* RETURNING previous_tx_hash, previous_tx_output_index
* ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ INSERT INTO cde_cardano_projected_nft(
owner_address,
current_tx_hash,
current_tx_output_index,
asset,
policy_id,
asset_name,
amount,
status,
plutus_datum,
Expand All @@ -18,7 +19,8 @@ INSERT INTO cde_cardano_projected_nft(
:owner_address!,
:current_tx_hash!,
:current_tx_output_index!,
:asset!,
:policy_id!,
:asset_name!,
:amount!,
:status!,
:plutus_datum!,
Expand All @@ -40,6 +42,7 @@ WHERE
cde_id = :cde_id!
AND current_tx_hash = :previous_tx_hash!
AND current_tx_output_index = :previous_tx_output_index!
AND asset = :asset!
AND policy_id = :policy_id!
AND asset_name = :asset_name!
AND amount = :amount!
RETURNING previous_tx_hash, previous_tx_output_index;

0 comments on commit 1dc2c32

Please sign in to comment.