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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions db/migrations/12_add_new_8_chain_events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
alter type "7a0b4cc03e" add value if not exists 'beefy' after 'validators';
alter type "7a0b4cc03e" add value if not exists 'revive' after 'beefy';

alter type "0bf3c7d4ef" add value if not exists 'self_register_did' after 'unlink_child_identity';
alter type "0bf3c7d4ef" add value if not exists 'remove_key' after 'sudo_as';
alter type "0bf3c7d4ef" add value if not exists 'set_mandatory_receiver_affirmation' after 'lock_instruction';
alter type "0bf3c7d4ef" add value if not exists 'transfer_funds' after 'set_mandatory_receiver_affirmation';
alter type "0bf3c7d4ef" add value if not exists 'unlock_instruction' after 'transfer_funds';
alter type "0bf3c7d4ef" add value if not exists 'approve_subsidy' after 'decrease_polyx_limit';
alter type "0bf3c7d4ef" add value if not exists 'revoke_subsidy' after 'approve_subsidy';
alter type "0bf3c7d4ef" add value if not exists 'accept_subsidy' after 'revoke_subsidy';
alter type "0bf3c7d4ef" add value if not exists 'remove_subsidy' after 'accept_subsidy';
alter type "0bf3c7d4ef" add value if not exists 'report_double_voting' after 'sumbit_unsigned';
alter type "0bf3c7d4ef" add value if not exists 'report_double_voting_unsigned' after 'report_double_voting';
alter type "0bf3c7d4ef" add value if not exists 'set_new_genesis' after 'report_double_voting_unsigned';
alter type "0bf3c7d4ef" add value if not exists 'report_fork_voting' after 'set_new_genesis';
alter type "0bf3c7d4ef" add value if not exists 'report_fork_voting_unsigned' after 'report_fork_voting';
alter type "0bf3c7d4ef" add value if not exists 'report_future_block_voting' after 'report_fork_voting_unsigned';
alter type "0bf3c7d4ef" add value if not exists 'report_future_block_voting_unsigned' after 'report_future_block_voting';
alter type "0bf3c7d4ef" add value if not exists 'eth_transact' after 'report_future_block_voting_unsigned';
alter type "0bf3c7d4ef" add value if not exists 'eth_instantiate_with_code' after 'eth_transact';
alter type "0bf3c7d4ef" add value if not exists 'eth_call' after 'eth_instantiate_with_code';
alter type "0bf3c7d4ef" add value if not exists 'eth_substrate_call' after 'eth_call';
alter type "0bf3c7d4ef" add value if not exists 'map_account' after 'eth_substrate_call';
alter type "0bf3c7d4ef" add value if not exists 'unmap_account' after 'map_account';
alter type "0bf3c7d4ef" add value if not exists 'dispatch_as_fallback_account' after 'unmap_account';


alter type "8f5a39c8ee" add value if not exists 'BurnedDebt' after 'Withdraw';
alter type "8f5a39c8ee" add value if not exists 'BurnedHeld' after 'BurnedDebt';
alter type "8f5a39c8ee" add value if not exists 'Held' after 'BurnedHeld';
alter type "8f5a39c8ee" add value if not exists 'MintedCredit' after 'Held';
alter type "8f5a39c8ee" add value if not exists 'Released' after 'MintedCredit';
alter type "8f5a39c8ee" add value if not exists 'TransferAndHold' after 'Released';
alter type "8f5a39c8ee" add value if not exists 'TransferOnHold' after 'TransferAndHold';
alter type "8f5a39c8ee" add value if not exists 'Unexpected' after 'TransferOnHold';
alter type "8f5a39c8ee" add value if not exists 'RootsPruned' after 'Slashed';
alter type "8f5a39c8ee" add value if not exists 'RootStored' after 'RootsPruned';
alter type "8f5a39c8ee" add value if not exists 'NFTHoldingsUpdated' after 'NFTPortfolioUpdated';
alter type "8f5a39c8ee" add value if not exists 'NewQueued' after 'ValidatorReenabled';
alter type "8f5a39c8ee" add value if not exists 'KeyRemoved' after 'KeyChanged';
alter type "8f5a39c8ee" add value if not exists 'InstructionUnlocked' after 'VenueSignersUpdated';
alter type "8f5a39c8ee" add value if not exists 'MandatoryReceiverAffirmationSet' after 'InstructionUnlocked';
alter type "8f5a39c8ee" add value if not exists 'AcceptedSubsidy' after 'UpdatedPolyxLimit';
alter type "8f5a39c8ee" add value if not exists 'ApprovedSubsidy' after 'AcceptedSubsidy';
alter type "8f5a39c8ee" add value if not exists 'RemovedPendingSubsidy' after 'ApprovedSubsidy';
alter type "8f5a39c8ee" add value if not exists 'RemovedSubsidy' after 'RemovedPendingSubsidy';
alter type "8f5a39c8ee" add value if not exists 'SubsidyDebited' after 'RemovedSubsidy';
alter type "8f5a39c8ee" add value if not exists 'EthExtrinsicRevert' after 'RootStored';

