diff --git a/explorer/gql/graphql.tsx b/explorer/gql/graphql.tsx index a7a8ed73d..b2829e03e 100644 --- a/explorer/gql/graphql.tsx +++ b/explorer/gql/graphql.tsx @@ -93,7 +93,6 @@ export type Consensus_Account_Histories = { nonce: Scalars['numeric']['output']; reserved: Scalars['numeric']['output']; total?: Maybe; - updated_at: Scalars['numeric']['output']; uuid: Scalars['uuid']['output']; }; @@ -135,7 +134,6 @@ export type Consensus_Account_Histories_Avg_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** Boolean expression to filter rows from the table "consensus.account_histories". All fields are combined with a logical 'AND'. */ @@ -151,7 +149,6 @@ export type Consensus_Account_Histories_Bool_Exp = { nonce?: InputMaybe; reserved?: InputMaybe; total?: InputMaybe; - updated_at?: InputMaybe; uuid?: InputMaybe; }; @@ -164,7 +161,6 @@ export type Consensus_Account_Histories_Max_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; uuid?: Maybe; }; @@ -177,7 +173,6 @@ export type Consensus_Account_Histories_Min_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; uuid?: Maybe; }; @@ -191,7 +186,6 @@ export type Consensus_Account_Histories_Order_By = { nonce?: InputMaybe; reserved?: InputMaybe; total?: InputMaybe; - updated_at?: InputMaybe; uuid?: InputMaybe; }; @@ -212,8 +206,6 @@ export enum Consensus_Account_Histories_Select_Column { /** column name */ Total = 'total', /** column name */ - UpdatedAt = 'updated_at', - /** column name */ Uuid = 'uuid' } @@ -225,7 +217,6 @@ export type Consensus_Account_Histories_Stddev_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** aggregate stddev_pop on columns */ @@ -236,7 +227,6 @@ export type Consensus_Account_Histories_Stddev_Pop_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** aggregate stddev_samp on columns */ @@ -247,7 +237,6 @@ export type Consensus_Account_Histories_Stddev_Samp_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** Streaming cursor of the table "consensus_account_histories" */ @@ -267,7 +256,6 @@ export type Consensus_Account_Histories_Stream_Cursor_Value_Input = { nonce?: InputMaybe; reserved?: InputMaybe; total?: InputMaybe; - updated_at?: InputMaybe; uuid?: InputMaybe; }; @@ -279,7 +267,6 @@ export type Consensus_Account_Histories_Sum_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** aggregate var_pop on columns */ @@ -290,7 +277,6 @@ export type Consensus_Account_Histories_Var_Pop_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** aggregate var_samp on columns */ @@ -301,7 +287,6 @@ export type Consensus_Account_Histories_Var_Samp_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** aggregate variance on columns */ @@ -312,7 +297,6 @@ export type Consensus_Account_Histories_Variance_Fields = { nonce?: Maybe; reserved?: Maybe; total?: Maybe; - updated_at?: Maybe; }; /** columns and relationships of "consensus.account_profiles" */ @@ -577,6 +561,7 @@ export type Consensus_Account_Rewards_Stream_Cursor_Value_Input = { export type Consensus_Accounts = { __typename?: 'consensus_accounts'; _block_range: Scalars['int8range']['output']; + account_id: Scalars['String']['output']; created_at: Scalars['numeric']['output']; /** An array relationship */ extrinsics: Array; @@ -684,6 +669,7 @@ export type Consensus_Accounts_Bool_Exp = { _block_range?: InputMaybe; _not?: InputMaybe; _or?: InputMaybe>; + account_id?: InputMaybe; created_at?: InputMaybe; extrinsics?: InputMaybe; extrinsics_aggregate?: InputMaybe; @@ -702,6 +688,7 @@ export type Consensus_Accounts_Bool_Exp = { /** aggregate max on columns */ export type Consensus_Accounts_Max_Fields = { __typename?: 'consensus_accounts_max_fields'; + account_id?: Maybe; created_at?: Maybe; free?: Maybe; id?: Maybe; @@ -715,6 +702,7 @@ export type Consensus_Accounts_Max_Fields = { /** aggregate min on columns */ export type Consensus_Accounts_Min_Fields = { __typename?: 'consensus_accounts_min_fields'; + account_id?: Maybe; created_at?: Maybe; free?: Maybe; id?: Maybe; @@ -728,6 +716,7 @@ export type Consensus_Accounts_Min_Fields = { /** Ordering options when selecting data from "consensus.accounts". */ export type Consensus_Accounts_Order_By = { _block_range?: InputMaybe; + account_id?: InputMaybe; created_at?: InputMaybe; extrinsics_aggregate?: InputMaybe; free?: InputMaybe; @@ -746,6 +735,8 @@ export enum Consensus_Accounts_Select_Column { /** column name */ BlockRange = '_block_range', /** column name */ + AccountId = 'account_id', + /** column name */ CreatedAt = 'created_at', /** column name */ Free = 'free', @@ -807,6 +798,7 @@ export type Consensus_Accounts_Stream_Cursor_Input = { /** Initial value of the column from where the streaming should start */ export type Consensus_Accounts_Stream_Cursor_Value_Input = { _block_range?: InputMaybe; + account_id?: InputMaybe; created_at?: InputMaybe; free?: InputMaybe; id?: InputMaybe; @@ -865,9 +857,27 @@ export type Consensus_Accounts_Variance_Fields = { export type Consensus_Blocks = { __typename?: 'consensus_blocks'; _block_range: Scalars['int8range']['output']; + accounts_count: Scalars['Int']['output']; author_id: Scalars['String']['output']; + block_reward_value: Scalars['numeric']['output']; + block_rewards_count: Scalars['Int']['output']; blockchain_size: Scalars['numeric']['output']; /** An array relationship */ + cids: Array; + /** An aggregate relationship */ + cids_aggregate: Files_Cids_Aggregate; + cumulative_accounts_count: Scalars['numeric']['output']; + cumulative_block_reward_value: Scalars['numeric']['output']; + cumulative_block_rewards_count: Scalars['numeric']['output']; + cumulative_events_count: Scalars['numeric']['output']; + cumulative_extrinsics_count: Scalars['numeric']['output']; + cumulative_reward_value: Scalars['numeric']['output']; + cumulative_rewards_count: Scalars['numeric']['output']; + cumulative_transfer_value: Scalars['numeric']['output']; + cumulative_transfers_count: Scalars['numeric']['output']; + cumulative_vote_reward_value: Scalars['numeric']['output']; + cumulative_vote_rewards_count: Scalars['numeric']['output']; + /** An array relationship */ events: Array; /** An aggregate relationship */ events_aggregate: Consensus_Events_Aggregate; @@ -886,12 +896,38 @@ export type Consensus_Blocks = { /** An aggregate relationship */ logs_aggregate: Consensus_Logs_Aggregate; parent_hash: Scalars['String']['output']; + reward_value: Scalars['numeric']['output']; + rewards_count: Scalars['Int']['output']; sort_id: Scalars['String']['output']; space_pledged: Scalars['numeric']['output']; spec_id: Scalars['String']['output']; state_root: Scalars['String']['output']; timestamp: Scalars['timestamp']['output']; + transfer_value: Scalars['numeric']['output']; + transfers_count: Scalars['Int']['output']; uuid: Scalars['uuid']['output']; + vote_reward_value: Scalars['numeric']['output']; + vote_rewards_count: Scalars['Int']['output']; +}; + + +/** columns and relationships of "consensus.blocks" */ +export type Consensus_BlocksCidsArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +/** columns and relationships of "consensus.blocks" */ +export type Consensus_BlocksCids_AggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; }; @@ -987,11 +1023,31 @@ export type Consensus_Blocks_Aggregate_FieldsCountArgs = { /** aggregate avg on columns */ export type Consensus_Blocks_Avg_Fields = { __typename?: 'consensus_blocks_avg_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** Boolean expression to filter rows from the table "consensus.blocks". All fields are combined with a logical 'AND'. */ @@ -1000,8 +1056,24 @@ export type Consensus_Blocks_Bool_Exp = { _block_range?: InputMaybe; _not?: InputMaybe; _or?: InputMaybe>; + accounts_count?: InputMaybe; author_id?: InputMaybe; + block_reward_value?: InputMaybe; + block_rewards_count?: InputMaybe; blockchain_size?: InputMaybe; + cids?: InputMaybe; + cids_aggregate?: InputMaybe; + cumulative_accounts_count?: InputMaybe; + cumulative_block_reward_value?: InputMaybe; + cumulative_block_rewards_count?: InputMaybe; + cumulative_events_count?: InputMaybe; + cumulative_extrinsics_count?: InputMaybe; + cumulative_reward_value?: InputMaybe; + cumulative_rewards_count?: InputMaybe; + cumulative_transfer_value?: InputMaybe; + cumulative_transfers_count?: InputMaybe; + cumulative_vote_reward_value?: InputMaybe; + cumulative_vote_rewards_count?: InputMaybe; events?: InputMaybe; events_aggregate?: InputMaybe; events_count?: InputMaybe; @@ -1015,19 +1087,39 @@ export type Consensus_Blocks_Bool_Exp = { logs?: InputMaybe; logs_aggregate?: InputMaybe; parent_hash?: InputMaybe; + reward_value?: InputMaybe; + rewards_count?: InputMaybe; sort_id?: InputMaybe; space_pledged?: InputMaybe; spec_id?: InputMaybe; state_root?: InputMaybe; timestamp?: InputMaybe; + transfer_value?: InputMaybe; + transfers_count?: InputMaybe; uuid?: InputMaybe; + vote_reward_value?: InputMaybe; + vote_rewards_count?: InputMaybe; }; /** aggregate max on columns */ export type Consensus_Blocks_Max_Fields = { __typename?: 'consensus_blocks_max_fields'; + accounts_count?: Maybe; author_id?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; extrinsics_root?: Maybe; @@ -1035,19 +1127,39 @@ export type Consensus_Blocks_Max_Fields = { height?: Maybe; id?: Maybe; parent_hash?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; sort_id?: Maybe; space_pledged?: Maybe; spec_id?: Maybe; state_root?: Maybe; timestamp?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; uuid?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** aggregate min on columns */ export type Consensus_Blocks_Min_Fields = { __typename?: 'consensus_blocks_min_fields'; + accounts_count?: Maybe; author_id?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; extrinsics_root?: Maybe; @@ -1055,19 +1167,40 @@ export type Consensus_Blocks_Min_Fields = { height?: Maybe; id?: Maybe; parent_hash?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; sort_id?: Maybe; space_pledged?: Maybe; spec_id?: Maybe; state_root?: Maybe; timestamp?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; uuid?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** Ordering options when selecting data from "consensus.blocks". */ export type Consensus_Blocks_Order_By = { _block_range?: InputMaybe; + accounts_count?: InputMaybe; author_id?: InputMaybe; + block_reward_value?: InputMaybe; + block_rewards_count?: InputMaybe; blockchain_size?: InputMaybe; + cids_aggregate?: InputMaybe; + cumulative_accounts_count?: InputMaybe; + cumulative_block_reward_value?: InputMaybe; + cumulative_block_rewards_count?: InputMaybe; + cumulative_events_count?: InputMaybe; + cumulative_extrinsics_count?: InputMaybe; + cumulative_reward_value?: InputMaybe; + cumulative_rewards_count?: InputMaybe; + cumulative_transfer_value?: InputMaybe; + cumulative_transfers_count?: InputMaybe; + cumulative_vote_reward_value?: InputMaybe; + cumulative_vote_rewards_count?: InputMaybe; events_aggregate?: InputMaybe; events_count?: InputMaybe; extrinsics_aggregate?: InputMaybe; @@ -1078,12 +1211,18 @@ export type Consensus_Blocks_Order_By = { id?: InputMaybe; logs_aggregate?: InputMaybe; parent_hash?: InputMaybe; + reward_value?: InputMaybe; + rewards_count?: InputMaybe; sort_id?: InputMaybe; space_pledged?: InputMaybe; spec_id?: InputMaybe; state_root?: InputMaybe; timestamp?: InputMaybe; + transfer_value?: InputMaybe; + transfers_count?: InputMaybe; uuid?: InputMaybe; + vote_reward_value?: InputMaybe; + vote_rewards_count?: InputMaybe; }; /** select columns of table "consensus.blocks" */ @@ -1091,10 +1230,38 @@ export enum Consensus_Blocks_Select_Column { /** column name */ BlockRange = '_block_range', /** column name */ + AccountsCount = 'accounts_count', + /** column name */ AuthorId = 'author_id', /** column name */ + BlockRewardValue = 'block_reward_value', + /** column name */ + BlockRewardsCount = 'block_rewards_count', + /** column name */ BlockchainSize = 'blockchain_size', /** column name */ + CumulativeAccountsCount = 'cumulative_accounts_count', + /** column name */ + CumulativeBlockRewardValue = 'cumulative_block_reward_value', + /** column name */ + CumulativeBlockRewardsCount = 'cumulative_block_rewards_count', + /** column name */ + CumulativeEventsCount = 'cumulative_events_count', + /** column name */ + CumulativeExtrinsicsCount = 'cumulative_extrinsics_count', + /** column name */ + CumulativeRewardValue = 'cumulative_reward_value', + /** column name */ + CumulativeRewardsCount = 'cumulative_rewards_count', + /** column name */ + CumulativeTransferValue = 'cumulative_transfer_value', + /** column name */ + CumulativeTransfersCount = 'cumulative_transfers_count', + /** column name */ + CumulativeVoteRewardValue = 'cumulative_vote_reward_value', + /** column name */ + CumulativeVoteRewardsCount = 'cumulative_vote_rewards_count', + /** column name */ EventsCount = 'events_count', /** column name */ ExtrinsicsCount = 'extrinsics_count', @@ -1109,6 +1276,10 @@ export enum Consensus_Blocks_Select_Column { /** column name */ ParentHash = 'parent_hash', /** column name */ + RewardValue = 'reward_value', + /** column name */ + RewardsCount = 'rewards_count', + /** column name */ SortId = 'sort_id', /** column name */ SpacePledged = 'space_pledged', @@ -1119,37 +1290,105 @@ export enum Consensus_Blocks_Select_Column { /** column name */ Timestamp = 'timestamp', /** column name */ - Uuid = 'uuid' + TransferValue = 'transfer_value', + /** column name */ + TransfersCount = 'transfers_count', + /** column name */ + Uuid = 'uuid', + /** column name */ + VoteRewardValue = 'vote_reward_value', + /** column name */ + VoteRewardsCount = 'vote_rewards_count' } /** aggregate stddev on columns */ export type Consensus_Blocks_Stddev_Fields = { __typename?: 'consensus_blocks_stddev_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** aggregate stddev_pop on columns */ export type Consensus_Blocks_Stddev_Pop_Fields = { __typename?: 'consensus_blocks_stddev_pop_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** aggregate stddev_samp on columns */ export type Consensus_Blocks_Stddev_Samp_Fields = { __typename?: 'consensus_blocks_stddev_samp_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** Streaming cursor of the table "consensus_blocks" */ @@ -1163,8 +1402,22 @@ export type Consensus_Blocks_Stream_Cursor_Input = { /** Initial value of the column from where the streaming should start */ export type Consensus_Blocks_Stream_Cursor_Value_Input = { _block_range?: InputMaybe; + accounts_count?: InputMaybe; author_id?: InputMaybe; + block_reward_value?: InputMaybe; + block_rewards_count?: InputMaybe; blockchain_size?: InputMaybe; + cumulative_accounts_count?: InputMaybe; + cumulative_block_reward_value?: InputMaybe; + cumulative_block_rewards_count?: InputMaybe; + cumulative_events_count?: InputMaybe; + cumulative_extrinsics_count?: InputMaybe; + cumulative_reward_value?: InputMaybe; + cumulative_rewards_count?: InputMaybe; + cumulative_transfer_value?: InputMaybe; + cumulative_transfers_count?: InputMaybe; + cumulative_vote_reward_value?: InputMaybe; + cumulative_vote_rewards_count?: InputMaybe; events_count?: InputMaybe; extrinsics_count?: InputMaybe; extrinsics_root?: InputMaybe; @@ -1172,52 +1425,138 @@ export type Consensus_Blocks_Stream_Cursor_Value_Input = { height?: InputMaybe; id?: InputMaybe; parent_hash?: InputMaybe; + reward_value?: InputMaybe; + rewards_count?: InputMaybe; sort_id?: InputMaybe; space_pledged?: InputMaybe; spec_id?: InputMaybe; state_root?: InputMaybe; timestamp?: InputMaybe; + transfer_value?: InputMaybe; + transfers_count?: InputMaybe; uuid?: InputMaybe; + vote_reward_value?: InputMaybe; + vote_rewards_count?: InputMaybe; }; /** aggregate sum on columns */ export type Consensus_Blocks_Sum_Fields = { __typename?: 'consensus_blocks_sum_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** aggregate var_pop on columns */ export type Consensus_Blocks_Var_Pop_Fields = { __typename?: 'consensus_blocks_var_pop_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** aggregate var_samp on columns */ export type Consensus_Blocks_Var_Samp_Fields = { __typename?: 'consensus_blocks_var_samp_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** aggregate variance on columns */ export type Consensus_Blocks_Variance_Fields = { __typename?: 'consensus_blocks_variance_fields'; + accounts_count?: Maybe; + block_reward_value?: Maybe; + block_rewards_count?: Maybe; blockchain_size?: Maybe; + cumulative_accounts_count?: Maybe; + cumulative_block_reward_value?: Maybe; + cumulative_block_rewards_count?: Maybe; + cumulative_events_count?: Maybe; + cumulative_extrinsics_count?: Maybe; + cumulative_reward_value?: Maybe; + cumulative_rewards_count?: Maybe; + cumulative_transfer_value?: Maybe; + cumulative_transfers_count?: Maybe; + cumulative_vote_reward_value?: Maybe; + cumulative_vote_rewards_count?: Maybe; events_count?: Maybe; extrinsics_count?: Maybe; height?: Maybe; + reward_value?: Maybe; + rewards_count?: Maybe; space_pledged?: Maybe; + transfer_value?: Maybe; + transfers_count?: Maybe; + vote_reward_value?: Maybe; + vote_rewards_count?: Maybe; }; /** columns and relationships of "consensus.event_modules" */ @@ -1232,6 +1571,7 @@ export type Consensus_Event_Modules = { method: Scalars['String']['output']; /** An object relationship */ module_section?: Maybe; + name: Scalars['String']['output']; section: Scalars['String']['output']; uuid: Scalars['uuid']['output']; }; @@ -1307,6 +1647,7 @@ export type Consensus_Event_Modules_Bool_Exp = { id?: InputMaybe; method?: InputMaybe; module_section?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1316,6 +1657,7 @@ export type Consensus_Event_Modules_Max_Fields = { __typename?: 'consensus_event_modules_max_fields'; id?: Maybe; method?: Maybe; + name?: Maybe; section?: Maybe; uuid?: Maybe; }; @@ -1324,6 +1666,7 @@ export type Consensus_Event_Modules_Max_Fields = { export type Consensus_Event_Modules_Max_Order_By = { id?: InputMaybe; method?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1333,6 +1676,7 @@ export type Consensus_Event_Modules_Min_Fields = { __typename?: 'consensus_event_modules_min_fields'; id?: Maybe; method?: Maybe; + name?: Maybe; section?: Maybe; uuid?: Maybe; }; @@ -1341,6 +1685,7 @@ export type Consensus_Event_Modules_Min_Fields = { export type Consensus_Event_Modules_Min_Order_By = { id?: InputMaybe; method?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1352,6 +1697,7 @@ export type Consensus_Event_Modules_Order_By = { id?: InputMaybe; method?: InputMaybe; module_section?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1365,6 +1711,8 @@ export enum Consensus_Event_Modules_Select_Column { /** column name */ Method = 'method', /** column name */ + Name = 'name', + /** column name */ Section = 'section', /** column name */ Uuid = 'uuid' @@ -1383,6 +1731,7 @@ export type Consensus_Event_Modules_Stream_Cursor_Value_Input = { _block_range?: InputMaybe; id?: InputMaybe; method?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1396,6 +1745,7 @@ export type Consensus_Events = { block?: Maybe; block_hash: Scalars['String']['output']; block_height: Scalars['numeric']['output']; + cid?: Maybe; /** An object relationship */ event_module?: Maybe; /** An object relationship */ @@ -1495,6 +1845,7 @@ export type Consensus_Events_Bool_Exp = { block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; event_module?: InputMaybe; extrinsic?: InputMaybe; extrinsic_hash?: InputMaybe; @@ -1517,6 +1868,7 @@ export type Consensus_Events_Max_Fields = { args?: Maybe; block_hash?: Maybe; block_height?: Maybe; + cid?: Maybe; extrinsic_hash?: Maybe; extrinsic_id?: Maybe; id?: Maybe; @@ -1536,6 +1888,7 @@ export type Consensus_Events_Max_Order_By = { args?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; extrinsic_hash?: InputMaybe; extrinsic_id?: InputMaybe; id?: InputMaybe; @@ -1556,6 +1909,7 @@ export type Consensus_Events_Min_Fields = { args?: Maybe; block_hash?: Maybe; block_height?: Maybe; + cid?: Maybe; extrinsic_hash?: Maybe; extrinsic_id?: Maybe; id?: Maybe; @@ -1575,6 +1929,7 @@ export type Consensus_Events_Min_Order_By = { args?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; extrinsic_hash?: InputMaybe; extrinsic_id?: InputMaybe; id?: InputMaybe; @@ -1596,6 +1951,7 @@ export type Consensus_Events_Order_By = { block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; event_module?: InputMaybe; extrinsic?: InputMaybe; extrinsic_hash?: InputMaybe; @@ -1623,6 +1979,8 @@ export enum Consensus_Events_Select_Column { /** column name */ BlockHeight = 'block_height', /** column name */ + Cid = 'cid', + /** column name */ ExtrinsicHash = 'extrinsic_hash', /** column name */ ExtrinsicId = 'extrinsic_id', @@ -1707,6 +2065,7 @@ export type Consensus_Events_Stream_Cursor_Value_Input = { args?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; extrinsic_hash?: InputMaybe; extrinsic_id?: InputMaybe; id?: InputMaybe; @@ -1793,6 +2152,7 @@ export type Consensus_Extrinsic_Modules = { method: Scalars['String']['output']; /** An object relationship */ module_section?: Maybe; + name: Scalars['String']['output']; section: Scalars['String']['output']; uuid: Scalars['uuid']['output']; }; @@ -1868,6 +2228,7 @@ export type Consensus_Extrinsic_Modules_Bool_Exp = { id?: InputMaybe; method?: InputMaybe; module_section?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1877,6 +2238,7 @@ export type Consensus_Extrinsic_Modules_Max_Fields = { __typename?: 'consensus_extrinsic_modules_max_fields'; id?: Maybe; method?: Maybe; + name?: Maybe; section?: Maybe; uuid?: Maybe; }; @@ -1885,6 +2247,7 @@ export type Consensus_Extrinsic_Modules_Max_Fields = { export type Consensus_Extrinsic_Modules_Max_Order_By = { id?: InputMaybe; method?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1894,6 +2257,7 @@ export type Consensus_Extrinsic_Modules_Min_Fields = { __typename?: 'consensus_extrinsic_modules_min_fields'; id?: Maybe; method?: Maybe; + name?: Maybe; section?: Maybe; uuid?: Maybe; }; @@ -1902,6 +2266,7 @@ export type Consensus_Extrinsic_Modules_Min_Fields = { export type Consensus_Extrinsic_Modules_Min_Order_By = { id?: InputMaybe; method?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1913,6 +2278,7 @@ export type Consensus_Extrinsic_Modules_Order_By = { id?: InputMaybe; method?: InputMaybe; module_section?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1926,6 +2292,8 @@ export enum Consensus_Extrinsic_Modules_Select_Column { /** column name */ Method = 'method', /** column name */ + Name = 'name', + /** column name */ Section = 'section', /** column name */ Uuid = 'uuid' @@ -1944,6 +2312,7 @@ export type Consensus_Extrinsic_Modules_Stream_Cursor_Value_Input = { _block_range?: InputMaybe; id?: InputMaybe; method?: InputMaybe; + name?: InputMaybe; section?: InputMaybe; uuid?: InputMaybe; }; @@ -1957,6 +2326,11 @@ export type Consensus_Extrinsics = { block?: Maybe; block_hash: Scalars['String']['output']; block_height: Scalars['numeric']['output']; + cid?: Maybe; + /** An array relationship */ + cids: Array; + /** An aggregate relationship */ + cids_aggregate: Files_Cids_Aggregate; error: Scalars['String']['output']; /** An array relationship */ events: Array; @@ -1983,6 +2357,26 @@ export type Consensus_Extrinsics = { }; +/** columns and relationships of "consensus.extrinsics" */ +export type Consensus_ExtrinsicsCidsArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + +/** columns and relationships of "consensus.extrinsics" */ +export type Consensus_ExtrinsicsCids_AggregateArgs = { + distinct_on?: InputMaybe>; + limit?: InputMaybe; + offset?: InputMaybe; + order_by?: InputMaybe>; + where?: InputMaybe; +}; + + /** columns and relationships of "consensus.extrinsics" */ export type Consensus_ExtrinsicsEventsArgs = { distinct_on?: InputMaybe>; @@ -2105,6 +2499,9 @@ export type Consensus_Extrinsics_Bool_Exp = { block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; + cids?: InputMaybe; + cids_aggregate?: InputMaybe; error?: InputMaybe; events?: InputMaybe; events_aggregate?: InputMaybe; @@ -2133,6 +2530,7 @@ export type Consensus_Extrinsics_Max_Fields = { args?: Maybe; block_hash?: Maybe; block_height?: Maybe; + cid?: Maybe; error?: Maybe; fee?: Maybe; hash?: Maybe; @@ -2156,6 +2554,7 @@ export type Consensus_Extrinsics_Max_Order_By = { args?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; error?: InputMaybe; fee?: InputMaybe; hash?: InputMaybe; @@ -2180,6 +2579,7 @@ export type Consensus_Extrinsics_Min_Fields = { args?: Maybe; block_hash?: Maybe; block_height?: Maybe; + cid?: Maybe; error?: Maybe; fee?: Maybe; hash?: Maybe; @@ -2203,6 +2603,7 @@ export type Consensus_Extrinsics_Min_Order_By = { args?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; error?: InputMaybe; fee?: InputMaybe; hash?: InputMaybe; @@ -2228,6 +2629,8 @@ export type Consensus_Extrinsics_Order_By = { block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; + cids_aggregate?: InputMaybe; error?: InputMaybe; events_aggregate?: InputMaybe; extrinsic_module?: InputMaybe; @@ -2260,6 +2663,8 @@ export enum Consensus_Extrinsics_Select_Column { /** column name */ BlockHeight = 'block_height', /** column name */ + Cid = 'cid', + /** column name */ Error = 'error', /** column name */ Fee = 'fee', @@ -2384,6 +2789,7 @@ export type Consensus_Extrinsics_Stream_Cursor_Value_Input = { args?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + cid?: InputMaybe; error?: InputMaybe; fee?: InputMaybe; hash?: InputMaybe; @@ -2492,6 +2898,7 @@ export type Consensus_Log_Kinds = { __typename?: 'consensus_log_kinds'; _block_range: Scalars['int8range']['output']; id: Scalars['String']['output']; + kind: Scalars['String']['output']; /** An array relationship */ logs: Array; /** An aggregate relationship */ @@ -2548,6 +2955,7 @@ export type Consensus_Log_Kinds_Bool_Exp = { _not?: InputMaybe; _or?: InputMaybe>; id?: InputMaybe; + kind?: InputMaybe; logs?: InputMaybe; logs_aggregate?: InputMaybe; uuid?: InputMaybe; @@ -2557,6 +2965,7 @@ export type Consensus_Log_Kinds_Bool_Exp = { export type Consensus_Log_Kinds_Max_Fields = { __typename?: 'consensus_log_kinds_max_fields'; id?: Maybe; + kind?: Maybe; uuid?: Maybe; }; @@ -2564,6 +2973,7 @@ export type Consensus_Log_Kinds_Max_Fields = { export type Consensus_Log_Kinds_Min_Fields = { __typename?: 'consensus_log_kinds_min_fields'; id?: Maybe; + kind?: Maybe; uuid?: Maybe; }; @@ -2571,6 +2981,7 @@ export type Consensus_Log_Kinds_Min_Fields = { export type Consensus_Log_Kinds_Order_By = { _block_range?: InputMaybe; id?: InputMaybe; + kind?: InputMaybe; logs_aggregate?: InputMaybe; uuid?: InputMaybe; }; @@ -2582,6 +2993,8 @@ export enum Consensus_Log_Kinds_Select_Column { /** column name */ Id = 'id', /** column name */ + Kind = 'kind', + /** column name */ Uuid = 'uuid' } @@ -2597,6 +3010,7 @@ export type Consensus_Log_Kinds_Stream_Cursor_Input = { export type Consensus_Log_Kinds_Stream_Cursor_Value_Input = { _block_range?: InputMaybe; id?: InputMaybe; + kind?: InputMaybe; uuid?: InputMaybe; }; @@ -2926,8 +3340,9 @@ export type Consensus_Rewards = { block?: Maybe; block_hash: Scalars['String']['output']; block_height: Scalars['numeric']['output']; + event_id: Scalars['String']['output']; + extrinsic_id: Scalars['String']['output']; id: Scalars['String']['output']; - index_in_block: Scalars['numeric']['output']; reward_type: Scalars['String']['output']; timestamp: Scalars['timestamp']['output']; uuid: Scalars['uuid']['output']; @@ -2994,14 +3409,12 @@ export type Consensus_Rewards_Avg_Fields = { __typename?: 'consensus_rewards_avg_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by avg() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Avg_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** Boolean expression to filter rows from the table "consensus.rewards". All fields are combined with a logical 'AND'. */ @@ -3016,8 +3429,9 @@ export type Consensus_Rewards_Bool_Exp = { block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + event_id?: InputMaybe; + extrinsic_id?: InputMaybe; id?: InputMaybe; - index_in_block?: InputMaybe; reward_type?: InputMaybe; timestamp?: InputMaybe; uuid?: InputMaybe; @@ -3030,8 +3444,9 @@ export type Consensus_Rewards_Max_Fields = { amount?: Maybe; block_hash?: Maybe; block_height?: Maybe; + event_id?: Maybe; + extrinsic_id?: Maybe; id?: Maybe; - index_in_block?: Maybe; reward_type?: Maybe; timestamp?: Maybe; uuid?: Maybe; @@ -3043,8 +3458,9 @@ export type Consensus_Rewards_Max_Order_By = { amount?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + event_id?: InputMaybe; + extrinsic_id?: InputMaybe; id?: InputMaybe; - index_in_block?: InputMaybe; reward_type?: InputMaybe; timestamp?: InputMaybe; uuid?: InputMaybe; @@ -3057,8 +3473,9 @@ export type Consensus_Rewards_Min_Fields = { amount?: Maybe; block_hash?: Maybe; block_height?: Maybe; + event_id?: Maybe; + extrinsic_id?: Maybe; id?: Maybe; - index_in_block?: Maybe; reward_type?: Maybe; timestamp?: Maybe; uuid?: Maybe; @@ -3070,8 +3487,9 @@ export type Consensus_Rewards_Min_Order_By = { amount?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + event_id?: InputMaybe; + extrinsic_id?: InputMaybe; id?: InputMaybe; - index_in_block?: InputMaybe; reward_type?: InputMaybe; timestamp?: InputMaybe; uuid?: InputMaybe; @@ -3086,8 +3504,9 @@ export type Consensus_Rewards_Order_By = { block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + event_id?: InputMaybe; + extrinsic_id?: InputMaybe; id?: InputMaybe; - index_in_block?: InputMaybe; reward_type?: InputMaybe; timestamp?: InputMaybe; uuid?: InputMaybe; @@ -3106,9 +3525,11 @@ export enum Consensus_Rewards_Select_Column { /** column name */ BlockHeight = 'block_height', /** column name */ - Id = 'id', + EventId = 'event_id', /** column name */ - IndexInBlock = 'index_in_block', + ExtrinsicId = 'extrinsic_id', + /** column name */ + Id = 'id', /** column name */ RewardType = 'reward_type', /** column name */ @@ -3122,14 +3543,12 @@ export type Consensus_Rewards_Stddev_Fields = { __typename?: 'consensus_rewards_stddev_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by stddev() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Stddev_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** aggregate stddev_pop on columns */ @@ -3137,14 +3556,12 @@ export type Consensus_Rewards_Stddev_Pop_Fields = { __typename?: 'consensus_rewards_stddev_pop_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by stddev_pop() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Stddev_Pop_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** aggregate stddev_samp on columns */ @@ -3152,14 +3569,12 @@ export type Consensus_Rewards_Stddev_Samp_Fields = { __typename?: 'consensus_rewards_stddev_samp_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by stddev_samp() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Stddev_Samp_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** Streaming cursor of the table "consensus_rewards" */ @@ -3177,8 +3592,9 @@ export type Consensus_Rewards_Stream_Cursor_Value_Input = { amount?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; + event_id?: InputMaybe; + extrinsic_id?: InputMaybe; id?: InputMaybe; - index_in_block?: InputMaybe; reward_type?: InputMaybe; timestamp?: InputMaybe; uuid?: InputMaybe; @@ -3189,14 +3605,12 @@ export type Consensus_Rewards_Sum_Fields = { __typename?: 'consensus_rewards_sum_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by sum() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Sum_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** aggregate var_pop on columns */ @@ -3204,14 +3618,12 @@ export type Consensus_Rewards_Var_Pop_Fields = { __typename?: 'consensus_rewards_var_pop_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by var_pop() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Var_Pop_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** aggregate var_samp on columns */ @@ -3219,14 +3631,12 @@ export type Consensus_Rewards_Var_Samp_Fields = { __typename?: 'consensus_rewards_var_samp_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by var_samp() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Var_Samp_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** aggregate variance on columns */ @@ -3234,14 +3644,12 @@ export type Consensus_Rewards_Variance_Fields = { __typename?: 'consensus_rewards_variance_fields'; amount?: Maybe; block_height?: Maybe; - index_in_block?: Maybe; }; /** order by variance() on columns of table "consensus.rewards" */ export type Consensus_Rewards_Variance_Order_By = { amount?: InputMaybe; block_height?: InputMaybe; - index_in_block?: InputMaybe; }; /** columns and relationships of "consensus.sections" */ @@ -3257,6 +3665,7 @@ export type Consensus_Sections = { /** An aggregate relationship */ extrinsic_modules_aggregate: Consensus_Extrinsic_Modules_Aggregate; id: Scalars['String']['output']; + section: Scalars['String']['output']; uuid: Scalars['uuid']['output']; }; @@ -3333,6 +3742,7 @@ export type Consensus_Sections_Bool_Exp = { extrinsic_modules?: InputMaybe; extrinsic_modules_aggregate?: InputMaybe; id?: InputMaybe; + section?: InputMaybe; uuid?: InputMaybe; }; @@ -3340,6 +3750,7 @@ export type Consensus_Sections_Bool_Exp = { export type Consensus_Sections_Max_Fields = { __typename?: 'consensus_sections_max_fields'; id?: Maybe; + section?: Maybe; uuid?: Maybe; }; @@ -3347,6 +3758,7 @@ export type Consensus_Sections_Max_Fields = { export type Consensus_Sections_Min_Fields = { __typename?: 'consensus_sections_min_fields'; id?: Maybe; + section?: Maybe; uuid?: Maybe; }; @@ -3356,6 +3768,7 @@ export type Consensus_Sections_Order_By = { event_modules_aggregate?: InputMaybe; extrinsic_modules_aggregate?: InputMaybe; id?: InputMaybe; + section?: InputMaybe; uuid?: InputMaybe; }; @@ -3366,6 +3779,8 @@ export enum Consensus_Sections_Select_Column { /** column name */ Id = 'id', /** column name */ + Section = 'section', + /** column name */ Uuid = 'uuid' } @@ -3381,6 +3796,7 @@ export type Consensus_Sections_Stream_Cursor_Input = { export type Consensus_Sections_Stream_Cursor_Value_Input = { _block_range?: InputMaybe; id?: InputMaybe; + section?: InputMaybe; uuid?: InputMaybe; }; @@ -3388,15 +3804,15 @@ export type Consensus_Sections_Stream_Cursor_Value_Input = { export type Consensus_Transfers = { __typename?: 'consensus_transfers'; _block_range: Scalars['int8range']['output']; - created_at: Scalars['numeric']['output']; - date: Scalars['timestamp']['output']; + block_hash: Scalars['String']['output']; + block_height: Scalars['numeric']['output']; event_id: Scalars['String']['output']; extrinsic_id: Scalars['String']['output']; fee: Scalars['numeric']['output']; from: Scalars['String']['output']; id: Scalars['String']['output']; success: Scalars['Boolean']['output']; - timestamp: Scalars['numeric']['output']; + timestamp: Scalars['timestamp']['output']; to: Scalars['String']['output']; uuid: Scalars['uuid']['output']; value: Scalars['numeric']['output']; @@ -3435,9 +3851,8 @@ export type Consensus_Transfers_Aggregate_FieldsCountArgs = { /** aggregate avg on columns */ export type Consensus_Transfers_Avg_Fields = { __typename?: 'consensus_transfers_avg_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; @@ -3447,15 +3862,15 @@ export type Consensus_Transfers_Bool_Exp = { _block_range?: InputMaybe; _not?: InputMaybe; _or?: InputMaybe>; - created_at?: InputMaybe; - date?: InputMaybe; + block_hash?: InputMaybe; + block_height?: InputMaybe; event_id?: InputMaybe; extrinsic_id?: InputMaybe; fee?: InputMaybe; from?: InputMaybe; id?: InputMaybe; success?: InputMaybe; - timestamp?: InputMaybe; + timestamp?: InputMaybe; to?: InputMaybe; uuid?: InputMaybe; value?: InputMaybe; @@ -3464,14 +3879,14 @@ export type Consensus_Transfers_Bool_Exp = { /** aggregate max on columns */ export type Consensus_Transfers_Max_Fields = { __typename?: 'consensus_transfers_max_fields'; - created_at?: Maybe; - date?: Maybe; + block_hash?: Maybe; + block_height?: Maybe; event_id?: Maybe; extrinsic_id?: Maybe; fee?: Maybe; from?: Maybe; id?: Maybe; - timestamp?: Maybe; + timestamp?: Maybe; to?: Maybe; uuid?: Maybe; value?: Maybe; @@ -3480,14 +3895,14 @@ export type Consensus_Transfers_Max_Fields = { /** aggregate min on columns */ export type Consensus_Transfers_Min_Fields = { __typename?: 'consensus_transfers_min_fields'; - created_at?: Maybe; - date?: Maybe; + block_hash?: Maybe; + block_height?: Maybe; event_id?: Maybe; extrinsic_id?: Maybe; fee?: Maybe; from?: Maybe; id?: Maybe; - timestamp?: Maybe; + timestamp?: Maybe; to?: Maybe; uuid?: Maybe; value?: Maybe; @@ -3496,8 +3911,8 @@ export type Consensus_Transfers_Min_Fields = { /** Ordering options when selecting data from "consensus.transfers". */ export type Consensus_Transfers_Order_By = { _block_range?: InputMaybe; - created_at?: InputMaybe; - date?: InputMaybe; + block_hash?: InputMaybe; + block_height?: InputMaybe; event_id?: InputMaybe; extrinsic_id?: InputMaybe; fee?: InputMaybe; @@ -3515,9 +3930,9 @@ export enum Consensus_Transfers_Select_Column { /** column name */ BlockRange = '_block_range', /** column name */ - CreatedAt = 'created_at', + BlockHash = 'block_hash', /** column name */ - Date = 'date', + BlockHeight = 'block_height', /** column name */ EventId = 'event_id', /** column name */ @@ -3543,27 +3958,24 @@ export enum Consensus_Transfers_Select_Column { /** aggregate stddev on columns */ export type Consensus_Transfers_Stddev_Fields = { __typename?: 'consensus_transfers_stddev_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; /** aggregate stddev_pop on columns */ export type Consensus_Transfers_Stddev_Pop_Fields = { __typename?: 'consensus_transfers_stddev_pop_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; /** aggregate stddev_samp on columns */ export type Consensus_Transfers_Stddev_Samp_Fields = { __typename?: 'consensus_transfers_stddev_samp_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; @@ -3578,15 +3990,15 @@ export type Consensus_Transfers_Stream_Cursor_Input = { /** Initial value of the column from where the streaming should start */ export type Consensus_Transfers_Stream_Cursor_Value_Input = { _block_range?: InputMaybe; - created_at?: InputMaybe; - date?: InputMaybe; + block_hash?: InputMaybe; + block_height?: InputMaybe; event_id?: InputMaybe; extrinsic_id?: InputMaybe; fee?: InputMaybe; from?: InputMaybe; id?: InputMaybe; success?: InputMaybe; - timestamp?: InputMaybe; + timestamp?: InputMaybe; to?: InputMaybe; uuid?: InputMaybe; value?: InputMaybe; @@ -3595,36 +4007,32 @@ export type Consensus_Transfers_Stream_Cursor_Value_Input = { /** aggregate sum on columns */ export type Consensus_Transfers_Sum_Fields = { __typename?: 'consensus_transfers_sum_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; /** aggregate var_pop on columns */ export type Consensus_Transfers_Var_Pop_Fields = { __typename?: 'consensus_transfers_var_pop_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; /** aggregate var_samp on columns */ export type Consensus_Transfers_Var_Samp_Fields = { __typename?: 'consensus_transfers_var_samp_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; /** aggregate variance on columns */ export type Consensus_Transfers_Variance_Fields = { __typename?: 'consensus_transfers_variance_fields'; - created_at?: Maybe; + block_height?: Maybe; fee?: Maybe; - timestamp?: Maybe; value?: Maybe; }; @@ -3904,10 +4312,14 @@ export type Files_Chunks_Stream_Cursor_Value_Input = { export type Files_Cids = { __typename?: 'files_cids'; _block_range: Scalars['int8range']['output']; + /** An object relationship */ + block?: Maybe; block_hash: Scalars['String']['output']; block_height: Scalars['numeric']['output']; /** An object relationship */ chunk?: Maybe; + /** An object relationship */ + extrinsic?: Maybe; extrinsic_hash: Scalars['String']['output']; extrinsic_id: Scalars['String']['output']; id: Scalars['String']['output']; @@ -3930,6 +4342,17 @@ export type Files_Cids_Aggregate = { nodes: Array; }; +export type Files_Cids_Aggregate_Bool_Exp = { + count?: InputMaybe; +}; + +export type Files_Cids_Aggregate_Bool_Exp_Count = { + arguments?: InputMaybe>; + distinct?: InputMaybe; + filter?: InputMaybe; + predicate: Int_Comparison_Exp; +}; + /** aggregate fields of "files.cids" */ export type Files_Cids_Aggregate_Fields = { __typename?: 'files_cids_aggregate_fields'; @@ -3953,6 +4376,21 @@ export type Files_Cids_Aggregate_FieldsCountArgs = { distinct?: InputMaybe; }; +/** order by aggregate values of table "files.cids" */ +export type Files_Cids_Aggregate_Order_By = { + avg?: InputMaybe; + count?: InputMaybe; + max?: InputMaybe; + min?: InputMaybe; + stddev?: InputMaybe; + stddev_pop?: InputMaybe; + stddev_samp?: InputMaybe; + sum?: InputMaybe; + var_pop?: InputMaybe; + var_samp?: InputMaybe; + variance?: InputMaybe; +}; + /** aggregate avg on columns */ export type Files_Cids_Avg_Fields = { __typename?: 'files_cids_avg_fields'; @@ -3960,15 +4398,23 @@ export type Files_Cids_Avg_Fields = { index_in_block?: Maybe; }; +/** order by avg() on columns of table "files.cids" */ +export type Files_Cids_Avg_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** Boolean expression to filter rows from the table "files.cids". All fields are combined with a logical 'AND'. */ export type Files_Cids_Bool_Exp = { _and?: InputMaybe>; _block_range?: InputMaybe; _not?: InputMaybe; _or?: InputMaybe>; + block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; chunk?: InputMaybe; + extrinsic?: InputMaybe; extrinsic_hash?: InputMaybe; extrinsic_id?: InputMaybe; id?: InputMaybe; @@ -3991,6 +4437,18 @@ export type Files_Cids_Max_Fields = { uuid?: Maybe; }; +/** order by max() on columns of table "files.cids" */ +export type Files_Cids_Max_Order_By = { + block_hash?: InputMaybe; + block_height?: InputMaybe; + extrinsic_hash?: InputMaybe; + extrinsic_id?: InputMaybe; + id?: InputMaybe; + index_in_block?: InputMaybe; + timestamp?: InputMaybe; + uuid?: InputMaybe; +}; + /** aggregate min on columns */ export type Files_Cids_Min_Fields = { __typename?: 'files_cids_min_fields'; @@ -4004,12 +4462,26 @@ export type Files_Cids_Min_Fields = { uuid?: Maybe; }; +/** order by min() on columns of table "files.cids" */ +export type Files_Cids_Min_Order_By = { + block_hash?: InputMaybe; + block_height?: InputMaybe; + extrinsic_hash?: InputMaybe; + extrinsic_id?: InputMaybe; + id?: InputMaybe; + index_in_block?: InputMaybe; + timestamp?: InputMaybe; + uuid?: InputMaybe; +}; + /** Ordering options when selecting data from "files.cids". */ export type Files_Cids_Order_By = { _block_range?: InputMaybe; + block?: InputMaybe; block_hash?: InputMaybe; block_height?: InputMaybe; chunk?: InputMaybe; + extrinsic?: InputMaybe; extrinsic_hash?: InputMaybe; extrinsic_id?: InputMaybe; id?: InputMaybe; @@ -4050,6 +4522,12 @@ export type Files_Cids_Stddev_Fields = { index_in_block?: Maybe; }; +/** order by stddev() on columns of table "files.cids" */ +export type Files_Cids_Stddev_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** aggregate stddev_pop on columns */ export type Files_Cids_Stddev_Pop_Fields = { __typename?: 'files_cids_stddev_pop_fields'; @@ -4057,6 +4535,12 @@ export type Files_Cids_Stddev_Pop_Fields = { index_in_block?: Maybe; }; +/** order by stddev_pop() on columns of table "files.cids" */ +export type Files_Cids_Stddev_Pop_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** aggregate stddev_samp on columns */ export type Files_Cids_Stddev_Samp_Fields = { __typename?: 'files_cids_stddev_samp_fields'; @@ -4064,6 +4548,12 @@ export type Files_Cids_Stddev_Samp_Fields = { index_in_block?: Maybe; }; +/** order by stddev_samp() on columns of table "files.cids" */ +export type Files_Cids_Stddev_Samp_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** Streaming cursor of the table "files_cids" */ export type Files_Cids_Stream_Cursor_Input = { /** Stream column input with initial value */ @@ -4093,6 +4583,12 @@ export type Files_Cids_Sum_Fields = { index_in_block?: Maybe; }; +/** order by sum() on columns of table "files.cids" */ +export type Files_Cids_Sum_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** aggregate var_pop on columns */ export type Files_Cids_Var_Pop_Fields = { __typename?: 'files_cids_var_pop_fields'; @@ -4100,6 +4596,12 @@ export type Files_Cids_Var_Pop_Fields = { index_in_block?: Maybe; }; +/** order by var_pop() on columns of table "files.cids" */ +export type Files_Cids_Var_Pop_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** aggregate var_samp on columns */ export type Files_Cids_Var_Samp_Fields = { __typename?: 'files_cids_var_samp_fields'; @@ -4107,6 +4609,12 @@ export type Files_Cids_Var_Samp_Fields = { index_in_block?: Maybe; }; +/** order by var_samp() on columns of table "files.cids" */ +export type Files_Cids_Var_Samp_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** aggregate variance on columns */ export type Files_Cids_Variance_Fields = { __typename?: 'files_cids_variance_fields'; @@ -4114,6 +4622,12 @@ export type Files_Cids_Variance_Fields = { index_in_block?: Maybe; }; +/** order by variance() on columns of table "files.cids" */ +export type Files_Cids_Variance_Order_By = { + block_height?: InputMaybe; + index_in_block?: InputMaybe; +}; + /** columns and relationships of "files.file_cids" */ export type Files_File_Cids = { __typename?: 'files_file_cids'; @@ -17746,7 +18260,7 @@ export type LatestRewardsWeekQueryVariables = Exact<{ }>; -export type LatestRewardsWeekQuery = { __typename?: 'query_root', consensus_rewards: Array<{ __typename?: 'consensus_rewards', id: string, block_height: any, index_in_block: any, reward_type: string, amount: any, timestamp: any }> }; +export type LatestRewardsWeekQuery = { __typename?: 'query_root', consensus_rewards: Array<{ __typename?: 'consensus_rewards', id: string, block_height: any, reward_type: string, amount: any, timestamp: any }> }; export type RewardsListQueryVariables = Exact<{ accountId: Scalars['String']['input']; @@ -17756,7 +18270,7 @@ export type RewardsListQueryVariables = Exact<{ }>; -export type RewardsListQuery = { __typename?: 'query_root', consensus_rewards_aggregate: { __typename?: 'consensus_rewards_aggregate', aggregate?: { __typename?: 'consensus_rewards_aggregate_fields', count: number } | null }, consensus_rewards: Array<{ __typename?: 'consensus_rewards', id: string, block_height: any, index_in_block: any, reward_type: string, amount: any, timestamp: any, block?: { __typename?: 'consensus_blocks', hash: string, id: string, height: any } | null, account?: { __typename?: 'consensus_accounts', id: string, free: any, reserved: any, total?: any | null, updated_at: any } | null }> }; +export type RewardsListQuery = { __typename?: 'query_root', consensus_rewards_aggregate: { __typename?: 'consensus_rewards_aggregate', aggregate?: { __typename?: 'consensus_rewards_aggregate_fields', count: number } | null }, consensus_rewards: Array<{ __typename?: 'consensus_rewards', id: string, block_height: any, reward_type: string, amount: any, timestamp: any, block?: { __typename?: 'consensus_blocks', hash: string, id: string, height: any } | null, account?: { __typename?: 'consensus_accounts', id: string, free: any, reserved: any, total?: any | null, updated_at: any } | null }> }; export type ExtrinsicsByAccountIdQueryVariables = Exact<{ limit: Scalars['Int']['input']; @@ -17776,7 +18290,7 @@ export type TransfersByAccountIdQueryVariables = Exact<{ }>; -export type TransfersByAccountIdQuery = { __typename?: 'query_root', consensus_transfers_aggregate: { __typename?: 'consensus_transfers_aggregate', aggregate?: { __typename?: 'consensus_transfers_aggregate_fields', count: number } | null }, consensus_transfers: Array<{ __typename?: 'consensus_transfers', id: string, extrinsic_id: string, event_id: string, from: string, to: string, value: any, fee: any, success: boolean, timestamp: any, date: any, created_at: any }> }; +export type TransfersByAccountIdQuery = { __typename?: 'query_root', consensus_transfers_aggregate: { __typename?: 'consensus_transfers_aggregate', aggregate?: { __typename?: 'consensus_transfers_aggregate_fields', count: number } | null }, consensus_transfers: Array<{ __typename?: 'consensus_transfers', id: string, extrinsic_id: string, event_id: string, from: string, to: string, value: any, fee: any, success: boolean, timestamp: any, block_height: any }> }; export type BalanceHistoryByAccountIdQueryVariables = Exact<{ limit: Scalars['Int']['input']; @@ -17786,14 +18300,14 @@ export type BalanceHistoryByAccountIdQueryVariables = Exact<{ }>; -export type BalanceHistoryByAccountIdQuery = { __typename?: 'query_root', consensus_account_histories_aggregate: { __typename?: 'consensus_account_histories_aggregate', aggregate?: { __typename?: 'consensus_account_histories_aggregate_fields', count: number } | null }, consensus_account_histories: Array<{ __typename?: 'consensus_account_histories', reserved: any, total?: any | null, nonce: any, free: any, created_at: any, updated_at: any, _block_range: any, id: any }> }; +export type BalanceHistoryByAccountIdQuery = { __typename?: 'query_root', consensus_account_histories_aggregate: { __typename?: 'consensus_account_histories_aggregate', aggregate?: { __typename?: 'consensus_account_histories_aggregate_fields', count: number } | null }, consensus_account_histories: Array<{ __typename?: 'consensus_account_histories', reserved: any, total?: any | null, nonce: any, free: any, created_at: any, _block_range: any, id: any }> }; export type AllRewardForAccountByIdQueryVariables = Exact<{ accountId: Scalars['String']['input']; }>; -export type AllRewardForAccountByIdQuery = { __typename?: 'query_root', consensus_rewards: Array<{ __typename?: 'consensus_rewards', id: string, block_height: any, index_in_block: any, reward_type: string, amount: any, timestamp: any }> }; +export type AllRewardForAccountByIdQuery = { __typename?: 'query_root', consensus_rewards: Array<{ __typename?: 'consensus_rewards', id: string, block_height: any, reward_type: string, amount: any, timestamp: any }> }; export type BlocksQueryVariables = Exact<{ limit: Scalars['Int']['input']; @@ -18462,7 +18976,6 @@ export const LatestRewardsWeekDocument = gql` ) { id block_height - index_in_block reward_type amount timestamp @@ -18520,7 +19033,6 @@ export const RewardsListDocument = gql` ) { id block_height - index_in_block reward_type amount timestamp @@ -18657,8 +19169,7 @@ export const TransfersByAccountIdDocument = gql` fee success timestamp - date - created_at + block_height } } `; @@ -18717,7 +19228,6 @@ export const BalanceHistoryByAccountIdDocument = gql` nonce free created_at - updated_at _block_range } } @@ -18766,7 +19276,6 @@ export const AllRewardForAccountByIdDocument = gql` ) { id block_height - index_in_block reward_type amount timestamp diff --git a/explorer/src/components/Consensus/Account/AccountTransfersList.tsx b/explorer/src/components/Consensus/Account/AccountTransfersList.tsx index b7ca60255..a2de8c9df 100644 --- a/explorer/src/components/Consensus/Account/AccountTransfersList.tsx +++ b/explorer/src/components/Consensus/Account/AccountTransfersList.tsx @@ -40,7 +40,7 @@ type Row = TransfersByAccountIdQuery['consensus_transfers'][0] export const AccountTransfersList: FC = ({ accountId }) => { const { ref, inView } = useInView() const [sorting, setSorting] = useState([ - { id: TransferColumn.CreatedAt, desc: true }, + { id: TransferColumn.BlockHeight, desc: true }, ]) const [pagination, setPagination] = useState({ pageSize: PAGE_SIZE, @@ -121,17 +121,17 @@ export const AccountTransfersList: FC = ({ accountId }) => { header: 'Block', enableSorting: true, cell: ({ row }: Cell) => ( -
+
-
{row.original.created_at}
+
{row.original.block_height}
), @@ -236,7 +236,7 @@ export const AccountTransfersList: FC = ({ accountId }) => { enableSorting: true, cell: ({ row }: Cell) => (
- {row.original.timestamp(row.original.date)} + {row.original.timestamp(row.original.timestamp)}
), }, diff --git a/explorer/src/components/Consensus/Account/BalanceHistory.tsx b/explorer/src/components/Consensus/Account/BalanceHistory.tsx index 626cb9cdf..5c366f514 100644 --- a/explorer/src/components/Consensus/Account/BalanceHistory.tsx +++ b/explorer/src/components/Consensus/Account/BalanceHistory.tsx @@ -11,9 +11,9 @@ import { formatUnits } from 'ethers' import { BalanceHistoryByAccountIdQuery, BalanceHistoryByAccountIdQueryVariables, + Consensus_Account_Histories_Select_Column as BalanceHistoryColumn, + Consensus_Account_Histories_Bool_Exp as BalanceHistoryWhere, Order_By as OrderBy, - Consensus_Transfers_Select_Column as TransferColumn, - Consensus_Transfers_Bool_Exp as TransferWhere, } from 'gql/graphql' import useIndexers from 'hooks/useIndexers' import { useIndexersQuery } from 'hooks/useIndexersQuery' @@ -37,7 +37,7 @@ type Row = BalanceHistoryByAccountIdQuery['consensus_account_histories'][0] export const BalanceHistory: FC = ({ accountId }) => { const { ref, inView } = useInView() const [sorting, setSorting] = useState([ - { id: TransferColumn.CreatedAt, desc: true }, + { id: BalanceHistoryColumn.CreatedAt, desc: true }, ]) const [pagination, setPagination] = useState({ pageSize: PAGE_SIZE, @@ -57,7 +57,7 @@ export const BalanceHistory: FC = ({ accountId }) => { [sorting], ) - const where: TransferWhere = useMemo(() => ({ id: { _eq: accountId } }), [accountId]) + const where: BalanceHistoryWhere = useMemo(() => ({ id: { _eq: accountId } }), [accountId]) const variables = useMemo(() => { return { diff --git a/explorer/src/components/Consensus/Account/query.ts b/explorer/src/components/Consensus/Account/query.ts index a78e2cc68..46da763b1 100644 --- a/explorer/src/components/Consensus/Account/query.ts +++ b/explorer/src/components/Consensus/Account/query.ts @@ -69,7 +69,6 @@ export const QUERY_LAST_WEEK_REWARDS = gql` ) { id block_height - index_in_block reward_type amount timestamp @@ -97,7 +96,6 @@ export const QUERY_REWARDS_LIST = gql` ) { id block_height - index_in_block reward_type amount timestamp @@ -164,8 +162,7 @@ export const QUERY_ACCOUNT_TRANSFERS = gql` fee success timestamp - date - created_at + block_height } } ` @@ -189,7 +186,6 @@ export const QUERY_ACCOUNT_BALANCE_HISTORY = gql` nonce free created_at - updated_at _block_range } } @@ -200,7 +196,6 @@ export const QUERY_ALL_REWARDS_FOR_ACCOUNT_BY_ID = gql` consensus_rewards(where: { account_id: { _eq: $accountId }, amount: { _gt: 0 } }, limit: 1) { id block_height - index_in_block reward_type amount timestamp diff --git a/explorer/src/components/Storage/Files/FilePreview.tsx b/explorer/src/components/Storage/Files/FilePreview.tsx index 7b678bb91..0855e606a 100644 --- a/explorer/src/components/Storage/Files/FilePreview.tsx +++ b/explorer/src/components/Storage/Files/FilePreview.tsx @@ -1,3 +1,4 @@ +import { LockClosedIcon } from '@heroicons/react/24/outline' import { Arguments } from 'components/common/Arguments' import { Spinner } from 'components/common/Spinner' import { GetCidQuery, GetCidQueryVariables } from 'gql/graphql' @@ -16,6 +17,9 @@ type Props = { type PreviewData = { type: string data: ArrayBuffer + isEncrypted: boolean + // eslint-disable-next-line @typescript-eslint/no-explicit-any + uploadOptions: any } export const FilePreview: FC = ({ cid }) => { @@ -31,11 +35,13 @@ export const FilePreview: FC = ({ cid }) => { const fetchData = useCallback(async () => { if (data) { - const { dataArrayBuffer } = extractFileData(data) + const { dataArrayBuffer, isEncrypted, uploadOptions } = extractFileData(data) const fileType = await detectFileType(dataArrayBuffer) setRawData({ type: fileType, data: dataArrayBuffer, + isEncrypted, + uploadOptions, }) } }, [data]) @@ -60,6 +66,15 @@ export const FilePreview: FC = ({ cid }) => { if (!imageSrc) return <> switch (true) { + case rawData?.isEncrypted: + return ( +
+ +

+ No preview available for encrypted files +

+
+ ) case rawData?.type.startsWith('image'): return ( { const logKindsToUpdate: string[] = []; const addressToUpdate: string[] = []; + let eventIndex = 0; let totalBlockRewardsCount = 0; let totalVoteRewardsCount = 0; let totalTransferValue = BigInt(0); @@ -155,7 +156,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { addressToUpdate.push(extrinsicSigner); // Process extrinsic events - extrinsicEvents.forEach((event, eventIdx) => { + extrinsicEvents.forEach((event) => { const extrinsicId = extrinsic ? height + "-" + extrinsicIdx.toString() : ""; @@ -177,7 +178,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { createEvent( height, blockHash, - BigInt(eventIdx), + BigInt(eventIndex), extrinsicId, extrinsic.hash.toString(), event.event.section, @@ -206,7 +207,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { height, blockHash, extrinsicId, - height + "-" + eventIdx.toString(), + height + "-" + eventIndex, from, to, amount, @@ -218,6 +219,39 @@ export async function handleBlock(_block: SubstrateBlock): Promise { break; } + default: + break; + } + + // Increment event index + eventIndex++; + }); + + // Get finalization events + const finalizationEvents = events.filter((e) => e.phase.isFinalization); + + // Process finalization events + finalizationEvents.forEach(async (event) => { + newEvents.push( + createEvent( + height, + blockHash, + BigInt(eventIndex), + height + "-" + event.phase.type, + extrinsic.hash.toString(), + event.event.section, + event.event.method, + timestamp ? timestamp : new Date(0), + event.phase.type, + pos, + args, + cid + ) + ); + eventMethodsToUpdate.push([event.event.section, event.event.method]); + + // Process specific events + switch (`${event.event.section}.${event.event.method}`) { case "rewards.VoteReward": { const voter = event.event.data[0].toString(); const reward = BigInt(event.event.data[1].toString()); @@ -231,8 +265,8 @@ export async function handleBlock(_block: SubstrateBlock): Promise { const newReward = createReward( height, blockHash, - extrinsicId, - height + "-" + eventIdx.toString(), + height + "-" + event.phase.type, + height + "-" + eventIndex, voter, "rewards.VoteReward", reward, @@ -255,8 +289,8 @@ export async function handleBlock(_block: SubstrateBlock): Promise { const newReward = createReward( height, blockHash, - extrinsicId, - height + "-" + eventIdx.toString(), + height + "-" + event.phase.type, + height + "-" + eventIndex, blockAuthor, "rewards.BlockReward", reward, @@ -269,6 +303,9 @@ export async function handleBlock(_block: SubstrateBlock): Promise { default: break; } + + // Increment event index + eventIndex++; }); }); diff --git a/indexers/mainnet/leaderboard/project.ts b/indexers/mainnet/leaderboard/project.ts index 00f97c891..a32a12c04 100644 --- a/indexers/mainnet/leaderboard/project.ts +++ b/indexers/mainnet/leaderboard/project.ts @@ -49,112 +49,9 @@ const project: SubstrateProject = { mapping: { file: "./dist/index.js", handlers: [ - // accounts { - kind: SubstrateHandlerKind.Event, - handler: "handleTransferEvent", - filter: { - module: "balances", - method: "Transfer", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleRemarkEvent", - filter: { - module: "system", - method: "Remarked", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleExtrinsicSuccessEvent", - filter: { - module: "system", - method: "ExtrinsicSuccess", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleExtrinsicFailedEvent", - filter: { - module: "system", - method: "ExtrinsicFailed", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleTransactionFeePaidEvent", - filter: { - module: "transactionPayment", - method: "TransactionFeePaid", - }, - }, - // farmers - { - kind: SubstrateHandlerKind.Event, - handler: "handleFarmerVoteRewardEvent", - filter: { - module: "rewards", - method: "VoteReward", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleFarmerBlockRewardEvent", - filter: { - module: "rewards", - method: "BlockReward", - }, - }, - // operators & nominators - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorRewardedEvent", - filter: { - module: "domains", - method: "OperatorRewarded", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorTaxCollectedEvent", - filter: { - module: "domains", - method: "OperatorTaxCollected", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleBundleStoredEvent", - filter: { - module: "domains", - method: "BundleStored", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorRegisteredEvent", - filter: { - module: "domains", - method: "OperatorRegistered", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorNominatedEvent", - filter: { - module: "domains", - method: "OperatorNominated", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleWithdrewStakeEvent", - filter: { - module: "domains", - method: "WithdrewStake", - }, + kind: SubstrateHandlerKind.Block, + handler: "handleBlock", }, ], }, diff --git a/indexers/mainnet/leaderboard/schema.graphql b/indexers/mainnet/leaderboard/schema.graphql index ef119761f..41789f17d 100644 --- a/indexers/mainnet/leaderboard/schema.graphql +++ b/indexers/mainnet/leaderboard/schema.graphql @@ -5,219 +5,243 @@ # account type AccountTransferSenderTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransferSenderTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransferReceiverTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransferReceiverTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountRemarkCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountExtrinsicTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountExtrinsicSuccessTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountExtrinsicFailedTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransactionFeePaidTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } # farmer type FarmerVoteTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerVoteTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerBlockTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerBlockTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerVoteAndBlockTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerVoteAndBlockTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } # operator type OperatorTotalRewardsCollectedHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorTotalTaxCollectedHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorBundleTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorDepositsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorDepositsTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorWithdrawalsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } # nominator/account type NominatorDepositsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type NominatorDepositsTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type NominatorWithdrawalsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } diff --git a/indexers/mainnet/leaderboard/src/mappings/db.ts b/indexers/mainnet/leaderboard/src/mappings/db.ts index 1cbdbd761..4b81d2e8c 100644 --- a/indexers/mainnet/leaderboard/src/mappings/db.ts +++ b/indexers/mainnet/leaderboard/src/mappings/db.ts @@ -25,437 +25,588 @@ import { OperatorWithdrawalsTotalCountHistory, } from "../types"; -export async function checkAndGetAccountTransferSenderTotalCount( - id: string, +type Cache = { + accountExtrinsicFailedTotalCountHistory: AccountExtrinsicFailedTotalCountHistory[]; + accountExtrinsicSuccessTotalCountHistory: AccountExtrinsicSuccessTotalCountHistory[]; + accountExtrinsicTotalCountHistory: AccountExtrinsicTotalCountHistory[]; + accountRemarkCountHistory: AccountRemarkCountHistory[]; + accountTransactionFeePaidTotalValueHistory: AccountTransactionFeePaidTotalValueHistory[]; + accountTransferReceiverTotalCountHistory: AccountTransferReceiverTotalCountHistory[]; + accountTransferReceiverTotalValueHistory: AccountTransferReceiverTotalValueHistory[]; + accountTransferSenderTotalCountHistory: AccountTransferSenderTotalCountHistory[]; + accountTransferSenderTotalValueHistory: AccountTransferSenderTotalValueHistory[]; + farmerBlockTotalCountHistory: FarmerBlockTotalCountHistory[]; + farmerBlockTotalValueHistory: FarmerBlockTotalValueHistory[]; + farmerVoteAndBlockTotalCountHistory: FarmerVoteAndBlockTotalCountHistory[]; + farmerVoteAndBlockTotalValueHistory: FarmerVoteAndBlockTotalValueHistory[]; + farmerVoteTotalCountHistory: FarmerVoteTotalCountHistory[]; + farmerVoteTotalValueHistory: FarmerVoteTotalValueHistory[]; + nominatorDepositsTotalCountHistory: NominatorDepositsTotalCountHistory[]; + nominatorDepositsTotalValueHistory: NominatorDepositsTotalValueHistory[]; + nominatorWithdrawalsTotalCountHistory: NominatorWithdrawalsTotalCountHistory[]; + operatorBundleTotalCountHistory: OperatorBundleTotalCountHistory[]; + operatorDepositsTotalCountHistory: OperatorDepositsTotalCountHistory[]; + operatorDepositsTotalValueHistory: OperatorDepositsTotalValueHistory[]; + operatorTotalRewardsCollectedHistory: OperatorTotalRewardsCollectedHistory[]; + operatorTotalTaxCollectedHistory: OperatorTotalTaxCollectedHistory[]; + operatorWithdrawalsTotalCountHistory: OperatorWithdrawalsTotalCountHistory[]; +}; + +export const initializeCache = (): Cache => ({ + accountExtrinsicFailedTotalCountHistory: [], + accountExtrinsicSuccessTotalCountHistory: [], + accountExtrinsicTotalCountHistory: [], + accountRemarkCountHistory: [], + accountTransactionFeePaidTotalValueHistory: [], + accountTransferReceiverTotalCountHistory: [], + accountTransferReceiverTotalValueHistory: [], + accountTransferSenderTotalCountHistory: [], + accountTransferSenderTotalValueHistory: [], + farmerBlockTotalCountHistory: [], + farmerBlockTotalValueHistory: [], + farmerVoteAndBlockTotalCountHistory: [], + farmerVoteAndBlockTotalValueHistory: [], + farmerVoteTotalCountHistory: [], + farmerVoteTotalValueHistory: [], + nominatorDepositsTotalCountHistory: [], + nominatorDepositsTotalValueHistory: [], + nominatorWithdrawalsTotalCountHistory: [], + operatorBundleTotalCountHistory: [], + operatorDepositsTotalCountHistory: [], + operatorDepositsTotalValueHistory: [], + operatorTotalRewardsCollectedHistory: [], + operatorTotalTaxCollectedHistory: [], + operatorWithdrawalsTotalCountHistory: [], +}); + +export const saveCache = async (cache: Cache) => { + await Promise.all( + cache.accountTransferSenderTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransferReceiverTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransferSenderTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransferReceiverTotalValueHistory.map((item) => item.save()) + ); + await Promise.all(cache.accountRemarkCountHistory.map((item) => item.save())); + await Promise.all( + cache.accountExtrinsicTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountExtrinsicSuccessTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountExtrinsicFailedTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransactionFeePaidTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerBlockTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerBlockTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteAndBlockTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteAndBlockTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.nominatorDepositsTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.nominatorDepositsTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.nominatorWithdrawalsTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorBundleTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorDepositsTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorDepositsTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorTotalRewardsCollectedHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorTotalTaxCollectedHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorWithdrawalsTotalCountHistory.map((item) => item.save()) + ); +}; + +export function createAccountTransferSenderTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferSenderTotalCountHistory.create({ - id, - rank: 0, +): AccountTransferSenderTotalCountHistory { + return AccountTransferSenderTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransferSenderTotalValue( - id: string, +export function createAccountTransferSenderTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferSenderTotalValueHistory.create({ - id, - rank: 0, +): AccountTransferSenderTotalValueHistory { + return AccountTransferSenderTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransferReceiverTotalCount( - id: string, +export function createAccountTransferReceiverTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferReceiverTotalCountHistory.create({ - id, - rank: 0, +): AccountTransferReceiverTotalCountHistory { + return AccountTransferReceiverTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransferReceiverTotalValue( - id: string, +export function createAccountTransferReceiverTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferReceiverTotalValueHistory.create({ - id, - rank: 0, +): AccountTransferReceiverTotalValueHistory { + return AccountTransferReceiverTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountRemarkCount( - id: string, +export function createAccountRemarkCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountRemarkCountHistory.create({ - id, - rank: 0, +): AccountRemarkCountHistory { + return AccountRemarkCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountExtrinsicTotalCount( - id: string, +export function createAccountExtrinsicTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountExtrinsicTotalCountHistory.create({ - id, - rank: 0, +): AccountExtrinsicTotalCountHistory { + return AccountExtrinsicTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountExtrinsicSuccessTotalCount( - id: string, +export function createAccountExtrinsicSuccessTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountExtrinsicSuccessTotalCountHistory.create({ - id, - rank: 0, +): AccountExtrinsicSuccessTotalCountHistory { + return AccountExtrinsicSuccessTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountExtrinsicFailedTotalCount( - id: string, +export function createAccountExtrinsicFailedTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountExtrinsicFailedTotalCountHistory.create({ - id, - rank: 0, +): AccountExtrinsicFailedTotalCountHistory { + return AccountExtrinsicFailedTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransactionFeePaidTotalValue( - id: string, +export function createAccountTransactionFeePaidTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransactionFeePaidTotalValueHistory.create({ - id, - rank: 0, +): AccountTransactionFeePaidTotalValueHistory { + return AccountTransactionFeePaidTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } // Farmer entities -export async function checkAndGetFarmerVoteTotalCount( - id: string, +export function createFarmerVoteTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteTotalCountHistory.create({ - id, - rank: 0, +): FarmerVoteTotalCountHistory { + return FarmerVoteTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerVoteTotalValue( - id: string, +export function createFarmerVoteTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteTotalValueHistory.create({ - id, - rank: 0, +): FarmerVoteTotalValueHistory { + return FarmerVoteTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerBlockTotalCount( - id: string, +export function createFarmerBlockTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerBlockTotalCountHistory.create({ - id, - rank: 0, +): FarmerBlockTotalCountHistory { + return FarmerBlockTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerBlockTotalValue( - id: string, +export function createFarmerBlockTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerBlockTotalValueHistory.create({ - id, - rank: 0, +): FarmerBlockTotalValueHistory { + return FarmerBlockTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerVoteAndBlockTotalCount( - id: string, +export function createFarmerVoteAndBlockTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteAndBlockTotalCountHistory.create({ - id, - rank: 0, +): FarmerVoteAndBlockTotalCountHistory { + return FarmerVoteAndBlockTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerVoteAndBlockTotalValue( - id: string, +export function createFarmerVoteAndBlockTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteAndBlockTotalValueHistory.create({ - id, - rank: 0, +): FarmerVoteAndBlockTotalValueHistory { + return FarmerVoteAndBlockTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } // Operator entities -export async function checkAndGetOperatorTotalRewardsCollected( - id: string, +export function createOperatorTotalRewardsCollected( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorTotalRewardsCollectedHistory.create({ - id, - rank: 0, +): OperatorTotalRewardsCollectedHistory { + return OperatorTotalRewardsCollectedHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorTotalTaxCollected( - id: string, +export function createOperatorTotalTaxCollected( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorTotalTaxCollectedHistory.create({ - id, - rank: 0, +): OperatorTotalTaxCollectedHistory { + return OperatorTotalTaxCollectedHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorBundleTotalCount( - id: string, +export function createOperatorBundleTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorBundleTotalCountHistory.create({ - id, - rank: 0, +): OperatorBundleTotalCountHistory { + return OperatorBundleTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorDepositsTotalCount( - id: string, +export function createOperatorDepositsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorDepositsTotalCountHistory.create({ - id, - rank: 0, +): OperatorDepositsTotalCountHistory { + return OperatorDepositsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorDepositsTotalValue( - id: string, +export function createOperatorDepositsTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorDepositsTotalValueHistory.create({ - id, - rank: 0, +): OperatorDepositsTotalValueHistory { + return OperatorDepositsTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorWithdrawalsTotalCount( - id: string, +export function createOperatorWithdrawalsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorWithdrawalsTotalCountHistory.create({ - id, - rank: 0, +): OperatorWithdrawalsTotalCountHistory { + return OperatorWithdrawalsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } // Nominator entities -export async function checkAndGetNominatorDepositsTotalCount( - id: string, +export function createNominatorDepositsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = NominatorDepositsTotalCountHistory.create({ - id, - rank: 0, +): NominatorDepositsTotalCountHistory { + return NominatorDepositsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetNominatorDepositsTotalValue( - id: string, +export function createNominatorDepositsTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = NominatorDepositsTotalValueHistory.create({ - id, - rank: 0, +): NominatorDepositsTotalValueHistory { + return NominatorDepositsTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetNominatorWithdrawalsTotalCount( - id: string, +export function createNominatorWithdrawalsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = NominatorWithdrawalsTotalCountHistory.create({ - id, - rank: 0, +): NominatorWithdrawalsTotalCountHistory { + return NominatorWithdrawalsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } diff --git a/indexers/mainnet/leaderboard/src/mappings/mappingHandlers.ts b/indexers/mainnet/leaderboard/src/mappings/mappingHandlers.ts index 552384cc3..14d9b6f65 100644 --- a/indexers/mainnet/leaderboard/src/mappings/mappingHandlers.ts +++ b/indexers/mainnet/leaderboard/src/mappings/mappingHandlers.ts @@ -1,371 +1,423 @@ -import { SubstrateEvent } from "@subql/types"; +import { SubstrateBlock } from "@subql/types"; import * as db from "./db"; -export async function handleTransferEvent( - event: SubstrateEvent -): Promise { +export async function handleBlock(_block: SubstrateBlock): Promise { const { - event: { - data: [_from, _to, _amount], + block: { + header: { number }, + extrinsics, }, - } = event; - const from = _from.toString(); - const to = _to.toString(); - const amount = BigInt(_amount.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountTransferSenderTotalCount( - from, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountTransferSenderTotalValue( - from, - amount, - blockNumber, - timestamp - ); - - await db.checkAndGetAccountTransferReceiverTotalCount( - to, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountTransferReceiverTotalValue( - to, - amount, - blockNumber, - timestamp - ); -} - -export async function handleRemarkEvent(event: SubstrateEvent): Promise { - const { - event: { index }, - } = event; - - const extrinsicIndex = Number(index); - const extrinsic = event.block.block.extrinsics[extrinsicIndex]; - const accountId = extrinsic.signer.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountRemarkCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleExtrinsicSuccessEvent( - event: SubstrateEvent -): Promise { - const { - event: { index }, - } = event; - - const extrinsicIndex = Number(index); - const extrinsic = event.block.block.extrinsics[extrinsicIndex]; - const accountId = extrinsic.signer.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountExtrinsicTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountExtrinsicSuccessTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleExtrinsicFailedEvent( - event: SubstrateEvent -): Promise { - const { - event: { index }, - } = event; - const extrinsicIndex = Number(index); - const extrinsic = event.block.block.extrinsics[extrinsicIndex]; - const accountId = extrinsic.signer.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountExtrinsicTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountExtrinsicFailedTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleTransactionFeePaidEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_who, _actualFee, _tip], - }, - } = event; - const who = _who.toString(); - const actualFee = BigInt(_actualFee.toString()); - const tip = BigInt(_tip.toString()); - const totalFeePaid = actualFee + tip; - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountTransactionFeePaidTotalValue( - who, - totalFeePaid, - blockNumber, - timestamp - ); -} - -export async function handleFarmerVoteRewardEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_voter, _reward], - }, - } = event; - const voter = _voter.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetFarmerVoteTotalCount( - voter, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerVoteTotalValue( - voter, - reward, - blockNumber, - timestamp - ); - - await db.checkAndGetFarmerVoteAndBlockTotalCount( - voter, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerVoteAndBlockTotalValue( - voter, - reward, - blockNumber, - timestamp - ); -} - -export async function handleFarmerBlockRewardEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_blockAuthor, _reward], - }, - } = event; - const blockAuthor = _blockAuthor.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetFarmerBlockTotalCount( - blockAuthor, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerBlockTotalValue( - blockAuthor, - reward, - blockNumber, - timestamp - ); - - await db.checkAndGetFarmerVoteAndBlockTotalCount( - blockAuthor, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerVoteAndBlockTotalValue( - blockAuthor, - reward, - blockNumber, - timestamp - ); -} - -export async function handleOperatorRewardedEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _reward], - }, - } = event; - const operatorId = _operatorId.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - if (reward === BigInt(0)) return; - - await db.checkAndGetOperatorTotalRewardsCollected( - operatorId, - reward, - blockNumber, - timestamp - ); -} - -export async function handleOperatorTaxCollectedEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _tax], - }, - } = event; - const operatorId = _operatorId.toString(); - const tax = BigInt(_tax.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorTotalTaxCollected( - operatorId, - tax, - blockNumber, - timestamp - ); -} - -export async function handleBundleStoredEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_bundleAuthor], - }, - } = event; - const operatorId = _bundleAuthor.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorBundleTotalCount( - operatorId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleOperatorRegisteredEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _reward], - }, - } = event; - const operatorId = _operatorId.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorTotalRewardsCollected( - operatorId, - reward, - blockNumber, - timestamp - ); -} - -export async function handleOperatorNominatedEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _nominatorId, _amount], - }, - } = event; - const operatorId = _operatorId.toString(); - const nominatorId = _nominatorId.toString(); - const amount = BigInt(_amount.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorDepositsTotalCount( - operatorId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetOperatorDepositsTotalValue( - operatorId, - amount, - blockNumber, - timestamp - ); - - await db.checkAndGetNominatorDepositsTotalCount( - nominatorId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetNominatorDepositsTotalValue( - nominatorId, - amount, - blockNumber, - timestamp - ); -} - -export async function handleWithdrewStakeEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _nominatorId], - }, - } = event; - const operatorId = _operatorId.toString(); - const nominatorId = _nominatorId.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorWithdrawalsTotalCount( - operatorId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetNominatorWithdrawalsTotalCount( - nominatorId, - BigInt(1), - blockNumber, - timestamp - ); + timestamp, + events, + } = _block; + const height = BigInt(number.toString()); + + let cache = db.initializeCache(); + let eventIndex = 0; + + // Process extrinsics + extrinsics.forEach((extrinsic, extrinsicIdx) => { + const extrinsicEvents = events.filter( + (e) => + e.phase.isApplyExtrinsic && + e.phase.asApplyExtrinsic.toNumber() === extrinsicIdx + ); + const successEvent = events.find( + (e) => + e.event.section === "system" && e.event.method === "ExtrinsicSuccess" + ); + const successEventId = events.findIndex( + (e) => + e.event.section === "system" && e.event.method === "ExtrinsicSuccess" + ); + const extrinsicId = extrinsic ? height + "-" + extrinsicIdx.toString() : ""; + const extrinsicSigner = extrinsic.signer.toString(); + + cache.accountExtrinsicTotalCountHistory.push( + db.createAccountExtrinsicTotalCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + height + "-" + successEventId.toString(), + timestamp + ) + ); + if (successEvent) { + cache.accountExtrinsicSuccessTotalCountHistory.push( + db.createAccountExtrinsicSuccessTotalCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + height + "-" + successEventId.toString(), + timestamp + ) + ); + + // Process specific extrinsic + switch (`${extrinsic.method.section}.${extrinsic.method.method}`) { + case "system.remark": + case "system.remarkWithEvent": { + cache.accountRemarkCountHistory.push( + db.createAccountRemarkCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + "", + timestamp + ) + ); + break; + } + } + + // Process extrinsic events + extrinsicEvents.forEach((event, eventIdx) => { + const eventId = height + "-" + eventIndex; + + // Process specific events + switch (`${event.event.section}.${event.event.method}`) { + case "balances.Transfer": { + const from = event.event.data[0].toString(); + const to = event.event.data[1].toString(); + const amount = BigInt(event.event.data[2].toString()); + + cache.accountTransferSenderTotalCountHistory.push( + db.createAccountTransferSenderTotalCount( + from, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.accountTransferSenderTotalValueHistory.push( + db.createAccountTransferSenderTotalValue( + from, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.accountTransferReceiverTotalCountHistory.push( + db.createAccountTransferReceiverTotalCount( + to, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.accountTransferReceiverTotalValueHistory.push( + db.createAccountTransferReceiverTotalValue( + to, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "transactionPayment.TransactionFeePaid": { + const who = event.event.data[0].toString(); + const actualFee = BigInt(event.event.data[1].toString()); + const tip = BigInt(event.event.data[2].toString()); + + cache.accountTransactionFeePaidTotalValueHistory.push( + db.createAccountTransactionFeePaidTotalValue( + who, + actualFee + tip, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorRewarded": { + const operatorId = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + if (reward === BigInt(0)) break; + + cache.operatorTotalRewardsCollectedHistory.push( + db.createOperatorTotalRewardsCollected( + operatorId, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorTaxCollected": { + const operatorId = event.event.data[0].toString(); + const tax = BigInt(event.event.data[1].toString()); + + cache.operatorTotalTaxCollectedHistory.push( + db.createOperatorTotalTaxCollected( + operatorId, + tax, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + break; + } + case "domains.BundleStored": { + const bundleAuthor = event.event.data[0].toString(); + + cache.operatorBundleTotalCountHistory.push( + db.createOperatorBundleTotalCount( + bundleAuthor, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorRegistered": { + const operatorId = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + + cache.operatorTotalRewardsCollectedHistory.push( + db.createOperatorTotalRewardsCollected( + operatorId, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorNominated": { + const operatorId = event.event.data[0].toString(); + const nominatorId = event.event.data[1].toString(); + const amount = BigInt(event.event.data[2].toString()); + + cache.operatorDepositsTotalCountHistory.push( + db.createOperatorDepositsTotalCount( + operatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.operatorDepositsTotalValueHistory.push( + db.createOperatorDepositsTotalValue( + operatorId, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.nominatorDepositsTotalCountHistory.push( + db.createNominatorDepositsTotalCount( + nominatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.nominatorDepositsTotalValueHistory.push( + db.createNominatorDepositsTotalValue( + nominatorId, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.WithdrewStake": { + const operatorId = event.event.data[0].toString(); + const nominatorId = event.event.data[1].toString(); + + cache.operatorWithdrawalsTotalCountHistory.push( + db.createOperatorWithdrawalsTotalCount( + operatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.nominatorWithdrawalsTotalCountHistory.push( + db.createNominatorWithdrawalsTotalCount( + nominatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + default: + break; + } + + // Increment event index + eventIndex++; + }); + } else { + // Process fail extrinsic + cache.accountExtrinsicFailedTotalCountHistory.push( + db.createAccountExtrinsicFailedTotalCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + height + "-" + successEventId.toString(), + timestamp + ) + ); + } + }); + + const finalizationEvents = events.filter((e) => e.phase.isFinalization); + + // Process finalization events + finalizationEvents.forEach((event) => { + const extrinsicId = height + "-" + event.phase.type; // AKA (blockHeight-Finalization) + const eventId = height + "-" + eventIndex; + + // Process specific events + switch (`${event.event.section}.${event.event.method}`) { + case "rewards.VoteReward": { + const voter = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + + cache.farmerVoteTotalCountHistory.push( + db.createFarmerVoteTotalCount( + voter, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerVoteTotalValueHistory.push( + db.createFarmerVoteTotalValue( + voter, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.farmerVoteAndBlockTotalCountHistory.push( + db.createFarmerVoteAndBlockTotalCount( + voter, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerVoteAndBlockTotalValueHistory.push( + db.createFarmerVoteAndBlockTotalValue( + voter, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + break; + } + case "rewards.BlockReward": { + const blockAuthor = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + + cache.farmerBlockTotalCountHistory.push( + db.createFarmerBlockTotalCount( + blockAuthor, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerBlockTotalValueHistory.push( + db.createFarmerBlockTotalValue( + blockAuthor, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.farmerVoteAndBlockTotalCountHistory.push( + db.createFarmerVoteAndBlockTotalCount( + blockAuthor, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerVoteAndBlockTotalValueHistory.push( + db.createFarmerVoteAndBlockTotalValue( + blockAuthor, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + break; + } + default: + break; + } + + // Increment event index + eventIndex++; + }); + + // Save cache + await db.saveCache(cache); } diff --git a/indexers/taskboard/src/utils/db.ts b/indexers/taskboard/src/utils/db.ts index f3c46e247..038bbab90 100644 --- a/indexers/taskboard/src/utils/db.ts +++ b/indexers/taskboard/src/utils/db.ts @@ -52,28 +52,28 @@ const consensusAccountsQuery = ` // Get unique sections from both extrinsics and events const updateLeaderboardRanking = (sourceTable: string, targetTable: string) => ` WITH aggregated_entries AS ( - SELECT id, - SUM(value) AS total_value, - MAX(last_contribution_at) AS last_contribution_at, - MIN(created_at) AS created_at, - MAX(updated_at) AS updated_at + SELECT account_id, + SUM(value) AS total_value, + MAX(last_contribution_at) AS last_contribution_at, + MIN(block_height) AS created_at, + MAX(block_height) AS updated_at FROM leaderboard.${sourceTable} - GROUP BY id + GROUP BY account_id ), ranked_entries AS ( - SELECT id, - ROW_NUMBER() OVER (ORDER BY total_value DESC, id) AS new_rank, - total_value, - last_contribution_at, - created_at, - updated_at + SELECT account_id as id, + ROW_NUMBER() OVER (ORDER BY total_value DESC, account_id) AS new_rank, + total_value, + last_contribution_at, + created_at, + updated_at FROM aggregated_entries ) INSERT INTO leaderboard.${targetTable} (id, rank, value, last_contribution_at, created_at, updated_at) SELECT id, new_rank, total_value, last_contribution_at, created_at, updated_at FROM ranked_entries ON CONFLICT (id) - DO UPDATE SET rank = EXCLUDED.rank, value = EXCLUDED.value, last_contribution_at = EXCLUDED.last_contribution_at, created_at = EXCLUDED.created_at, updated_at = EXCLUDED.updated_at; - `; + DO UPDATE SET rank = EXCLUDED.rank, value = EXCLUDED.value, last_contribution_at = EXCLUDED.last_contribution_at, updated_at = EXCLUDED.updated_at; +`; const consensusUpsertAccountQuery = ` INSERT INTO consensus.accounts (id, account_id, _id, nonce, free, reserved, total, created_at, updated_at, _block_range) diff --git a/indexers/taurus/consensus/src/mappings/mappingHandlers.ts b/indexers/taurus/consensus/src/mappings/mappingHandlers.ts index c6f1b4d92..70b43a6ca 100644 --- a/indexers/taurus/consensus/src/mappings/mappingHandlers.ts +++ b/indexers/taurus/consensus/src/mappings/mappingHandlers.ts @@ -63,6 +63,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { const logKindsToUpdate: string[] = []; const addressToUpdate: string[] = []; + let eventIndex = 0; let totalBlockRewardsCount = 0; let totalVoteRewardsCount = 0; let totalTransferValue = BigInt(0); @@ -155,7 +156,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { addressToUpdate.push(extrinsicSigner); // Process extrinsic events - extrinsicEvents.forEach((event, eventIdx) => { + extrinsicEvents.forEach((event) => { const extrinsicId = extrinsic ? height + "-" + extrinsicIdx.toString() : ""; @@ -177,7 +178,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { createEvent( height, blockHash, - BigInt(eventIdx), + BigInt(eventIndex), extrinsicId, extrinsic.hash.toString(), event.event.section, @@ -206,7 +207,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { height, blockHash, extrinsicId, - height + "-" + eventIdx.toString(), + height + "-" + eventIndex, from, to, amount, @@ -218,6 +219,39 @@ export async function handleBlock(_block: SubstrateBlock): Promise { break; } + default: + break; + } + + // Increment event index + eventIndex++; + }); + + // Get finalization events + const finalizationEvents = events.filter((e) => e.phase.isFinalization); + + // Process finalization events + finalizationEvents.forEach(async (event) => { + newEvents.push( + createEvent( + height, + blockHash, + BigInt(eventIndex), + height + "-" + event.phase.type, + extrinsic.hash.toString(), + event.event.section, + event.event.method, + timestamp ? timestamp : new Date(0), + event.phase.type, + pos, + args, + cid + ) + ); + eventMethodsToUpdate.push([event.event.section, event.event.method]); + + // Process specific events + switch (`${event.event.section}.${event.event.method}`) { case "rewards.VoteReward": { const voter = event.event.data[0].toString(); const reward = BigInt(event.event.data[1].toString()); @@ -231,8 +265,8 @@ export async function handleBlock(_block: SubstrateBlock): Promise { const newReward = createReward( height, blockHash, - extrinsicId, - height + "-" + eventIdx.toString(), + height + "-" + event.phase.type, + height + "-" + eventIndex, voter, "rewards.VoteReward", reward, @@ -255,8 +289,8 @@ export async function handleBlock(_block: SubstrateBlock): Promise { const newReward = createReward( height, blockHash, - extrinsicId, - height + "-" + eventIdx.toString(), + height + "-" + event.phase.type, + height + "-" + eventIndex, blockAuthor, "rewards.BlockReward", reward, @@ -269,6 +303,9 @@ export async function handleBlock(_block: SubstrateBlock): Promise { default: break; } + + // Increment event index + eventIndex++; }); }); diff --git a/indexers/taurus/leaderboard/project.ts b/indexers/taurus/leaderboard/project.ts index e8034caa0..b3f34b040 100644 --- a/indexers/taurus/leaderboard/project.ts +++ b/indexers/taurus/leaderboard/project.ts @@ -49,112 +49,9 @@ const project: SubstrateProject = { mapping: { file: "./dist/index.js", handlers: [ - // accounts { - kind: SubstrateHandlerKind.Event, - handler: "handleTransferEvent", - filter: { - module: "balances", - method: "Transfer", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleRemarkEvent", - filter: { - module: "system", - method: "Remarked", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleExtrinsicSuccessEvent", - filter: { - module: "system", - method: "ExtrinsicSuccess", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleExtrinsicFailedEvent", - filter: { - module: "system", - method: "ExtrinsicFailed", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleTransactionFeePaidEvent", - filter: { - module: "transactionPayment", - method: "TransactionFeePaid", - }, - }, - // farmers - { - kind: SubstrateHandlerKind.Event, - handler: "handleFarmerVoteRewardEvent", - filter: { - module: "rewards", - method: "VoteReward", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleFarmerBlockRewardEvent", - filter: { - module: "rewards", - method: "BlockReward", - }, - }, - // operators & nominators - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorRewardedEvent", - filter: { - module: "domains", - method: "OperatorRewarded", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorTaxCollectedEvent", - filter: { - module: "domains", - method: "OperatorTaxCollected", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleBundleStoredEvent", - filter: { - module: "domains", - method: "BundleStored", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorRegisteredEvent", - filter: { - module: "domains", - method: "OperatorRegistered", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleOperatorNominatedEvent", - filter: { - module: "domains", - method: "OperatorNominated", - }, - }, - { - kind: SubstrateHandlerKind.Event, - handler: "handleWithdrewStakeEvent", - filter: { - module: "domains", - method: "WithdrewStake", - }, + kind: SubstrateHandlerKind.Block, + handler: "handleBlock", }, ], }, diff --git a/indexers/taurus/leaderboard/schema.graphql b/indexers/taurus/leaderboard/schema.graphql index ef119761f..41789f17d 100644 --- a/indexers/taurus/leaderboard/schema.graphql +++ b/indexers/taurus/leaderboard/schema.graphql @@ -5,219 +5,243 @@ # account type AccountTransferSenderTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransferSenderTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransferReceiverTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransferReceiverTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountRemarkCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountExtrinsicTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountExtrinsicSuccessTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountExtrinsicFailedTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type AccountTransactionFeePaidTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } # farmer type FarmerVoteTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerVoteTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerBlockTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerBlockTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerVoteAndBlockTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type FarmerVoteAndBlockTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } # operator type OperatorTotalRewardsCollectedHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorTotalTaxCollectedHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorBundleTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorDepositsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorDepositsTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type OperatorWithdrawalsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } # nominator/account type NominatorDepositsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type NominatorDepositsTotalValueHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } type NominatorWithdrawalsTotalCountHistory @entity { id: ID! - rank: Int! @index + accountId: String! @index value: BigInt! @index lastContributionAt: Date! - createdAt: Int! @index - updatedAt: Int! @index + blockHeight: BigInt! @index + extrinsicId: String! + eventId: String! } diff --git a/indexers/taurus/leaderboard/src/mappings/db.ts b/indexers/taurus/leaderboard/src/mappings/db.ts index 1cbdbd761..4b81d2e8c 100644 --- a/indexers/taurus/leaderboard/src/mappings/db.ts +++ b/indexers/taurus/leaderboard/src/mappings/db.ts @@ -25,437 +25,588 @@ import { OperatorWithdrawalsTotalCountHistory, } from "../types"; -export async function checkAndGetAccountTransferSenderTotalCount( - id: string, +type Cache = { + accountExtrinsicFailedTotalCountHistory: AccountExtrinsicFailedTotalCountHistory[]; + accountExtrinsicSuccessTotalCountHistory: AccountExtrinsicSuccessTotalCountHistory[]; + accountExtrinsicTotalCountHistory: AccountExtrinsicTotalCountHistory[]; + accountRemarkCountHistory: AccountRemarkCountHistory[]; + accountTransactionFeePaidTotalValueHistory: AccountTransactionFeePaidTotalValueHistory[]; + accountTransferReceiverTotalCountHistory: AccountTransferReceiverTotalCountHistory[]; + accountTransferReceiverTotalValueHistory: AccountTransferReceiverTotalValueHistory[]; + accountTransferSenderTotalCountHistory: AccountTransferSenderTotalCountHistory[]; + accountTransferSenderTotalValueHistory: AccountTransferSenderTotalValueHistory[]; + farmerBlockTotalCountHistory: FarmerBlockTotalCountHistory[]; + farmerBlockTotalValueHistory: FarmerBlockTotalValueHistory[]; + farmerVoteAndBlockTotalCountHistory: FarmerVoteAndBlockTotalCountHistory[]; + farmerVoteAndBlockTotalValueHistory: FarmerVoteAndBlockTotalValueHistory[]; + farmerVoteTotalCountHistory: FarmerVoteTotalCountHistory[]; + farmerVoteTotalValueHistory: FarmerVoteTotalValueHistory[]; + nominatorDepositsTotalCountHistory: NominatorDepositsTotalCountHistory[]; + nominatorDepositsTotalValueHistory: NominatorDepositsTotalValueHistory[]; + nominatorWithdrawalsTotalCountHistory: NominatorWithdrawalsTotalCountHistory[]; + operatorBundleTotalCountHistory: OperatorBundleTotalCountHistory[]; + operatorDepositsTotalCountHistory: OperatorDepositsTotalCountHistory[]; + operatorDepositsTotalValueHistory: OperatorDepositsTotalValueHistory[]; + operatorTotalRewardsCollectedHistory: OperatorTotalRewardsCollectedHistory[]; + operatorTotalTaxCollectedHistory: OperatorTotalTaxCollectedHistory[]; + operatorWithdrawalsTotalCountHistory: OperatorWithdrawalsTotalCountHistory[]; +}; + +export const initializeCache = (): Cache => ({ + accountExtrinsicFailedTotalCountHistory: [], + accountExtrinsicSuccessTotalCountHistory: [], + accountExtrinsicTotalCountHistory: [], + accountRemarkCountHistory: [], + accountTransactionFeePaidTotalValueHistory: [], + accountTransferReceiverTotalCountHistory: [], + accountTransferReceiverTotalValueHistory: [], + accountTransferSenderTotalCountHistory: [], + accountTransferSenderTotalValueHistory: [], + farmerBlockTotalCountHistory: [], + farmerBlockTotalValueHistory: [], + farmerVoteAndBlockTotalCountHistory: [], + farmerVoteAndBlockTotalValueHistory: [], + farmerVoteTotalCountHistory: [], + farmerVoteTotalValueHistory: [], + nominatorDepositsTotalCountHistory: [], + nominatorDepositsTotalValueHistory: [], + nominatorWithdrawalsTotalCountHistory: [], + operatorBundleTotalCountHistory: [], + operatorDepositsTotalCountHistory: [], + operatorDepositsTotalValueHistory: [], + operatorTotalRewardsCollectedHistory: [], + operatorTotalTaxCollectedHistory: [], + operatorWithdrawalsTotalCountHistory: [], +}); + +export const saveCache = async (cache: Cache) => { + await Promise.all( + cache.accountTransferSenderTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransferReceiverTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransferSenderTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransferReceiverTotalValueHistory.map((item) => item.save()) + ); + await Promise.all(cache.accountRemarkCountHistory.map((item) => item.save())); + await Promise.all( + cache.accountExtrinsicTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountExtrinsicSuccessTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountExtrinsicFailedTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.accountTransactionFeePaidTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerBlockTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerBlockTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteAndBlockTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.farmerVoteAndBlockTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.nominatorDepositsTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.nominatorDepositsTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.nominatorWithdrawalsTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorBundleTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorDepositsTotalCountHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorDepositsTotalValueHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorTotalRewardsCollectedHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorTotalTaxCollectedHistory.map((item) => item.save()) + ); + await Promise.all( + cache.operatorWithdrawalsTotalCountHistory.map((item) => item.save()) + ); +}; + +export function createAccountTransferSenderTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferSenderTotalCountHistory.create({ - id, - rank: 0, +): AccountTransferSenderTotalCountHistory { + return AccountTransferSenderTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransferSenderTotalValue( - id: string, +export function createAccountTransferSenderTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferSenderTotalValueHistory.create({ - id, - rank: 0, +): AccountTransferSenderTotalValueHistory { + return AccountTransferSenderTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransferReceiverTotalCount( - id: string, +export function createAccountTransferReceiverTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferReceiverTotalCountHistory.create({ - id, - rank: 0, +): AccountTransferReceiverTotalCountHistory { + return AccountTransferReceiverTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransferReceiverTotalValue( - id: string, +export function createAccountTransferReceiverTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransferReceiverTotalValueHistory.create({ - id, - rank: 0, +): AccountTransferReceiverTotalValueHistory { + return AccountTransferReceiverTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountRemarkCount( - id: string, +export function createAccountRemarkCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountRemarkCountHistory.create({ - id, - rank: 0, +): AccountRemarkCountHistory { + return AccountRemarkCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountExtrinsicTotalCount( - id: string, +export function createAccountExtrinsicTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountExtrinsicTotalCountHistory.create({ - id, - rank: 0, +): AccountExtrinsicTotalCountHistory { + return AccountExtrinsicTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountExtrinsicSuccessTotalCount( - id: string, +export function createAccountExtrinsicSuccessTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountExtrinsicSuccessTotalCountHistory.create({ - id, - rank: 0, +): AccountExtrinsicSuccessTotalCountHistory { + return AccountExtrinsicSuccessTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountExtrinsicFailedTotalCount( - id: string, +export function createAccountExtrinsicFailedTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountExtrinsicFailedTotalCountHistory.create({ - id, - rank: 0, +): AccountExtrinsicFailedTotalCountHistory { + return AccountExtrinsicFailedTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetAccountTransactionFeePaidTotalValue( - id: string, +export function createAccountTransactionFeePaidTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = AccountTransactionFeePaidTotalValueHistory.create({ - id, - rank: 0, +): AccountTransactionFeePaidTotalValueHistory { + return AccountTransactionFeePaidTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } // Farmer entities -export async function checkAndGetFarmerVoteTotalCount( - id: string, +export function createFarmerVoteTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteTotalCountHistory.create({ - id, - rank: 0, +): FarmerVoteTotalCountHistory { + return FarmerVoteTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerVoteTotalValue( - id: string, +export function createFarmerVoteTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteTotalValueHistory.create({ - id, - rank: 0, +): FarmerVoteTotalValueHistory { + return FarmerVoteTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerBlockTotalCount( - id: string, +export function createFarmerBlockTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerBlockTotalCountHistory.create({ - id, - rank: 0, +): FarmerBlockTotalCountHistory { + return FarmerBlockTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerBlockTotalValue( - id: string, +export function createFarmerBlockTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerBlockTotalValueHistory.create({ - id, - rank: 0, +): FarmerBlockTotalValueHistory { + return FarmerBlockTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerVoteAndBlockTotalCount( - id: string, +export function createFarmerVoteAndBlockTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteAndBlockTotalCountHistory.create({ - id, - rank: 0, +): FarmerVoteAndBlockTotalCountHistory { + return FarmerVoteAndBlockTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetFarmerVoteAndBlockTotalValue( - id: string, +export function createFarmerVoteAndBlockTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = FarmerVoteAndBlockTotalValueHistory.create({ - id, - rank: 0, +): FarmerVoteAndBlockTotalValueHistory { + return FarmerVoteAndBlockTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } // Operator entities -export async function checkAndGetOperatorTotalRewardsCollected( - id: string, +export function createOperatorTotalRewardsCollected( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorTotalRewardsCollectedHistory.create({ - id, - rank: 0, +): OperatorTotalRewardsCollectedHistory { + return OperatorTotalRewardsCollectedHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorTotalTaxCollected( - id: string, +export function createOperatorTotalTaxCollected( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorTotalTaxCollectedHistory.create({ - id, - rank: 0, +): OperatorTotalTaxCollectedHistory { + return OperatorTotalTaxCollectedHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorBundleTotalCount( - id: string, +export function createOperatorBundleTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorBundleTotalCountHistory.create({ - id, - rank: 0, +): OperatorBundleTotalCountHistory { + return OperatorBundleTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorDepositsTotalCount( - id: string, +export function createOperatorDepositsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorDepositsTotalCountHistory.create({ - id, - rank: 0, +): OperatorDepositsTotalCountHistory { + return OperatorDepositsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorDepositsTotalValue( - id: string, +export function createOperatorDepositsTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorDepositsTotalValueHistory.create({ - id, - rank: 0, +): OperatorDepositsTotalValueHistory { + return OperatorDepositsTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetOperatorWithdrawalsTotalCount( - id: string, +export function createOperatorWithdrawalsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = OperatorWithdrawalsTotalCountHistory.create({ - id, - rank: 0, +): OperatorWithdrawalsTotalCountHistory { + return OperatorWithdrawalsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } // Nominator entities -export async function checkAndGetNominatorDepositsTotalCount( - id: string, +export function createNominatorDepositsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = NominatorDepositsTotalCountHistory.create({ - id, - rank: 0, +): NominatorDepositsTotalCountHistory { + return NominatorDepositsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetNominatorDepositsTotalValue( - id: string, +export function createNominatorDepositsTotalValue( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = NominatorDepositsTotalValueHistory.create({ - id, - rank: 0, +): NominatorDepositsTotalValueHistory { + return NominatorDepositsTotalValueHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } -export async function checkAndGetNominatorWithdrawalsTotalCount( - id: string, +export function createNominatorWithdrawalsTotalCount( + accountId: string, value: bigint, - blockNumber: number, + blockHeight: bigint, + extrinsicId: string, + eventId: string, lastContributionAt: Date = new Date() -): Promise { - const account = NominatorWithdrawalsTotalCountHistory.create({ - id, - rank: 0, +): NominatorWithdrawalsTotalCountHistory { + return NominatorWithdrawalsTotalCountHistory.create({ + id: `${accountId}-${extrinsicId}-${eventId}`, + accountId, value, lastContributionAt, - createdAt: blockNumber, - updatedAt: blockNumber, + blockHeight, + extrinsicId, + eventId, }); - await account.save(); - return account; } diff --git a/indexers/taurus/leaderboard/src/mappings/mappingHandlers.ts b/indexers/taurus/leaderboard/src/mappings/mappingHandlers.ts index 552384cc3..14d9b6f65 100644 --- a/indexers/taurus/leaderboard/src/mappings/mappingHandlers.ts +++ b/indexers/taurus/leaderboard/src/mappings/mappingHandlers.ts @@ -1,371 +1,423 @@ -import { SubstrateEvent } from "@subql/types"; +import { SubstrateBlock } from "@subql/types"; import * as db from "./db"; -export async function handleTransferEvent( - event: SubstrateEvent -): Promise { +export async function handleBlock(_block: SubstrateBlock): Promise { const { - event: { - data: [_from, _to, _amount], + block: { + header: { number }, + extrinsics, }, - } = event; - const from = _from.toString(); - const to = _to.toString(); - const amount = BigInt(_amount.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountTransferSenderTotalCount( - from, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountTransferSenderTotalValue( - from, - amount, - blockNumber, - timestamp - ); - - await db.checkAndGetAccountTransferReceiverTotalCount( - to, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountTransferReceiverTotalValue( - to, - amount, - blockNumber, - timestamp - ); -} - -export async function handleRemarkEvent(event: SubstrateEvent): Promise { - const { - event: { index }, - } = event; - - const extrinsicIndex = Number(index); - const extrinsic = event.block.block.extrinsics[extrinsicIndex]; - const accountId = extrinsic.signer.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountRemarkCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleExtrinsicSuccessEvent( - event: SubstrateEvent -): Promise { - const { - event: { index }, - } = event; - - const extrinsicIndex = Number(index); - const extrinsic = event.block.block.extrinsics[extrinsicIndex]; - const accountId = extrinsic.signer.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountExtrinsicTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountExtrinsicSuccessTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleExtrinsicFailedEvent( - event: SubstrateEvent -): Promise { - const { - event: { index }, - } = event; - const extrinsicIndex = Number(index); - const extrinsic = event.block.block.extrinsics[extrinsicIndex]; - const accountId = extrinsic.signer.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountExtrinsicTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetAccountExtrinsicFailedTotalCount( - accountId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleTransactionFeePaidEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_who, _actualFee, _tip], - }, - } = event; - const who = _who.toString(); - const actualFee = BigInt(_actualFee.toString()); - const tip = BigInt(_tip.toString()); - const totalFeePaid = actualFee + tip; - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetAccountTransactionFeePaidTotalValue( - who, - totalFeePaid, - blockNumber, - timestamp - ); -} - -export async function handleFarmerVoteRewardEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_voter, _reward], - }, - } = event; - const voter = _voter.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetFarmerVoteTotalCount( - voter, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerVoteTotalValue( - voter, - reward, - blockNumber, - timestamp - ); - - await db.checkAndGetFarmerVoteAndBlockTotalCount( - voter, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerVoteAndBlockTotalValue( - voter, - reward, - blockNumber, - timestamp - ); -} - -export async function handleFarmerBlockRewardEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_blockAuthor, _reward], - }, - } = event; - const blockAuthor = _blockAuthor.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetFarmerBlockTotalCount( - blockAuthor, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerBlockTotalValue( - blockAuthor, - reward, - blockNumber, - timestamp - ); - - await db.checkAndGetFarmerVoteAndBlockTotalCount( - blockAuthor, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetFarmerVoteAndBlockTotalValue( - blockAuthor, - reward, - blockNumber, - timestamp - ); -} - -export async function handleOperatorRewardedEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _reward], - }, - } = event; - const operatorId = _operatorId.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - if (reward === BigInt(0)) return; - - await db.checkAndGetOperatorTotalRewardsCollected( - operatorId, - reward, - blockNumber, - timestamp - ); -} - -export async function handleOperatorTaxCollectedEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _tax], - }, - } = event; - const operatorId = _operatorId.toString(); - const tax = BigInt(_tax.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorTotalTaxCollected( - operatorId, - tax, - blockNumber, - timestamp - ); -} - -export async function handleBundleStoredEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_bundleAuthor], - }, - } = event; - const operatorId = _bundleAuthor.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorBundleTotalCount( - operatorId, - BigInt(1), - blockNumber, - timestamp - ); -} - -export async function handleOperatorRegisteredEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _reward], - }, - } = event; - const operatorId = _operatorId.toString(); - const reward = BigInt(_reward.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorTotalRewardsCollected( - operatorId, - reward, - blockNumber, - timestamp - ); -} - -export async function handleOperatorNominatedEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _nominatorId, _amount], - }, - } = event; - const operatorId = _operatorId.toString(); - const nominatorId = _nominatorId.toString(); - const amount = BigInt(_amount.toString()); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorDepositsTotalCount( - operatorId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetOperatorDepositsTotalValue( - operatorId, - amount, - blockNumber, - timestamp - ); - - await db.checkAndGetNominatorDepositsTotalCount( - nominatorId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetNominatorDepositsTotalValue( - nominatorId, - amount, - blockNumber, - timestamp - ); -} - -export async function handleWithdrewStakeEvent( - event: SubstrateEvent -): Promise { - const { - event: { - data: [_operatorId, _nominatorId], - }, - } = event; - const operatorId = _operatorId.toString(); - const nominatorId = _nominatorId.toString(); - const blockNumber = event.block.block.header.number.toNumber(); - const timestamp = event.block.timestamp ?? new Date(0); - - await db.checkAndGetOperatorWithdrawalsTotalCount( - operatorId, - BigInt(1), - blockNumber, - timestamp - ); - await db.checkAndGetNominatorWithdrawalsTotalCount( - nominatorId, - BigInt(1), - blockNumber, - timestamp - ); + timestamp, + events, + } = _block; + const height = BigInt(number.toString()); + + let cache = db.initializeCache(); + let eventIndex = 0; + + // Process extrinsics + extrinsics.forEach((extrinsic, extrinsicIdx) => { + const extrinsicEvents = events.filter( + (e) => + e.phase.isApplyExtrinsic && + e.phase.asApplyExtrinsic.toNumber() === extrinsicIdx + ); + const successEvent = events.find( + (e) => + e.event.section === "system" && e.event.method === "ExtrinsicSuccess" + ); + const successEventId = events.findIndex( + (e) => + e.event.section === "system" && e.event.method === "ExtrinsicSuccess" + ); + const extrinsicId = extrinsic ? height + "-" + extrinsicIdx.toString() : ""; + const extrinsicSigner = extrinsic.signer.toString(); + + cache.accountExtrinsicTotalCountHistory.push( + db.createAccountExtrinsicTotalCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + height + "-" + successEventId.toString(), + timestamp + ) + ); + if (successEvent) { + cache.accountExtrinsicSuccessTotalCountHistory.push( + db.createAccountExtrinsicSuccessTotalCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + height + "-" + successEventId.toString(), + timestamp + ) + ); + + // Process specific extrinsic + switch (`${extrinsic.method.section}.${extrinsic.method.method}`) { + case "system.remark": + case "system.remarkWithEvent": { + cache.accountRemarkCountHistory.push( + db.createAccountRemarkCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + "", + timestamp + ) + ); + break; + } + } + + // Process extrinsic events + extrinsicEvents.forEach((event, eventIdx) => { + const eventId = height + "-" + eventIndex; + + // Process specific events + switch (`${event.event.section}.${event.event.method}`) { + case "balances.Transfer": { + const from = event.event.data[0].toString(); + const to = event.event.data[1].toString(); + const amount = BigInt(event.event.data[2].toString()); + + cache.accountTransferSenderTotalCountHistory.push( + db.createAccountTransferSenderTotalCount( + from, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.accountTransferSenderTotalValueHistory.push( + db.createAccountTransferSenderTotalValue( + from, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.accountTransferReceiverTotalCountHistory.push( + db.createAccountTransferReceiverTotalCount( + to, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.accountTransferReceiverTotalValueHistory.push( + db.createAccountTransferReceiverTotalValue( + to, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "transactionPayment.TransactionFeePaid": { + const who = event.event.data[0].toString(); + const actualFee = BigInt(event.event.data[1].toString()); + const tip = BigInt(event.event.data[2].toString()); + + cache.accountTransactionFeePaidTotalValueHistory.push( + db.createAccountTransactionFeePaidTotalValue( + who, + actualFee + tip, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorRewarded": { + const operatorId = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + if (reward === BigInt(0)) break; + + cache.operatorTotalRewardsCollectedHistory.push( + db.createOperatorTotalRewardsCollected( + operatorId, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorTaxCollected": { + const operatorId = event.event.data[0].toString(); + const tax = BigInt(event.event.data[1].toString()); + + cache.operatorTotalTaxCollectedHistory.push( + db.createOperatorTotalTaxCollected( + operatorId, + tax, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + break; + } + case "domains.BundleStored": { + const bundleAuthor = event.event.data[0].toString(); + + cache.operatorBundleTotalCountHistory.push( + db.createOperatorBundleTotalCount( + bundleAuthor, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorRegistered": { + const operatorId = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + + cache.operatorTotalRewardsCollectedHistory.push( + db.createOperatorTotalRewardsCollected( + operatorId, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.OperatorNominated": { + const operatorId = event.event.data[0].toString(); + const nominatorId = event.event.data[1].toString(); + const amount = BigInt(event.event.data[2].toString()); + + cache.operatorDepositsTotalCountHistory.push( + db.createOperatorDepositsTotalCount( + operatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.operatorDepositsTotalValueHistory.push( + db.createOperatorDepositsTotalValue( + operatorId, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.nominatorDepositsTotalCountHistory.push( + db.createNominatorDepositsTotalCount( + nominatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.nominatorDepositsTotalValueHistory.push( + db.createNominatorDepositsTotalValue( + nominatorId, + amount, + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + case "domains.WithdrewStake": { + const operatorId = event.event.data[0].toString(); + const nominatorId = event.event.data[1].toString(); + + cache.operatorWithdrawalsTotalCountHistory.push( + db.createOperatorWithdrawalsTotalCount( + operatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.nominatorWithdrawalsTotalCountHistory.push( + db.createNominatorWithdrawalsTotalCount( + nominatorId, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + break; + } + default: + break; + } + + // Increment event index + eventIndex++; + }); + } else { + // Process fail extrinsic + cache.accountExtrinsicFailedTotalCountHistory.push( + db.createAccountExtrinsicFailedTotalCount( + extrinsicSigner, + BigInt(1), + height, + extrinsicId, + height + "-" + successEventId.toString(), + timestamp + ) + ); + } + }); + + const finalizationEvents = events.filter((e) => e.phase.isFinalization); + + // Process finalization events + finalizationEvents.forEach((event) => { + const extrinsicId = height + "-" + event.phase.type; // AKA (blockHeight-Finalization) + const eventId = height + "-" + eventIndex; + + // Process specific events + switch (`${event.event.section}.${event.event.method}`) { + case "rewards.VoteReward": { + const voter = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + + cache.farmerVoteTotalCountHistory.push( + db.createFarmerVoteTotalCount( + voter, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerVoteTotalValueHistory.push( + db.createFarmerVoteTotalValue( + voter, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.farmerVoteAndBlockTotalCountHistory.push( + db.createFarmerVoteAndBlockTotalCount( + voter, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerVoteAndBlockTotalValueHistory.push( + db.createFarmerVoteAndBlockTotalValue( + voter, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + break; + } + case "rewards.BlockReward": { + const blockAuthor = event.event.data[0].toString(); + const reward = BigInt(event.event.data[1].toString()); + + cache.farmerBlockTotalCountHistory.push( + db.createFarmerBlockTotalCount( + blockAuthor, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerBlockTotalValueHistory.push( + db.createFarmerBlockTotalValue( + blockAuthor, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + cache.farmerVoteAndBlockTotalCountHistory.push( + db.createFarmerVoteAndBlockTotalCount( + blockAuthor, + BigInt(1), + height, + extrinsicId, + eventId, + timestamp + ) + ); + cache.farmerVoteAndBlockTotalValueHistory.push( + db.createFarmerVoteAndBlockTotalValue( + blockAuthor, + reward, + height, + extrinsicId, + eventId, + timestamp + ) + ); + + break; + } + default: + break; + } + + // Increment event index + eventIndex++; + }); + + // Save cache + await db.saveCache(cache); }