Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions indexer/src/kadena-server/config/graphql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ export type Query = {
* At least one of accountName, fungibleName, blockHash, or requestKey must be provided.
*/
transactions: QueryTransactionsConnection;
/** Retrieve all transactions by a given pact code. */
transactionsByPactCode: QueryTransactionsByPactCodeConnection;
/** Retrieve all transactions by a given public key. */
transactionsByPublicKey: QueryTransactionsByPublicKeyConnection;
/** Retrieve transfers. Default page size is 20. */
Expand Down Expand Up @@ -998,6 +1000,14 @@ export type QueryTransactionsArgs = {
requestKey?: InputMaybe<Scalars['String']['input']>;
};

export type QueryTransactionsByPactCodeArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
first?: InputMaybe<Scalars['Int']['input']>;
last?: InputMaybe<Scalars['Int']['input']>;
pactCode: Scalars['String']['input'];
};

export type QueryTransactionsByPublicKeyArgs = {
after?: InputMaybe<Scalars['String']['input']>;
before?: InputMaybe<Scalars['String']['input']>;
Expand Down Expand Up @@ -1108,6 +1118,18 @@ export type QueryTokensEdge = {
node: Token;
};

export type QueryTransactionsByPactCodeConnection = {
__typename?: 'QueryTransactionsByPactCodeConnection';
edges: Array<QueryTransactionsByPactCodeConnectionEdge>;
pageInfo: PageInfo;
};

export type QueryTransactionsByPactCodeConnectionEdge = {
__typename?: 'QueryTransactionsByPactCodeConnectionEdge';
cursor: Scalars['String']['output'];
node: TransactionSummary;
};

export type QueryTransactionsByPublicKeyConnection = {
__typename?: 'QueryTransactionsByPublicKeyConnection';
edges: Array<QueryTransactionsByPublicKeyConnectionEdge>;
Expand Down Expand Up @@ -1377,6 +1399,19 @@ export type TransactionSignature = {
sig: Scalars['String']['output'];
};

export type TransactionSummary = {
__typename?: 'TransactionSummary';
canonical: Scalars['Boolean']['output'];
chainId: Scalars['String']['output'];
creationTime: Scalars['String']['output'];
gas: Scalars['String']['output'];
gasLimit: Scalars['String']['output'];
gasPrice: Scalars['String']['output'];
height: Scalars['String']['output'];
requestKey: Scalars['String']['output'];
sender: Scalars['String']['output'];
};

/** A transfer of funds from a fungible between two accounts. */
export type Transfer = Node & {
__typename?: 'Transfer';
Expand Down Expand Up @@ -1779,6 +1814,8 @@ export type ResolversTypes = {
QueryPoolsConnectionEdge: ResolverTypeWrapper<QueryPoolsConnectionEdge>;
QueryTokensConnection: ResolverTypeWrapper<QueryTokensConnection>;
QueryTokensEdge: ResolverTypeWrapper<QueryTokensEdge>;
QueryTransactionsByPactCodeConnection: ResolverTypeWrapper<QueryTransactionsByPactCodeConnection>;
QueryTransactionsByPactCodeConnectionEdge: ResolverTypeWrapper<QueryTransactionsByPactCodeConnectionEdge>;
QueryTransactionsByPublicKeyConnection: ResolverTypeWrapper<
Omit<QueryTransactionsByPublicKeyConnection, 'edges'> & {
edges: Array<ResolversTypes['QueryTransactionsByPublicKeyConnectionEdge']>;
Expand Down Expand Up @@ -1856,6 +1893,7 @@ export type ResolversTypes = {
Omit<TransactionResultTransfersConnectionEdge, 'node'> & { node: ResolversTypes['Transfer'] }
>;
TransactionSignature: ResolverTypeWrapper<TransactionSignature>;
TransactionSummary: ResolverTypeWrapper<TransactionSummary>;
Transfer: ResolverTypeWrapper<
Omit<Transfer, 'block' | 'crossChainTransfer' | 'transaction'> & {
block: ResolversTypes['Block'];
Expand Down Expand Up @@ -2047,6 +2085,8 @@ export type ResolversParentTypes = {
QueryPoolsConnectionEdge: QueryPoolsConnectionEdge;
QueryTokensConnection: QueryTokensConnection;
QueryTokensEdge: QueryTokensEdge;
QueryTransactionsByPactCodeConnection: QueryTransactionsByPactCodeConnection;
QueryTransactionsByPactCodeConnectionEdge: QueryTransactionsByPactCodeConnectionEdge;
QueryTransactionsByPublicKeyConnection: Omit<QueryTransactionsByPublicKeyConnection, 'edges'> & {
edges: Array<ResolversParentTypes['QueryTransactionsByPublicKeyConnectionEdge']>;
};
Expand Down Expand Up @@ -2105,6 +2145,7 @@ export type ResolversParentTypes = {
'node'
> & { node: ResolversParentTypes['Transfer'] };
TransactionSignature: TransactionSignature;
TransactionSummary: TransactionSummary;
Transfer: Omit<Transfer, 'block' | 'crossChainTransfer' | 'transaction'> & {
block: ResolversParentTypes['Block'];
crossChainTransfer?: Maybe<ResolversParentTypes['Transfer']>;
Expand Down Expand Up @@ -3094,6 +3135,12 @@ export type QueryResolvers<
ContextType,
Partial<QueryTransactionsArgs>
>;
transactionsByPactCode?: Resolver<
ResolversTypes['QueryTransactionsByPactCodeConnection'],
ParentType,
ContextType,
RequireFields<QueryTransactionsByPactCodeArgs, 'pactCode'>
>;
transactionsByPublicKey?: Resolver<
ResolversTypes['QueryTransactionsByPublicKeyConnection'],
ParentType,
Expand Down Expand Up @@ -3264,6 +3311,30 @@ export type QueryTokensEdgeResolvers<
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type QueryTransactionsByPactCodeConnectionResolvers<
ContextType = any,
ParentType extends
ResolversParentTypes['QueryTransactionsByPactCodeConnection'] = ResolversParentTypes['QueryTransactionsByPactCodeConnection'],
> = {
edges?: Resolver<
Array<ResolversTypes['QueryTransactionsByPactCodeConnectionEdge']>,
ParentType,
ContextType
>;
pageInfo?: Resolver<ResolversTypes['PageInfo'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type QueryTransactionsByPactCodeConnectionEdgeResolvers<
ContextType = any,
ParentType extends
ResolversParentTypes['QueryTransactionsByPactCodeConnectionEdge'] = ResolversParentTypes['QueryTransactionsByPactCodeConnectionEdge'],
> = {
cursor?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
node?: Resolver<ResolversTypes['TransactionSummary'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type QueryTransactionsByPublicKeyConnectionResolvers<
ContextType = any,
ParentType extends
Expand Down Expand Up @@ -3595,6 +3666,23 @@ export type TransactionSignatureResolvers<
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type TransactionSummaryResolvers<
ContextType = any,
ParentType extends
ResolversParentTypes['TransactionSummary'] = ResolversParentTypes['TransactionSummary'],
> = {
canonical?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
chainId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
creationTime?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
gas?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
gasLimit?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
gasPrice?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
height?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
requestKey?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
sender?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type TransferResolvers<
ContextType = any,
ParentType extends ResolversParentTypes['Transfer'] = ResolversParentTypes['Transfer'],
Expand Down Expand Up @@ -3701,6 +3789,8 @@ export type Resolvers<ContextType = any> = {
QueryPoolsConnectionEdge?: QueryPoolsConnectionEdgeResolvers<ContextType>;
QueryTokensConnection?: QueryTokensConnectionResolvers<ContextType>;
QueryTokensEdge?: QueryTokensEdgeResolvers<ContextType>;
QueryTransactionsByPactCodeConnection?: QueryTransactionsByPactCodeConnectionResolvers<ContextType>;
QueryTransactionsByPactCodeConnectionEdge?: QueryTransactionsByPactCodeConnectionEdgeResolvers<ContextType>;
QueryTransactionsByPublicKeyConnection?: QueryTransactionsByPublicKeyConnectionResolvers<ContextType>;
QueryTransactionsByPublicKeyConnectionEdge?: QueryTransactionsByPublicKeyConnectionEdgeResolvers<ContextType>;
QueryTransactionsConnection?: QueryTransactionsConnectionResolvers<ContextType>;
Expand All @@ -3725,6 +3815,7 @@ export type Resolvers<ContextType = any> = {
TransactionResultTransfersConnection?: TransactionResultTransfersConnectionResolvers<ContextType>;
TransactionResultTransfersConnectionEdge?: TransactionResultTransfersConnectionEdgeResolvers<ContextType>;
TransactionSignature?: TransactionSignatureResolvers<ContextType>;
TransactionSummary?: TransactionSummaryResolvers<ContextType>;
Transfer?: TransferResolvers<ContextType>;
UserGuard?: UserGuardResolvers<ContextType>;
};
Expand Down
33 changes: 33 additions & 0 deletions indexer/src/kadena-server/config/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,17 @@ type Query {
publicKey: String!
): QueryTransactionsByPublicKeyConnection! @complexity(value: 1, multipliers: ["first", "last"])

"""
Retrieve all transactions by a given pact code.
"""
transactionsByPactCode(
after: String
before: String
first: Int
last: Int
pactCode: String!
): QueryTransactionsByPactCodeConnection! @complexity(value: 1, multipliers: ["first", "last"])

"""
Retrieve transfers. Default page size is 20.
"""
Expand Down Expand Up @@ -432,6 +443,28 @@ type Query {
tokenPrices(protocolAddress: String): [TokenPrice!]! @complexity(value: 1)
}

type QueryTransactionsByPactCodeConnection {
edges: [QueryTransactionsByPactCodeConnectionEdge!]!
pageInfo: PageInfo!
}

type QueryTransactionsByPactCodeConnectionEdge {
cursor: String!
node: TransactionSummary!
}

type TransactionSummary {
requestKey: String!
height: String!
chainId: String!
canonical: Boolean!
creationTime: String!
sender: String!
gas: String!
gasLimit: String!
gasPrice: String!
}

"""
Connection type for balance query results.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import { ConnectionEdge } from '../types';
*/
export type GetTransactionsParams = GetTransactionsCountParams & PaginationsParams;

export type GetTransactionsByPactCodeParams = PaginationsParams & {
pactCode: string;
};

/**
* Parameters for fetching transactions by a specific public key.
* Extends pagination parameters to support page-based data access.
Expand Down Expand Up @@ -109,6 +113,18 @@ export type TransactionOutput = Omit<Transaction, 'cmd'> & {
blockHeight: number;
};

export type TransactionByPactCodeOutput = {
creationTime: string;
requestKey: string;
chainId: string;
height: string;
canonical: boolean;
gas: string;
gasLimit: string;
gasPrice: string;
sender: string;
};

/**
* Transaction metadata as returned by the repository.
* Direct mapping to the GraphQL TransactionMeta type.
Expand Down Expand Up @@ -138,6 +154,18 @@ export default interface TransactionRepository {
edges: ConnectionEdge<TransactionOutput>[];
}>;

/**
* Retrieves transactions by pact code with pagination.
*
* @param params - Pact code and pagination parameters
* @returns Promise resolving to paginated transaction results
*/

getTransactionsByPactCode(params: GetTransactionsByPactCodeParams): Promise<{
pageInfo: PageInfo;
edges: ConnectionEdge<TransactionByPactCodeOutput>[];
}>;

/**
* Retrieves the last transactions based on specified parameters.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,8 @@ export default class TransactionQueryBuilder {
limit: number;
transactionCode: string;
}) {
let whereCondition = `\nWHERE td.code::text LIKE '%' || $2::text || '%' AND b.canonical = $3`;
let queryParams: (string | number | boolean)[] = [params.limit, params.transactionCode, true];

if (!params.after && !params.before && params.order === 'DESC') {
const currentTime = Date.now() - 10000000;
queryParams.push(currentTime, 0);
whereCondition += `\nAND t.creationtime > $${queryParams.length - 1} AND t.id > $${queryParams.length}`;
}
let whereCondition = `\nWHERE td.code::text LIKE '%' || $2 || '%' AND t.sender != 'coinbase'`;
let queryParams: (string | number | boolean)[] = [params.limit, params.transactionCode];

if (params.after) {
const [creationTime, id] = params.after.split(':');
Expand All @@ -442,38 +436,24 @@ export default class TransactionQueryBuilder {
}

const query = `
WITH filtered_transactions AS (
SELECT t.*, td.code, td.nonce, td.sigs, td.continuation, td.pactid, td.proof, td.rollback, td.gas, td.step, td.data, b.height, b.hash as "blockHash"
FROM "Transactions" t
JOIN "TransactionDetails" td ON t.id = td."transactionId"
JOIN "Blocks" b ON b.id = t."blockId"
${whereCondition}
ORDER BY t.creationtime ${params.order}, t.id ${params.order}
)
SELECT
t.id AS id,
t.creationtime AS "creationTime",
t.hash AS "hashTransaction",
t.nonce AS "nonceTransaction",
t.sigs AS sigs,
t.continuation AS continuation,
t.num_events AS "eventCount",
t.pactid AS "pactId",
t.proof AS proof,
t.rollback AS rollback,
t.txid AS txid,
t.height AS "height",
t."blockHash" AS "blockHash",
t.requestkey AS "requestKey",
t."chainId" AS "chainId",
t.gas AS "gas",
t.step AS step,
t.data AS data,
t.code AS code,
t.logs AS "logs",
t.creationtime AS "creationTime",
t.sender AS "sender",
td.gas AS "gas",
td.gaslimit AS "gasLimit",
td.gasprice AS "gasPrice",
t.result AS "result",
t.requestkey AS "requestKey"
FROM filtered_transactions t
LIMIT $1
b.height AS "height",
b.canonical AS "canonical"
FROM "TransactionDetails" td
JOIN "Transactions" t ON t.id = td."transactionId"
JOIN "Blocks" b ON b.id = t."blockId"
${whereCondition}
ORDER BY t.creationtime ${params.order}, t.id ${params.order}
LIMIT $1
`;

return { query, queryParams };
Expand Down
Loading