33 changes: 33 additions & 0 deletions db/migrations/13_add_identity_to_asset_transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
alter table "asset_transactions" add column if not exists "from_identity_id" text;
alter table "asset_transactions" add column if not exists "to_identity_id" text;

-- Backfill from portfolio IDs (format: did/portfolioNumber)
update "asset_transactions"
set "from_identity_id" = split_part("from_portfolio_id", '/', 1)
where "from_portfolio_id" is not null
and "from_identity_id" is null;

update "asset_transactions"
set "to_identity_id" = split_part("to_portfolio_id", '/', 1)
where "to_portfolio_id" is not null
and "to_identity_id" is null;

-- Backfill account-based transactions from the accounts table.
-- Note: this reflects the current identity association for the account,
-- not necessarily the identity at the time of the transaction.
update "asset_transactions" at
set "from_identity_id" = a."identity_id"
from "accounts" a
where at."from_account" = a."id"
and at."from_identity_id" is null
and a."identity_id" is not null;

update "asset_transactions" at
set "to_identity_id" = a."identity_id"
from "accounts" a
where at."to_account" = a."id"
and at."to_identity_id" is null
and a."identity_id" is not null;

create index if not exists "asset_transactions_from_identity_id" on "asset_transactions" ("from_identity_id");
create index if not exists "asset_transactions_to_identity_id" on "asset_transactions" ("to_identity_id");
65 changes: 65 additions & 0 deletions db/migrations/14_confidential_assets_events_8_chain.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
alter type "7a0b4cc03e" add value if not exists 'didregistrars' after 'revive';
alter type "7a0b4cc03e" add value if not exists 'polymeshtransactionpayment' after 'didregistrars';
alter type "7a0b4cc03e" add value if not exists 'multiblockmigrations' after 'polymeshtransactionpayment';
alter type "7a0b4cc03e" add value if not exists 'confidentialassets' after 'multiblockmigrations';

alter type "0bf3c7d4ef" add value if not exists 'force_set_cursor' after 'dispatch_as_fallback_account';
alter type "0bf3c7d4ef" add value if not exists 'force_set_active_cursor' after 'force_set_cursor';
alter type "0bf3c7d4ef" add value if not exists 'force_onboard_mbms' after 'force_set_active_cursor';
alter type "0bf3c7d4ef" add value if not exists 'clear_historic' after 'force_onboard_mbms';
alter type "0bf3c7d4ef" add value if not exists 'register_accounts' after 'clear_historic';
alter type "0bf3c7d4ef" add value if not exists 'register_encryption_keys' after 'register_accounts';
alter type "0bf3c7d4ef" add value if not exists 'register_account_assets' after 'register_encryption_keys';
alter type "0bf3c7d4ef" add value if not exists 'mint_asset' after 'register_account_assets';
alter type "0bf3c7d4ef" add value if not exists 'create_settlement' after 'mint_asset';
alter type "0bf3c7d4ef" add value if not exists 'sender_affirmation' after 'create_settlement';
alter type "0bf3c7d4ef" add value if not exists 'receiver_affirmation' after 'sender_affirmation';
alter type "0bf3c7d4ef" add value if not exists 'mediator_affirmation' after 'receiver_affirmation';
alter type "0bf3c7d4ef" add value if not exists 'sender_update_counter' after 'mediator_affirmation';
alter type "0bf3c7d4ef" add value if not exists 'sender_revert_affirmation' after 'sender_update_counter';
alter type "0bf3c7d4ef" add value if not exists 'receiver_revert_affirmation' after 'sender_revert_affirmation';
alter type "0bf3c7d4ef" add value if not exists 'receiver_claim' after 'receiver_revert_affirmation';
alter type "0bf3c7d4ef" add value if not exists 'batched_settlement' after 'receiver_claim';
alter type "0bf3c7d4ef" add value if not exists 'register_fee_accounts' after 'batched_settlement';
alter type "0bf3c7d4ef" add value if not exists 'topup_fee_accounts' after 'register_fee_accounts';
alter type "0bf3c7d4ef" add value if not exists 'submit_batched_proofs' after 'topup_fee_accounts';
alter type "0bf3c7d4ef" add value if not exists 'relayer_submit_batched_proofs' after 'submit_batched_proofs';
alter type "0bf3c7d4ef" add value if not exists 'execute_instant_settlement' after 'relayer_submit_batched_proofs';
alter type "0bf3c7d4ef" add value if not exists 'instant_sender_affirmation' after 'execute_instant_settlement';
alter type "0bf3c7d4ef" add value if not exists 'instant_receiver_affirmation' after 'instant_sender_affirmation';

