Skip to content

Commit

Permalink
feat: 🎸 handle AccountAssetFrozen, AccountAssetUnfrozen
Browse files Browse the repository at this point in the history
Signed-off-by: Marcin Pastecki <marcin.pastecki@inndei.com>
  • Loading branch information
sansan authored and mpastecki committed Apr 18, 2024
1 parent 0fc2b71 commit 61b53a0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,7 @@ type ConfidentialAccount @entity {
account: String!
creator: Identity!
eventIdx: Int!
frozenForAsset: [String!]!
createdBlock: Block!
updatedBlock: Block!
}
Expand Down Expand Up @@ -2470,7 +2471,7 @@ type ConfidentialAsset @entity {
totalSupply: BigInt!
allowedVenues: [Int!]
venueFiltering: Boolean!
isFrozen: Boolean
isFrozen: Boolean!
eventIdx: Int!
createdBlock: Block!
updatedBlock: Block!
Expand Down
63 changes: 57 additions & 6 deletions src/mappings/entities/mapConfidentialAccountCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { ConfidentialAccount, EventIdEnum, ModuleIdEnum } from '../../types';
import { getTextValue } from '../util';
import { HandlerArgs } from './common';

export const mapConfidentialAccountCreated = async (args: HandlerArgs): Promise<void> => {
const { blockId, moduleId, eventId, params, eventIdx } = args;

if (moduleId !== ModuleIdEnum.confidentialasset || eventId !== EventIdEnum.AccountCreated) {
return;
}
const handleConfidentialAccountCreated = async (args: HandlerArgs): Promise<void> => {
const { blockId, params, eventIdx } = args;

const [rawCreator, rawAccount] = params;

Expand All @@ -19,7 +15,62 @@ export const mapConfidentialAccountCreated = async (args: HandlerArgs): Promise<
account,
creatorId: creator,
eventIdx,
frozenForAsset: [],
createdBlockId: blockId,
updatedBlockId: blockId,
}).save();
};

const handleConfidentialAssetFrozenForAccount = async (args: HandlerArgs): Promise<void> => {
const { blockId, params } = args;
const [, rawAccount, rawAsset] = params;

const accountId = getTextValue(rawAccount);
const assetId = getTextValue(rawAsset);

const account = await ConfidentialAccount.get(accountId);

if (account && !account.frozenForAsset.includes(assetId)) {
account.frozenForAsset = [...account.frozenForAsset, assetId];
account.updatedBlockId = blockId;

await account.save();
}
};

const handleConfidentialAssetUnfrozenForAccount = async (args: HandlerArgs): Promise<void> => {
const { blockId, params } = args;
const [, rawAccount, rawAsset] = params;

const accountId = getTextValue(rawAccount);
const assetId = getTextValue(rawAsset);

const account = await ConfidentialAccount.get(accountId);

if (account?.frozenForAsset.includes(assetId)) {
account.frozenForAsset = account.frozenForAsset.filter(id => id !== assetId);
account.updatedBlockId = blockId;

await account.save();
}
};

export const mapConfidentialAccountCreated = async (args: HandlerArgs): Promise<void> => {
const { moduleId, eventId } = args;

if (moduleId !== ModuleIdEnum.confidentialasset) {
return;
}

if (eventId === EventIdEnum.AccountCreated) {
handleConfidentialAccountCreated(args);
}

if (eventId === EventIdEnum.AccountAssetFrozen) {
await handleConfidentialAssetFrozenForAccount(args);
}

if (eventId === EventIdEnum.AccountAssetUnfrozen) {
await handleConfidentialAssetUnfrozenForAccount(args);
}
};
1 change: 1 addition & 0 deletions src/mappings/entities/mapConfidentialAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const handleConfidentialAssetCreated = async (
mediators,
totalSupply: BigInt(0),
venueFiltering: false,
isFrozen: false,
eventIdx,
createdBlockId: blockId,
updatedBlockId: blockId,
Expand Down

0 comments on commit 61b53a0

Please sign in to comment.