Skip to content

Commit 3988ba6

Browse files
committed
refat: added guards backfill process; fetch balances from kadena node for now
1 parent a74dd03 commit 3988ba6

23 files changed

+515
-49
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ COPY --from=builder /app/src/config/global-bundle.pem ./dist/config/global-bundl
1414
COPY --from=builder /app/src/kadena-server/config/schema.graphql ./dist/kadena-server/config/schema.graphql
1515
EXPOSE 3001
1616

17-
CMD ["node", "dist/index.js", "--graphqlServer"]
17+
CMD ["node", "dist/index.js", "--graphql"]

indexer/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"dev:streaming": "ts-node src/index.ts --streaming",
6868
"dev:old-graphql": "ts-node src/index.ts --oldGraphql",
6969
"dev:graphql": "nodemon src/index.ts --graphql",
70+
"dev:guards": "nodemon src/index.ts --guards",
7071
"prod:start": "docker-compose up --build indexer && docker-compose logs -f indexer",
7172
"prod:streaming": "node dist/index.js --streaming",
7273
"prod:backfill": "node dist/index.js --backfill",
@@ -75,4 +76,4 @@
7576
"migrate:up": "dotenv -e .env npx sequelize-cli db:migrate",
7677
"migrate:down": "dotenv -e .env npx sequelize-cli db:migrate:undo"
7778
}
78-
}
79+
}

indexer/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import { usePostgraphile } from "./server/metrics";
88
import { useKadenaGraphqlServer } from "./kadena-server/server";
99
import { closeDatabase } from "./config/database";
1010
import { initializeDatabase } from "./config/init";
11+
import { startGuardsBackfill } from "./services/sync/guards";
1112

1213
program
1314
.option("-s, --streaming", "Start streaming blockchain data")
1415
.option("-g, --oldGraphql", "Start GraphQL server based on Postgraphile")
1516
.option("-t, --graphql", "Start GraphQL server based on kadena schema")
17+
.option("-f, --guards", "Backfill the guards")
1618
.option("-z, --database", "Init the database");
1719