alter type "8f5a39c8ee" add value if not exists 'AllowanceSpent' after 'CreatedAssetTransfer';
alter type "8f5a39c8ee" add value if not exists 'FundsTransferred' after 'TickerLinkedToAsset';
alter type "8f5a39c8ee" add value if not exists 'AccountAssetRegistered' after 'EthExtrinsicRevert';
alter type "8f5a39c8ee" add value if not exists 'AccountCurveTreeRootUpdated' after 'AccountAssetRegistered';
alter type "8f5a39c8ee" add value if not exists 'AccountRegistered' after 'AccountCurveTreeRootUpdated';
alter type "8f5a39c8ee" add value if not exists 'AccountStateLeafInserted' after 'AccountRegistered';
alter type "8f5a39c8ee" add value if not exists 'AssetCurveTreeRootUpdated' after 'AccountStateLeafInserted';
alter type "8f5a39c8ee" add value if not exists 'AssetMinted' after 'AssetCurveTreeRootUpdated';
alter type "8f5a39c8ee" add value if not exists 'AssetStateLeafUpdated' after 'AssetMinted';
alter type "8f5a39c8ee" add value if not exists 'AssetUpdated' after 'AssetStateLeafUpdated';
alter type "8f5a39c8ee" add value if not exists 'EncryptionKeyRegistered' after 'AssetUpdated';
alter type "8f5a39c8ee" add value if not exists 'FeeAccountCurveTreeRootUpdated' after 'EncryptionKeyRegistered';
alter type "8f5a39c8ee" add value if not exists 'FeeAccountDeposited' after 'FeeAccountCurveTreeRootUpdated';
alter type "8f5a39c8ee" add value if not exists 'FeeAccountStateLeafInserted' after 'FeeAccountDeposited';
alter type "8f5a39c8ee" add value if not exists 'FeeAccountUpdated' after 'FeeAccountStateLeafInserted';
alter type "8f5a39c8ee" add value if not exists 'FeeAccountWithdrawn' after 'FeeAccountUpdated';
alter type "8f5a39c8ee" add value if not exists 'MediatorAffirmed' after 'FeeAccountWithdrawn';
alter type "8f5a39c8ee" add value if not exists 'MediatorRejected' after 'MediatorAffirmed';
alter type "8f5a39c8ee" add value if not exists 'ReceiverAffirmationReverted' after 'MediatorRejected';
alter type "8f5a39c8ee" add value if not exists 'ReceiverAffirmed' after 'ReceiverAffirmationReverted';
alter type "8f5a39c8ee" add value if not exists 'ReceiverClaimed' after 'ReceiverAffirmed';
alter type "8f5a39c8ee" add value if not exists 'RelayerBatchedProofs' after 'ReceiverClaimed';
alter type "8f5a39c8ee" add value if not exists 'SenderAffirmationReverted' after 'RelayerBatchedProofs';
alter type "8f5a39c8ee" add value if not exists 'SenderAffirmed' after 'SenderAffirmationReverted';
alter type "8f5a39c8ee" add value if not exists 'SenderCounterUpdated' after 'SenderAffirmed';
alter type "8f5a39c8ee" add value if not exists 'SettlementCreated' after 'SenderCounterUpdated';
alter type "8f5a39c8ee" add value if not exists 'SettlementStatusUpdated' after 'SettlementCreated';
alter type "8f5a39c8ee" add value if not exists 'HistoricCleared' after 'SettlementStatusUpdated';
alter type "8f5a39c8ee" add value if not exists 'MigrationAdvanced' after 'HistoricCleared';
alter type "8f5a39c8ee" add value if not exists 'MigrationCompleted' after 'MigrationAdvanced';
alter type "8f5a39c8ee" add value if not exists 'MigrationFailed' after 'MigrationCompleted';
alter type "8f5a39c8ee" add value if not exists 'MigrationSkipped' after 'MigrationFailed';
alter type "8f5a39c8ee" add value if not exists 'UpgradeCompleted' after 'MigrationSkipped';
alter type "8f5a39c8ee" add value if not exists 'UpgradeFailed' after 'UpgradeCompleted';
alter type "8f5a39c8ee" add value if not exists 'UpgradeStarted' after 'UpgradeFailed';
1 change: 1 addition & 0 deletions db/migrations/15_add_missing_transfer_nft.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter type "0bf3c7d4ef" add value if not exists 'transfer_nft' after 'redeem_nft';
20 changes: 9 additions & 11 deletions db/schemaMigrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getMigrationVersion = (fileName: string): number | null => {
const match = fileName.match(regex);

if (match && match.length >= 2) {
return parseInt(match[1]);
return Number.parseInt(match[1]);
}

return null; // Return null if the version number is not found or invalid
Expand All @@ -41,24 +41,22 @@ export const schemaMigrations = async (dataSource?: DataSource): Promise<void> =
const migrationDetails = await getLastMigrationFromDB(postgres);
lastMigration = migrationDetails?.lastMigration || 0;
} catch (e) {
console.log(`Error message: ${e.message}`);
console.log(`Error message: ${(e as Error).message}`);
}

