Skip to content

Commit

Permalink
chore: 🤖 modify queries to work with SQ historical state
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantasdeveloper committed Jul 30, 2024
1 parent dcc13a3 commit d0de49c
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 234 deletions.
8 changes: 2 additions & 6 deletions src/api/client/__tests__/Claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,7 @@ describe('Claims Class', () => {
{
id: '1',
name: 'Some Claim Type',
identity: {
did,
},
identityId: did,
},
],
totalCount: 1,
Expand Down Expand Up @@ -905,9 +903,7 @@ describe('Claims Class', () => {
{
id: '1',
name: 'Some Claim Type',
identity: {
did,
},
identityId: did,
},
],
totalCount: 1,
Expand Down
38 changes: 22 additions & 16 deletions src/api/entities/Asset/Fungible/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
balanceToBigNumber,
middlewareEventDetailsToEventIdentifier,
middlewarePortfolioToPortfolio,
portfolioIdStringToPortfolio,
stringToTicker,
tickerToDid,
} from '~/utils/conversion';
Expand Down Expand Up @@ -197,29 +198,34 @@ export class FungibleAsset extends BaseAsset {
({
assetId,
amount,
fromPortfolio,
toPortfolio,
fromPortfolioId,
toPortfolioId,
createdBlock,
eventId,
eventIdx,
extrinsicIdx,
fundingRound,
instructionId,
instructionMemo,
}) => ({
asset: new FungibleAsset({ ticker: assetId }, context),
amount: new BigNumber(amount).shiftedBy(-6),
event: eventId,
from: optionize(middlewarePortfolioToPortfolio)(fromPortfolio, context),
to: optionize(middlewarePortfolioToPortfolio)(toPortfolio, context),
fundingRound,
instructionId: instructionId ? new BigNumber(instructionId) : undefined,
instructionMemo,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
extrinsicIndex: new BigNumber(extrinsicIdx!),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...middlewareEventDetailsToEventIdentifier(createdBlock!, eventIdx),
})
}) => {
const fromPortfolio = optionize(portfolioIdStringToPortfolio)(fromPortfolioId);
const toPortfolio = optionize(portfolioIdStringToPortfolio)(toPortfolioId);

return {
asset: new FungibleAsset({ ticker: assetId }, context),
amount: new BigNumber(amount).shiftedBy(-6),
event: eventId,
from: optionize(middlewarePortfolioToPortfolio)(fromPortfolio, context),
to: optionize(middlewarePortfolioToPortfolio)(toPortfolio, context),
fundingRound,
instructionId: instructionId ? new BigNumber(instructionId) : undefined,
instructionMemo,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
extrinsicIndex: new BigNumber(extrinsicIdx!),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...middlewareEventDetailsToEventIdentifier(createdBlock!, eventIdx),
};
}
);