1820
program.parse(process.argv);
@@ -34,6 +36,8 @@ async function main() {
3436
if (options.streaming) {
3537
await initializeDatabase();
3638
await startStreaming();
39+
} else if (options.guards) {
40+
await startGuardsBackfill();
3741
} else if (options.oldGraphql) {
3842
await usePostgraphile();
3943
} else if (options.graphql) {

indexer/src/kadena-server/config/graphql-types.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export type FungibleChainAccount = Node & {
182182
balance: Scalars['Float']['output'];
183183
chainId: Scalars['String']['output'];
184184
fungibleName: Scalars['String']['output'];
185+
guard: Guard;
185186
id: Scalars['ID']['output'];
186187
transactions: FungibleChainAccountTransactionsConnection;
187188
transfers: FungibleChainAccountTransfersConnection;
@@ -250,6 +251,13 @@ export type GraphConfiguration = {
250251
minimumBlockHeight?: Maybe<Scalars['BigInt']['output']>;
251252
};
252253

254+
export type Guard = {
255+
__typename?: 'Guard';
256+
keys: Array<Scalars['String']['output']>;
257+
predicate: Scalars['String']['output'];
258+
raw: Scalars['String']['output'];
259+
};
260+
253261
/** Information about the network. */
254262
export type NetworkInfo = {
255263
__typename?: 'NetworkInfo';
@@ -922,7 +930,7 @@ export type ResolversUnionTypes<_RefType extends Record<string, unknown>> = {
922930

923931
/** Mapping of interface types */
924932
export type ResolversInterfaceTypes<_RefType extends Record<string, unknown>> = {
925-
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, 'transactions' | 'transfers'> & { transactions: _RefType['FungibleChainAccountTransactionsConnection'], transfers: _RefType['FungibleChainAccountTransfersConnection'] } ) | ( Omit<NonFungibleAccount, 'transactions'> & { transactions: _RefType['NonFungibleAccountTransactionsConnection'] } ) | ( Omit<NonFungibleChainAccount, 'transactions'> & { transactions: _RefType['NonFungibleChainAccountTransactionsConnection'] } ) | ( NonFungibleTokenBalance ) | ( 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']> } );
933+
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['Guard'], transactions: _RefType['FungibleChainAccountTransactionsConnection'], transfers: _RefType['FungibleChainAccountTransfersConnection'] } ) | ( Omit<NonFungibleAccount, 'transactions'> & { transactions: _RefType['NonFungibleAccountTransactionsConnection'] } ) | ( Omit<NonFungibleChainAccount, 'transactions'> & { transactions: _RefType['NonFungibleChainAccountTransactionsConnection'] } ) | ( NonFungibleTokenBalance ) | ( 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']> } );
926934
};
927935

928936
/** Mapping between all available schema types and the resolvers types */
@@ -946,14 +954,15 @@ export type ResolversTypes = {
946954
FungibleAccountTransactionsConnectionEdge: ResolverTypeWrapper<Omit<FungibleAccountTransactionsConnectionEdge, 'node'> & { node: ResolversTypes['Transaction'] }>;
947955
FungibleAccountTransfersConnection: ResolverTypeWrapper<Omit<FungibleAccountTransfersConnection, 'edges'> & { edges: Array<ResolversTypes['FungibleAccountTransfersConnectionEdge']> }>;
948956
FungibleAccountTransfersConnectionEdge: ResolverTypeWrapper<Omit<FungibleAccountTransfersConnectionEdge, 'node'> & { node: ResolversTypes['Transfer'] }>;
949-
FungibleChainAccount: ResolverTypeWrapper<Omit<FungibleChainAccount, 'transactions' | 'transfers'> & { transactions: ResolversTypes['FungibleChainAccountTransactionsConnection'], transfers: ResolversTypes['FungibleChainAccountTransfersConnection'] }>;
957+
FungibleChainAccount: ResolverTypeWrapper<Omit<FungibleChainAccount, 'guard' | 'transactions' | 'transfers'> & { guard: ResolversTypes['Guard'], transactions: ResolversTypes['FungibleChainAccountTransactionsConnection'], transfers: ResolversTypes['FungibleChainAccountTransfersConnection'] }>;
950958
FungibleChainAccountTransactionsConnection: ResolverTypeWrapper<Omit<FungibleChainAccountTransactionsConnection, 'edges'> & { edges: Array<ResolversTypes['FungibleChainAccountTransactionsConnectionEdge']> }>;
951959
FungibleChainAccountTransactionsConnectionEdge: ResolverTypeWrapper<Omit<FungibleChainAccountTransactionsConnectionEdge, 'node'> & { node: ResolversTypes['Transaction'] }>;
952960
FungibleChainAccountTransfersConnection: ResolverTypeWrapper<Omit<FungibleChainAccountTransfersConnection, 'edges'> & { edges: Array<ResolversTypes['FungibleChainAccountTransfersConnectionEdge']> }>;
953961
FungibleChainAccountTransfersConnectionEdge: ResolverTypeWrapper<Omit<FungibleChainAccountTransfersConnectionEdge, 'node'> & { node: ResolversTypes['Transfer'] }>;
954962
GasLimitEstimation: ResolverTypeWrapper<GasLimitEstimation>;
955963
GenesisHeight: ResolverTypeWrapper<GenesisHeight>;
956964
GraphConfiguration: ResolverTypeWrapper<GraphConfiguration>;
965+
Guard: ResolverTypeWrapper<Guard>;
957966
ID: ResolverTypeWrapper<Scalars['ID']['output']>;
958967
Int: ResolverTypeWrapper<Scalars['Int']['output']>;
959968
NetworkInfo: ResolverTypeWrapper<NetworkInfo>;
@@ -1025,14 +1034,15 @@ export type ResolversParentTypes = {
10251034
FungibleAccountTransactionsConnectionEdge: Omit<FungibleAccountTransactionsConnectionEdge, 'node'> & { node: ResolversParentTypes['Transaction'] };
10261035
FungibleAccountTransfersConnection: Omit<FungibleAccountTransfersConnection, 'edges'> & { edges: Array<ResolversParentTypes['FungibleAccountTransfersConnectionEdge']> };
10271036
FungibleAccountTransfersConnectionEdge: Omit<FungibleAccountTransfersConnectionEdge, 'node'> & { node: ResolversParentTypes['Transfer'] };
1028-
FungibleChainAccount: Omit<FungibleChainAccount, 'transactions' | 'transfers'> & { transactions: ResolversParentTypes['FungibleChainAccountTransactionsConnection'], transfers: ResolversParentTypes['FungibleChainAccountTransfersConnection'] };
1037+
FungibleChainAccount: Omit<FungibleChainAccount, 'guard' | 'transactions' | 'transfers'> & { guard: ResolversParentTypes['Guard'], transactions: ResolversParentTypes['FungibleChainAccountTransactionsConnection'], transfers: ResolversParentTypes['FungibleChainAccountTransfersConnection'] };
10291038
FungibleChainAccountTransactionsConnection: Omit<FungibleChainAccountTransactionsConnection, 'edges'> & { edges: Array<ResolversParentTypes['FungibleChainAccountTransactionsConnectionEdge']> };
10301039
FungibleChainAccountTransactionsConnectionEdge: Omit<FungibleChainAccountTransactionsConnectionEdge, 'node'> & { node: ResolversParentTypes['Transaction'] };
10311040
FungibleChainAccountTransfersConnection: Omit<FungibleChainAccountTransfersConnection, 'edges'> & { edges: Array<ResolversParentTypes['FungibleChainAccountTransfersConnectionEdge']> };
10321041
FungibleChainAccountTransfersConnectionEdge: Omit<FungibleChainAccountTransfersConnectionEdge, 'node'> & { node: ResolversParentTypes['Transfer'] };
10331042
GasLimitEstimation: GasLimitEstimation;
10341043
GenesisHeight: GenesisHeight;
10351044
GraphConfiguration: GraphConfiguration;
1045+
Guard: Guard;
10361046
ID: Scalars['ID']['output'];
10371047
Int: Scalars['Int']['output'];
10381048
NetworkInfo: NetworkInfo;
@@ -1221,6 +1231,7 @@ export type FungibleChainAccountResolvers<ContextType = any, ParentType extends
12211231
balance?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
12221232
chainId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
12231233
fungibleName?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
1234+
guard?: Resolver<ResolversTypes['Guard'], ParentType, ContextType>;
12241235
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
12251236
transactions?: Resolver<ResolversTypes['FungibleChainAccountTransactionsConnection'], ParentType, ContextType, RequireFields<FungibleChainAccountTransactionsArgs, 'first' | 'last'>>;
12261237
transfers?: Resolver<ResolversTypes['FungibleChainAccountTransfersConnection'], ParentType, ContextType, RequireFields<FungibleChainAccountTransfersArgs, 'first' | 'last'>>;
@@ -1273,6 +1284,13 @@ export type GraphConfigurationResolvers<ContextType = any, ParentType extends Re
12731284
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
12741285
};
12751286

1287+
export type GuardResolvers<ContextType = any, ParentType extends ResolversParentTypes['Guard'] = ResolversParentTypes['Guard']> = {
1288+
keys?: Resolver<Array<ResolversTypes['String']>, ParentType, ContextType>;
1289+
predicate?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
1290+
raw?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
1291+
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
1292+
};
1293+
12761294
export type NetworkInfoResolvers<ContextType = any, ParentType extends ResolversParentTypes['NetworkInfo'] = ResolversParentTypes['NetworkInfo']> = {
12771295
apiVersion?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
12781296
coinsInCirculation?: Resolver<ResolversTypes['Float'], ParentType, ContextType>;
@@ -1639,6 +1657,7 @@ export type Resolvers<ContextType = any> = {
16391657
GasLimitEstimation?: GasLimitEstimationResolvers<ContextType>;
16401658
GenesisHeight?: GenesisHeightResolvers<ContextType>;
16411659
GraphConfiguration?: GraphConfigurationResolvers<ContextType>;
1660+
Guard?: GuardResolvers<ContextType>;
16421661
NetworkInfo?: NetworkInfoResolvers<ContextType>;
16431662
Node?: NodeResolvers<ContextType>;
16441663
NonFungibleAccount?: NonFungibleAccountResolvers<ContextType>;

indexer/src/kadena-server/config/schema.graphql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ type FungibleChainAccount implements Node {
432432
balance: Float!
433433
chainId: String!
434434
fungibleName: String!
435+
guard: Guard!
435436

436437
transactions(
437438
after: String
@@ -790,3 +791,9 @@ type NonFungibleChainAccountTransactionsConnectionEdge {
790791
cursor: String!
791792
node: Transaction!
792793
}
794+
795+
type Guard {
796+
keys: [String!]!
797+
predicate: String!
798+
raw: String!
799+
}

indexer/src/kadena-server/repository/application/balance-repository.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,27 @@ export default interface BalanceRepository {
7171
chainId: string,
7272
tokenId: string,
7373
): Promise<INonFungibleTokenBalance | null>;
74+
75+
/** methods below use balance from node */
76+
getAccountInfo_NODE(
77+
accountName: string,
78+
fungibleName?: string | null,
79+
): Promise<FungibleAccountOutput>;
80+
81+
getChainsAccountInfo_NODE(
82+
accountName: string,
83+
fungibleName: string,
84+
chainIds?: string[],
85+
): Promise<FungibleChainAccountOutput[]>;
86+
87+
getAccountsByPublicKey_NODE(
88+
publicKey: string,
89+
fungibleName: string,
90+
): Promise<FungibleAccountOutput[]>;
91+
92+
getChainAccountsByPublicKey_NODE(
93+
publicKey: string,
94+
fungibleName: string,
95+
chainId: string,
96+
): Promise<FungibleChainAccountOutput[]>;
7497
}

indexer/src/kadena-server/repository/application/block-repository.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export default interface BlockRepository {
4848
pageInfo: PageInfo;
4949
edges: ConnectionEdge<BlockOutput>[];
5050
}>;
51-
getMinerData(hash: string): Promise<FungibleChainAccountOutput>;
51+
getMinerData(
52+
hash: string,
53+
chainId: string,
54+
): Promise<FungibleChainAccountOutput>;
5255

5356
getLowestBlockHeight(): Promise<number>;
5457

0 commit comments

Comments
 (0)