const queries: string[] = [];

const migrations = readdirSync('../db/migrations');

console.log(`Last executed migration sequence - ${lastMigration}`);

for (const file of migrations) {
const fileVersion = getMigrationVersion(file);
const migrations = readdirSync('../db/migrations')
.map(file => ({ file, version: getMigrationVersion(file) || 0 }))
.filter(m => m.version > lastMigration)
.sort((a, b) => a.version - b.version);

if (fileVersion && fileVersion > lastMigration) {
console.log(`Collecting migration file - ${file}`);
for (const { file, version } of migrations) {
console.log(`Collecting migration file - ${file}`);

queries.push(readFileSync(`../db/migrations/${file}`, 'utf-8'));
queries.push(migrationInsert(fileVersion));
}
queries.push(readFileSync(`../db/migrations/${file}`, 'utf-8'), migrationInsert(version));
}

if (queries.length > 0) {
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ services:
# Polymesh-local
NETWORK_ENDPOINT: ws://host.docker.internal:9944
# Setting NETWORK_HTTP_ENDPOINT will allow dynamic lookup of NETWORK_CHAIN_ID
NETWORK_HTTP_ENDPOINT: 'http://host.docker.internal:9933'
# NETWORK_HTTP_ENDPOINT: 'http://host.docker.internal:9933'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncomment and change to port 9944 - v8 chains use the same port for WS and HTTP

# Staging
# NETWORK_ENDPOINT: wss://staging-rpc.polymesh.dev/
# NETWORK_CHAIN_ID: '0x3c3183f6d701500766ff7d147b79c4f10014a095eaaa98e960dcef6b3ead50ee'
NETWORK_CHAIN_ID: '0x6c191a0da0933134971d11575424a0558d773684a3b00c45b6ab14da4c2c1fe6'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this to 0x3c3183f6d701500766ff7d147b79c4f10014a095eaaa98e960dcef6b3ead50ee (staging genesis hash) and comment out

# NETWORK_DICTIONARY: https://subql-dictionary.polymesh.dev
# Testnet
# NETWORK_ENDPOINT: wss://testnet-rpc.polymesh.live
Expand All @@ -50,7 +50,7 @@ services:
# NETWORK_DICTIONARY: https://mainnet-subql-dictionary.polymesh.network/
command:
- -f=/app # Path of the project
- --batch-size=50 # Batch size of blocks to fetch in one round
- --batch-size=250 # Batch size of blocks to fetch in one round
# - --scale-batch-size # scale batch size based on memory usage. To know more about the process - https://github.com/subquery/subql/blob/c9bc9733deef726f78fa48387e74e52f8d6ca8d2/packages/node/src/indexer/fetch.service.ts#L88
# - --timeout=3600 # Timeout for indexer sandbox to execute the mapping functions (in seconds)
# - --local # This is now deprecated
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "polymesh-subquery",
"version": "19.3.1",
"version": "19.6.0",
"author": "Polymesh Association",
"license": "Apache-2.0",
"description": "A Polymesh Chain Indexer, providing a GraphQL interface",
"main": "dist/index.js",
"scripts": {
"build": "subql build",
"sql": "ts-node scripts/run-sql.ts",
"run:dev": "subql-node -f=./ --batch-size=50",
"migrations": "ts-node scripts/run-migrations.ts",
"prepack": "rm -rf dist && yarn build",
"prepare": "husky install",
Expand Down Expand Up @@ -35,8 +36,8 @@
"dependencies": {
"@polkadot/api": "^16.5.2",
"@polkadot/types-support": "^16.5.2",
"@polymeshassociation/polymesh-types": "^7.2.0",
"@subql/cli": "^6.6.0",
"@polymeshassociation/polymesh-types": "^7.4.0",
"@subql/cli": "^6.6.3",
"@subql/types": "^3.15.0",
"@subql/types-core": "^2.2.0",
"bignumber.js": "^9.0.2",
Expand Down
20 changes: 15 additions & 5 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const chainId = process.env.NETWORK_CHAIN_ID || '';
const endpoint = process.env.NETWORK_ENDPOINT || '';
const dictionary = process.env.NETWORK_DICTIONARY || '';

const filters = {
const filters: Record<string, Record<string, string[]>> = {
asset: {
AssetAffirmationExemption: [],
AssetBalanceUpdated: ['handleAssetBalanceUpdated'],
Expand Down Expand Up @@ -216,7 +216,8 @@ const filters = {
ProposalFailedToExecute: [],
},
nft: {
NFTPortfolioUpdated: ['handleNftPortfolioUpdates'],
NFTPortfolioUpdated: ['handleNftHoldingsUpdates'],
NFTHoldingsUpdated: ['handleNftHoldingsUpdates'],
NftCollectionCreated: ['handleNftCollectionCreated'],
},
pips: {
Expand Down Expand Up @@ -260,6 +261,7 @@ const filters = {
settlement: {
AffirmationWithdrawn: ['handleAffirmationWithdrawn'],
FailedToExecuteInstruction: ['handleFailedToExecuteInstruction'],
FundsTransferred: ['handleFundsTransferred'],
InstructionAffirmed: ['handleInstructionUpdate'],
InstructionAutomaticallyAffirmed: ['handleAutomaticAffirmation'],
InstructionAuthorized: ['handleInstructionUpdate'],
Expand Down Expand Up @@ -362,6 +364,14 @@ const filters = {
RewardPaymentSchedulingInterrupted: [],
SlashingAllowedForChanged: [],
},
confidentialAssets: {},
didregistrars: {},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be didRegistrars (camelCase) to match the expected pallet name

polymeshTransactionPayment: {},
multiBlockMigrations: {},
beefy: {},
revive: {},
stateTrieMigration: {},
electionProviderMultiPhase: {},
};

const handlers: SubstrateEventHandler[] = [];
Expand All @@ -375,7 +385,7 @@ Object.keys(filters).forEach(module => {
filter: {
module,
},
} as SubstrateEventHandler);
});
}

Object.keys(filters[module]).forEach(method => {
Expand All @@ -387,7 +397,7 @@ Object.keys(filters).forEach(module => {
module,
method,
},
} as SubstrateEventHandler);
});
}

if (filters[module][method].length > 0) {
Expand All @@ -401,7 +411,7 @@ Object.keys(filters).forEach(module => {
module,
method,
},
} as SubstrateEventHandler);
});
});
}
});
Expand Down
Loading
Loading