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
5 changes: 5 additions & 0 deletions indexer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { useKadenaGraphqlServer } from "./kadena-server/server";
import { closeDatabase } from "./config/database";
import { initializeDatabase } from "./config/init";
import { startGuardsBackfill } from "./services/sync/guards";
import { startBackfillCoinbaseTransactions } from "./services/sync/coinbase";

program
.option("-s, --streaming", "Start streaming blockchain data")
.option("-g, --oldGraphql", "Start GraphQL server based on Postgraphile")
.option("-t, --graphql", "Start GraphQL server based on kadena schema")
.option("-f, --guards", "Backfill the guards")
// this option shouldn't be used if you initialize the indexer from the beginning
.option("-c, --coinbase", "Backfill coinbase transactions")
.option("-z, --database", "Init the database");

program.parse(process.argv);
Expand All @@ -37,6 +40,8 @@ async function main() {
await startStreaming();
} else if (options.guards) {
await startGuardsBackfill();
} else if (options.coinbase) {
await startBackfillCoinbaseTransactions();
} else if (options.oldGraphql) {
await usePostgraphile();
} else if (options.graphql) {
Expand Down
2 changes: 2 additions & 0 deletions indexer/src/kadena-server/config/apollo-server-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type ResolverContext = {
mempoolGateway: MempoolGateway;
pactGateway: PactGateway;
pubSub: PubSub;
signal: AbortSignal;
};

export const createGraphqlContext = () => {
Expand All @@ -56,6 +57,7 @@ export const createGraphqlContext = () => {
mempoolGateway: new MempoolApiGateway(),
pactGateway: new PactApiGateway(),
pubSub: publishSubscribe,
signal: new AbortController().signal,
};

return Promise.resolve({
Expand Down
70 changes: 66 additions & 4 deletions indexer/src/kadena-server/config/graphql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,13 @@ export type Query = {
fungibleAccount?: Maybe<FungibleAccount>;
/** Retrieve an account by public key. */
fungibleAccountsByPublicKey: Array<FungibleAccount>;
/**
* Retrieve an account by its name and fungible, such as coin, on a specific chain.
* @deprecated deprecated, use Query.fungibleChainAccounts
*/
fungibleChainAccount?: Maybe<FungibleChainAccount>;
/** Retrieve an account by its name and fungible, such as coin, on a specific chain. */
fungibleChainAccounts: Array<FungibleChainAccount>;
fungibleChainAccounts?: Maybe<Array<FungibleChainAccount>>;
/** Retrieve a chain account by public key. */
fungibleChainAccountsByPublicKey: Array<FungibleChainAccount>;
/**
Expand Down Expand Up @@ -585,6 +590,13 @@ export type QueryFungibleAccountsByPublicKeyArgs = {
};


export type QueryFungibleChainAccountArgs = {
accountName: Scalars['String']['input'];
chainId: Scalars['String']['input'];
fungibleName?: InputMaybe<Scalars['String']['input']>;
};


export type QueryFungibleChainAccountsArgs = {
accountName: Scalars['String']['input'];
chainIds?: InputMaybe<Array<Scalars['String']['input']>>;
Expand Down Expand Up @@ -762,6 +774,16 @@ export type QueryTransfersConnectionEdge = {
node: Transfer;
};

/** DEPRECATED: a fallthrough IGuard type to cover non-KeysetGuard types. */
export type RawGuard = IGuard & {
__typename?: 'RawGuard';
/** @deprecated deprecated, use KeysetGuard.keys */
keys: Array<Scalars['String']['output']>;
/** @deprecated deprecated, use KeysetGuard.predicate */
predicate: Scalars['String']['output'];
raw: Scalars['String']['output'];
};

/** A signer for a specific transaction. */
export type Signer = Node & {
__typename?: 'Signer';
Expand Down Expand Up @@ -884,6 +906,11 @@ export type TransactionResult = {
gas: Scalars['BigInt']['output'];
/** The transaction result when it was successful. Formatted as raw JSON. */
goodResult?: Maybe<Scalars['String']['output']>;
/**
* The height of the block this transaction belongs to.
* @deprecated Use `block.height` instead.
*/
height: Scalars['BigInt']['output'];
/** Identifier to retrieve the logs for the execution of the transaction. */
logs?: Maybe<Scalars['String']['output']>;
/** @deprecated Not used. */
Expand Down Expand Up @@ -968,6 +995,17 @@ export type Transfer = Node & {
transaction?: Maybe<Transaction>;
};

export type UserGuard = IGuard & {
__typename?: 'UserGuard';
args: Array<Scalars['String']['output']>;
fun: Scalars['String']['output'];
/** @deprecated deprecated, use KeysetGuard.keys */
keys: Array<Scalars['String']['output']>;
/** @deprecated deprecated, use KeysetGuard.predicate */
predicate: Scalars['String']['output'];
raw: Scalars['String']['output'];
};



export type ResolverTypeWrapper<T> = Promise<T> | T;
Expand Down Expand Up @@ -1043,7 +1081,7 @@ export type ResolversUnionTypes<_RefType extends Record<string, unknown>> = {

/** Mapping of interface types */
export type ResolversInterfaceTypes<_RefType extends Record<string, unknown>> = {
IGuard: ( KeysetGuard );
IGuard: ( KeysetGuard ) | ( RawGuard ) | ( UserGuard );
Node: ( Omit<Block, 'events' | 'minerAccount' | 'parent' | 'transactions'> & { events: _RefType['BlockEventsConnection'], minerAccount: _RefType['FungibleChainAccount'], parent?: Maybe<_RefType['Block']>, transactions: _RefType['BlockTransactionsConnection'] } ) | ( Omit<Event, 'block' | 'transaction'> & { block: _RefType['Block'], transaction?: Maybe<_RefType['Transaction']> } ) | ( Omit<FungibleAccount, 'chainAccounts' | 'transactions' | 'transfers'> & { chainAccounts: Array<_RefType['FungibleChainAccount']>, transactions: _RefType['FungibleAccountTransactionsConnection'], transfers: _RefType['FungibleAccountTransfersConnection'] } ) | ( Omit<FungibleChainAccount, 'guard' | 'transactions' | 'transfers'> & { guard: _RefType['IGuard'], transactions: _RefType['FungibleChainAccountTransactionsConnection'], transfers: _RefType['FungibleChainAccountTransfersConnection'] } ) | ( Omit<NonFungibleAccount, 'chainAccounts' | 'nonFungibleTokenBalances' | 'transactions'> & { chainAccounts: Array<_RefType['NonFungibleChainAccount']>, nonFungibleTokenBalances: Array<_RefType['NonFungibleTokenBalance']>, transactions: _RefType['NonFungibleAccountTransactionsConnection'] } ) | ( Omit<NonFungibleChainAccount, 'nonFungibleTokenBalances' | 'transactions'> & { nonFungibleTokenBalances: Array<_RefType['NonFungibleTokenBalance']>, transactions: _RefType['NonFungibleChainAccountTransactionsConnection'] } ) | ( Omit<NonFungibleTokenBalance, 'guard'> & { guard: _RefType['IGuard'] } ) | ( Signer ) | ( Omit<Transaction, 'cmd' | 'orphanedTransactions' | 'result'> & { cmd: _RefType['TransactionCommand'], orphanedTransactions?: Maybe<Array<Maybe<_RefType['Transaction']>>>, result: _RefType['TransactionInfo'] } ) | ( Omit<Transfer, 'block' | 'crossChainTransfer' | 'transaction'> & { block: _RefType['Block'], crossChainTransfer?: Maybe<_RefType['Transfer']>, transaction?: Maybe<_RefType['Transaction']> } );
};

Expand Down Expand Up @@ -1109,6 +1147,7 @@ export type ResolversTypes = {
QueryTransactionsConnectionEdge: ResolverTypeWrapper<Omit<QueryTransactionsConnectionEdge, 'node'> & { node: ResolversTypes['Transaction'] }>;
QueryTransfersConnection: ResolverTypeWrapper<Omit<QueryTransfersConnection, 'edges'> & { edges: Array<ResolversTypes['QueryTransfersConnectionEdge']> }>;
QueryTransfersConnectionEdge: ResolverTypeWrapper<Omit<QueryTransfersConnectionEdge, 'node'> & { node: ResolversTypes['Transfer'] }>;
RawGuard: ResolverTypeWrapper<RawGuard>;
Signer: ResolverTypeWrapper<Signer>;
String: ResolverTypeWrapper<Scalars['String']['output']>;
Subscription: ResolverTypeWrapper<{}>;
Expand All @@ -1126,6 +1165,7 @@ export type ResolversTypes = {
TransactionResultTransfersConnectionEdge: ResolverTypeWrapper<Omit<TransactionResultTransfersConnectionEdge, 'node'> & { node: ResolversTypes['Transfer'] }>;
TransactionSignature: ResolverTypeWrapper<TransactionSignature>;
Transfer: ResolverTypeWrapper<Omit<Transfer, 'block' | 'crossChainTransfer' | 'transaction'> & { block: ResolversTypes['Block'], crossChainTransfer?: Maybe<ResolversTypes['Transfer']>, transaction?: Maybe<ResolversTypes['Transaction']> }>;
UserGuard: ResolverTypeWrapper<UserGuard>;
};

/** Mapping between all available schema types and the resolvers parents */
Expand Down Expand Up @@ -1190,6 +1230,7 @@ export type ResolversParentTypes = {
QueryTransactionsConnectionEdge: Omit<QueryTransactionsConnectionEdge, 'node'> & { node: ResolversParentTypes['Transaction'] };
QueryTransfersConnection: Omit<QueryTransfersConnection, 'edges'> & { edges: Array<ResolversParentTypes['QueryTransfersConnectionEdge']> };
QueryTransfersConnectionEdge: Omit<QueryTransfersConnectionEdge, 'node'> & { node: ResolversParentTypes['Transfer'] };
RawGuard: RawGuard;
Signer: Signer;
String: Scalars['String']['output'];
Subscription: {};
Expand All @@ -1207,6 +1248,7 @@ export type ResolversParentTypes = {
TransactionResultTransfersConnectionEdge: Omit<TransactionResultTransfersConnectionEdge, 'node'> & { node: ResolversParentTypes['Transfer'] };
TransactionSignature: TransactionSignature;
Transfer: Omit<Transfer, 'block' | 'crossChainTransfer' | 'transaction'> & { block: ResolversParentTypes['Block'], crossChainTransfer?: Maybe<ResolversParentTypes['Transfer']>, transaction?: Maybe<ResolversParentTypes['Transaction']> };
UserGuard: UserGuard;
};

export interface BigIntScalarConfig extends GraphQLScalarTypeConfig<ResolversTypes['BigInt'], any> {
Expand Down Expand Up @@ -1403,7 +1445,7 @@ export type GraphConfigurationResolvers<ContextType = any, ParentType extends Re
};

export type IGuardResolvers<ContextType = any, ParentType extends ResolversParentTypes['IGuard'] = ResolversParentTypes['IGuard']> = {
__resolveType: TypeResolveFn<'KeysetGuard', ParentType, ContextType>;
__resolveType: TypeResolveFn<'KeysetGuard' | 'RawGuard' | 'UserGuard', ParentType, ContextType>;
keys?: Resolver<Array<ResolversTypes['String']>, ParentType, ContextType>;
predicate?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
raw?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
Expand Down Expand Up @@ -1527,7 +1569,8 @@ export type QueryResolvers<ContextType = any, ParentType extends ResolversParent
events?: Resolver<ResolversTypes['QueryEventsConnection'], ParentType, ContextType, RequireFields<QueryEventsArgs, 'qualifiedEventName'>>;
fungibleAccount?: Resolver<Maybe<ResolversTypes['FungibleAccount']>, ParentType, ContextType, RequireFields<QueryFungibleAccountArgs, 'accountName' | 'fungibleName'>>;
fungibleAccountsByPublicKey?: Resolver<Array<ResolversTypes['FungibleAccount']>, ParentType, ContextType, RequireFields<QueryFungibleAccountsByPublicKeyArgs, 'fungibleName' | 'publicKey'>>;
fungibleChainAccounts?: Resolver<Array<ResolversTypes['FungibleChainAccount']>, ParentType, ContextType, RequireFields<QueryFungibleChainAccountsArgs, 'accountName' | 'fungibleName'>>;
fungibleChainAccount?: Resolver<Maybe<ResolversTypes['FungibleChainAccount']>, ParentType, ContextType, RequireFields<QueryFungibleChainAccountArgs, 'accountName' | 'chainId' | 'fungibleName'>>;
fungibleChainAccounts?: Resolver<Maybe<Array<ResolversTypes['FungibleChainAccount']>>, ParentType, ContextType, RequireFields<QueryFungibleChainAccountsArgs, 'accountName' | 'fungibleName'>>;
fungibleChainAccountsByPublicKey?: Resolver<Array<ResolversTypes['FungibleChainAccount']>, ParentType, ContextType, RequireFields<QueryFungibleChainAccountsByPublicKeyArgs, 'chainId' | 'fungibleName' | 'publicKey'>>;
gasLimitEstimate?: Resolver<Array<ResolversTypes['GasLimitEstimation']>, ParentType, ContextType, RequireFields<QueryGasLimitEstimateArgs, 'input'>>;
graphConfiguration?: Resolver<ResolversTypes['GraphConfiguration'], ParentType, ContextType>;
Expand Down Expand Up @@ -1632,6 +1675,13 @@ export type QueryTransfersConnectionEdgeResolvers<ContextType = any, ParentType
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type RawGuardResolvers<ContextType = any, ParentType extends ResolversParentTypes['RawGuard'] = ResolversParentTypes['RawGuard']> = {
keys?: Resolver<Array<ResolversTypes['String']>, ParentType, ContextType>;
predicate?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
raw?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type SignerResolvers<ContextType = any, ParentType extends ResolversParentTypes['Signer'] = ResolversParentTypes['Signer']> = {
address?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
clist?: Resolver<Array<ResolversTypes['TransactionCapability']>, ParentType, ContextType>;
Expand Down Expand Up @@ -1705,6 +1755,7 @@ export type TransactionResultResolvers<ContextType = any, ParentType extends Res
events?: Resolver<ResolversTypes['TransactionResultEventsConnection'], ParentType, ContextType, Partial<TransactionResultEventsArgs>>;
gas?: Resolver<ResolversTypes['BigInt'], ParentType, ContextType>;
goodResult?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
height?: Resolver<ResolversTypes['BigInt'], ParentType, ContextType>;
logs?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
metadata?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
transactionId?: Resolver<Maybe<ResolversTypes['BigInt']>, ParentType, ContextType>;
Expand Down Expand Up @@ -1762,6 +1813,15 @@ export type TransferResolvers<ContextType = any, ParentType extends ResolversPar
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type UserGuardResolvers<ContextType = any, ParentType extends ResolversParentTypes['UserGuard'] = ResolversParentTypes['UserGuard']> = {
args?: Resolver<Array<ResolversTypes['String']>, ParentType, ContextType>;
fun?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
keys?: Resolver<Array<ResolversTypes['String']>, ParentType, ContextType>;
predicate?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
raw?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type Resolvers<ContextType = any> = {
BigInt?: GraphQLScalarType;
Block?: BlockResolvers<ContextType>;
Expand Down Expand Up @@ -1817,6 +1877,7 @@ export type Resolvers<ContextType = any> = {
QueryTransactionsConnectionEdge?: QueryTransactionsConnectionEdgeResolvers<ContextType>;
QueryTransfersConnection?: QueryTransfersConnectionResolvers<ContextType>;
QueryTransfersConnectionEdge?: QueryTransfersConnectionEdgeResolvers<ContextType>;
RawGuard?: RawGuardResolvers<ContextType>;
Signer?: SignerResolvers<ContextType>;
Subscription?: SubscriptionResolvers<ContextType>;
Transaction?: TransactionResolvers<ContextType>;
Expand All @@ -1833,5 +1894,6 @@ export type Resolvers<ContextType = any> = {
TransactionResultTransfersConnectionEdge?: TransactionResultTransfersConnectionEdgeResolvers<ContextType>;
TransactionSignature?: TransactionSignatureResolvers<ContextType>;
Transfer?: TransferResolvers<ContextType>;
UserGuard?: UserGuardResolvers<ContextType>;
};

36 changes: 35 additions & 1 deletion indexer/src/kadena-server/config/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,24 @@ type Query {
publicKey: String!
): [FungibleAccount!]!

"""
Retrieve an account by its name and fungible, such as coin, on a specific chain.
"""
fungibleChainAccount(
accountName: String!
chainId: String!
fungibleName: String = "coin"
): FungibleChainAccount
@deprecated(reason: "deprecated, use Query.fungibleChainAccounts")

"""
Retrieve an account by its name and fungible, such as coin, on a specific chain.
"""
fungibleChainAccounts(
accountName: String!
chainIds: [String!]
fungibleName: String = "coin"
): [FungibleChainAccount!]!
): [FungibleChainAccount!]

"""
Retrieve a chain account by public key.
Expand Down Expand Up @@ -732,6 +742,11 @@ type TransactionResult {
logs: String
transactionId: BigInt

"""
The height of the block this transaction belongs to.
"""
height: BigInt! @deprecated(reason: "Use `block.height` instead.")

metadata: String! @deprecated(reason: "Not used.")

block: Block!
Expand Down Expand Up @@ -1021,3 +1036,22 @@ type KeysetGuard implements IGuard {
predicate: String!
raw: String!
}

type UserGuard implements IGuard {
args: [String!]!
fun: String!
keys: [String!]! @deprecated(reason: "deprecated, use KeysetGuard.keys")
predicate: String!
@deprecated(reason: "deprecated, use KeysetGuard.predicate")
raw: String!
}

"""
DEPRECATED: a fallthrough IGuard type to cover non-KeysetGuard types.
"""
type RawGuard implements IGuard {
keys: [String!]! @deprecated(reason: "deprecated, use KeysetGuard.keys")
predicate: String!
@deprecated(reason: "deprecated, use KeysetGuard.predicate")
raw: String!
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "../../config/graphql-types";
import { PaginationsParams } from "../pagination";
import { ConnectionEdge } from "../types";
import { TransactionOutput } from "./transaction-repository";

export interface GetBlocksFromDepthParams extends PaginationsParams {
chainIds?: InputMaybe<string[]>;
Expand All @@ -24,6 +25,12 @@ export interface GetBlocksBetweenHeightsParams extends PaginationsParams {
endHeight?: InputMaybe<number>;
}

export interface GetLatestBlocksParams {
creationTime: number;
lastBlockId?: number;
chainIds?: string[];
}

export type BlockOutput = Omit<
Block,
"parent" | "events" | "minerAccount" | "transactions"
Expand Down Expand Up @@ -61,6 +68,12 @@ export default interface BlockRepository {

getTotalCountOfBlockEvents(blockHash: string): Promise<number>;

getLatestBlocks(params: GetLatestBlocksParams): Promise<BlockOutput[]>;

getTransactionsOrderedByBlockDepth(
transactions: TransactionOutput[],
): Promise<TransactionOutput[]>;

// dataloader
getBlocksByEventIds(eventIds: string[]): Promise<BlockOutput[]>;
getBlocksByTransactionIds(transactionIds: string[]): Promise<BlockOutput[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export interface GetEventParams {
requestKey: string;
}

export interface GetLastEventsParams {
qualifiedEventName: string;
lastEventId?: number;
chainId?: string | null;
minimumDepth?: number | null;
}

export default interface EventRepository {
getEvent(params: GetEventParams): Promise<EventOutput>;
getBlockEvents(params: GetBlockEventsParams): Promise<{
Expand All @@ -51,7 +58,9 @@ export default interface EventRepository {
}>;
getTotalEventsCount(hash: GetTotalEventsCount): Promise<number>;
getTotalTransactionEventsCount(
hash: GetTotalTransactionEventsCount
hash: GetTotalTransactionEventsCount,
): Promise<number>;
getTotalCountOfBlockEvents(hash: string): Promise<number>;
getLastEventId(): Promise<number>;
getLastEvents(params: GetLastEventsParams): Promise<EventOutput[]>;
}
Loading