const count = new BigNumber(totalCount);
Expand Down
46 changes: 26 additions & 20 deletions src/api/entities/Asset/NonFungible/NftCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
PolymeshError,
transferAssetOwnership,
} from '~/internal';
import { assetQuery, nftTransactionQuery } from '~/middleware/queries/assets';
import { assetQuery, assetTransactionQuery } from '~/middleware/queries/assets';
import { Query } from '~/middleware/types';
import {
AssetDetails,
Expand All @@ -36,6 +36,7 @@ import {
meshMetadataKeyToMetadataKey,
middlewareEventDetailsToEventIdentifier,
middlewarePortfolioToPortfolio,
portfolioIdStringToPortfolio,
stringToTicker,
u64ToBigNumber,
} from '~/utils/conversion';
Expand Down Expand Up @@ -324,7 +325,7 @@ export class NftCollection extends BaseAsset {
assetTransactions: { nodes, totalCount },
},
} = await context.queryMiddleware<Ensured<Query, 'assetTransactions'>>(
nftTransactionQuery(
assetTransactionQuery(
{
assetId: ticker,
},
Expand All @@ -337,31 +338,36 @@ export class NftCollection extends BaseAsset {
({
assetId,
nftIds,
fromPortfolio,
toPortfolio,
fromPortfolioId,
toPortfolioId,
createdBlock,
eventId,
eventIdx,
extrinsicIdx,
fundingRound,
instructionId,
instructionMemo,
}) => ({
asset: new NftCollection({ ticker: assetId }, context),
nfts: nftIds.map(
(id: string) => new Nft({ ticker: assetId, id: new BigNumber(id) }, context)
),
event: eventId,
to: optionize(middlewarePortfolioToPortfolio)(toPortfolio, context),
from: optionize(middlewarePortfolioToPortfolio)(fromPortfolio, context),
fundingRound,
instructionMemo,
instructionId: instructionId ? new BigNumber(instructionId) : undefined,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
extrinsicIndex: new BigNumber(extrinsicIdx!),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...middlewareEventDetailsToEventIdentifier(createdBlock!, eventIdx),
})
}) => {
const fromPortfolio = optionize(portfolioIdStringToPortfolio)(fromPortfolioId);
const toPortfolio = optionize(portfolioIdStringToPortfolio)(toPortfolioId);

return {
asset: new NftCollection({ ticker: assetId }, context),
nfts: nftIds.map(
(id: string) => new Nft({ ticker: assetId, id: new BigNumber(id) }, context)
),
event: eventId,
to: optionize(middlewarePortfolioToPortfolio)(toPortfolio, context),
from: optionize(middlewarePortfolioToPortfolio)(fromPortfolio, context),
fundingRound,
instructionMemo,
instructionId: instructionId ? new BigNumber(instructionId) : undefined,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
extrinsicIndex: new BigNumber(extrinsicIdx!),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...middlewareEventDetailsToEventIdentifier(createdBlock!, eventIdx),
};
}
);

const count = new BigNumber(totalCount);
Expand Down
24 changes: 6 additions & 18 deletions src/api/entities/Asset/__tests__/Fungible/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,8 @@ describe('Asset class', () => {
assetId: ticker,
amount: new BigNumber(100).shiftedBy(6),
eventId: EventIdEnum.Issued,
toPortfolio: {
identityId: 'SOME_DID',
number: 0,
},
fromPortfolio: null,
toPortfolioId: 'SOME_DID/0',
fromPortfolioId: null,
eventIdx: 1,
extrinsicIdx: 1,
createdBlock: {
Expand All @@ -797,11 +794,8 @@ describe('Asset class', () => {
assetId: ticker,
amount: new BigNumber(1).shiftedBy(6),
eventId: EventIdEnum.Redeemed,
fromPortfolio: {
identityId: 'SOME_DID',
number: 0,
},
toPortfolio: null,
fromPortfolioId: 'SOME_DID/0',
toPortfolioId: null,
eventIdx: 1,
extrinsicIdx: 1,
createdBlock: {
Expand All @@ -814,14 +808,8 @@ describe('Asset class', () => {
assetId: ticker,
amount: new BigNumber(10).shiftedBy(6),
eventId: EventIdEnum.Transfer,
fromPortfolio: {
identityId: 'SOME_DID',
number: 0,
},
toPortfolio: {
identityId: 'SOME_OTHER_DID',
number: 1,
},
fromPortfolioId: 'SOME_DID/0',
toPortfolioId: 'SOME_OTHER_DID/1',
instructionId: '2',
instructionMemo: 'Some memo',
eventIdx: 1,
Expand Down
21 changes: 6 additions & 15 deletions src/api/entities/Asset/__tests__/NonFungible/NftCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PolymeshError,
PolymeshTransaction,
} from '~/internal';
import { assetQuery, nftTransactionQuery } from '~/middleware/queries/assets';
import { assetQuery, assetTransactionQuery } from '~/middleware/queries/assets';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import {
ErrorCode,
Expand Down Expand Up @@ -578,11 +578,8 @@ describe('NftCollection class', () => {
assetId: ticker,
nftIds: ['1'],
eventId: EventIdEnum.Issued,
toPortfolio: {
identityId: 'SOME_DID',
number: 0,
},
fromPortfolio: null,
toPortfolioId: 'SOME_DID/0',
fromPortfolioId: null,
extrinsicIdx: 1,
eventIdx: 1,
createdBlock: {
Expand All @@ -595,14 +592,8 @@ describe('NftCollection class', () => {
assetId: ticker,
nftIds: ['1'],
eventId: EventIdEnum.Transfer,
toPortfolio: {
identityId: 'OTHER_DID',
number: 0,
},
fromPortfolio: {
identityId: 'SOME_DID',
number: 0,
},
toPortfolioId: 'OTHER_DID/0',
fromPortfolioId: 'SOME_DID/0',
instructionId: 1,
instructionMemo: 'some memo',
extrinsicIdx: 1,
Expand All @@ -617,7 +608,7 @@ describe('NftCollection class', () => {
};

dsMockUtils.createApolloQueryMock(
nftTransactionQuery({ assetId: ticker }, new BigNumber(3), new BigNumber(0)),
assetTransactionQuery({ assetId: ticker }, new BigNumber(3), new BigNumber(0)),
{
assetTransactions: transactionResponse,
}
Expand Down
23 changes: 0 additions & 23 deletions src/middleware/__tests__/queries/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
assetTransactionQuery,
nftCollectionHolders,
nftHoldersQuery,
nftTransactionQuery,
} from '~/middleware/queries/assets';

describe('assetQuery', () => {
Expand Down Expand Up @@ -88,28 +87,6 @@ describe('assetTransactionQuery', () => {
});
});

describe('nftTransactionQuery', () => {
it('should pass the variables to the grapqhl query', () => {
const variables = {
assetId: 'SOME_TICKER',
};

let result = nftTransactionQuery(variables);

expect(result.query).toBeDefined();
expect(result.variables).toEqual(variables);

result = nftTransactionQuery(variables, new BigNumber(1), new BigNumber(0));

expect(result.query).toBeDefined();
expect(result.variables).toEqual({
...variables,
size: 1,
start: 0,
});
});
});

describe('nftCollectionHoldersQuery', () => {
it('should pass the variables to the grapqhl query', () => {
const ticker = 'TICKER';
Expand Down
60 changes: 0 additions & 60 deletions src/middleware/queries/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,69 +130,9 @@ export function assetTransactionQuery(
nodes {
assetId
amount
fromPortfolioId
fromPortfolio {
identityId
number
}
toPortfolioId
toPortfolio {
identityId
number
}
eventId
eventIdx
extrinsicIdx
fundingRound
instructionId
instructionMemo
datetime
createdBlock {
blockId
hash
datetime
}
}
}
}
`;

return {
query,
variables: { ...filters, size: size?.toNumber(), start: start?.toNumber() },
};
}

/**
* @hidden
*
* Get the transaction history for an NFT Collection
*/
export function nftTransactionQuery(
filters: QueryArgs<AssetTransaction, 'assetId'>,
size?: BigNumber,
start?: BigNumber
): QueryOptions<PaginatedQueryArgs<QueryArgs<AssetTransaction, 'assetId'>>> {
const query = gql`
query AssetTransactionQuery($assetId: String!) {
assetTransactions(
filter: { assetId: { equalTo: $assetId } }
orderBy: [${AssetTransactionsOrderBy.CreatedAtAsc}, ${AssetTransactionsOrderBy.CreatedBlockIdAsc}]
) {
totalCount
nodes {
assetId
nftIds
fromPortfolioId
fromPortfolio {
identityId
number
}
toPortfolioId
toPortfolio {
identityId
number
}
eventId
eventIdx
extrinsicIdx
Expand Down
4 changes: 1 addition & 3 deletions src/middleware/queries/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ export function customClaimTypeQuery(
nodes {
id
name
identity {
did
}
identityId
}
totalCount
}
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/queries/multisigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function multiSigProposalQuery(
hash
datetime
}
votes {
votes(orderBy: [${MultiSigProposalVotesOrderBy.CreatedAtAsc}, ${MultiSigProposalVotesOrderBy.CreatedBlockIdAsc}, ${MultiSigProposalVotesOrderBy.EventIdxAsc}]) {
nodes {
action
signer {
Expand Down Expand Up @@ -68,7 +68,7 @@ export function multiSigProposalVotesQuery(
query MultiSigProposalVotesQuery($proposalId: String!) {
multiSigProposalVotes(
filter: { proposalId: { equalTo: $proposalId } }
orderBy: [${MultiSigProposalVotesOrderBy.CreatedAtAsc}]
orderBy: [${MultiSigProposalVotesOrderBy.CreatedAtAsc}, ${MultiSigProposalVotesOrderBy.CreatedBlockIdAsc}, ${MultiSigProposalVotesOrderBy.EventIdxAsc}]
) {
nodes {
signer {
Expand Down
Loading

0 comments on commit d0de49c

Please sign in to comment.