Skip to content

Commit

Permalink
Reconcile destroyed markets on testnet (#217)
Browse files Browse the repository at this point in the history
* Add handler marketDestroyed

* Connect handler to processor

* Add marketIds to hook destroyMarkets

* Connect handler only to bsr network

* Resolve db txn conflicts
  • Loading branch information
saboonikhil committed Nov 11, 2022
1 parent f92a146 commit 63e6a43
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/mappings/postHooks/marketDestroyed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { BlockHandlerContext } from '@subsquid/substrate-processor';
import { Store } from '@subsquid/typeorm-store';
import { HistoricalMarket, Market } from '../../model';

export async function destroyMarkets(ctx: BlockHandlerContext<Store>) {
const mIds = [
8, 9, 10, 11, 12, 16, 17, 19, 20, 26, 27, 28, 37, 38, 39, 42, 43, 45, 50, 51, 52, 53, 57,
58, 66, 67, 92, 105, 112, 124, 126, 134, 135, 137, 151, 152, 158, 159, 161, 162, 165, 182,
191, 202, 232, 239, 252, 253, 257, 258, 265, 266, 283, 284, 312, 328, 333, 334, 335, 344,
];

await Promise.all(
mIds.map(async (mId) => {
let market = await ctx.store.get(Market, { where: { marketId: mId } });
if (!market) return;

market.status = 'Destroyed';
console.log(`[postHooks.destroyMarkets] Saving market: ${JSON.stringify(market, null, 2)}`);
await ctx.store.save<Market>(market);

let hm = new HistoricalMarket();
hm.id = '0000579140-000000-9634e-' + market.marketId;
hm.marketId = market.marketId;
hm.event = 'MarketDestroyed';
hm.status = market.status;
hm.blockNumber = ctx.block.height;
hm.timestamp = new Date(ctx.block.timestamp);
console.log(`[postHooks.destroyMarkets] Saving historical market: ${JSON.stringify(hm, null, 2)}`);
await ctx.store.save<HistoricalMarket>(hm);
})
)
}
5 changes: 4 additions & 1 deletion src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { balancesBalanceSet, balancesDustLost, balancesEndowed, balancesReserved
balancesTransferOld, balancesUnreserved, balancesWithdraw } from './mappings/balances';
import { currencyDeposited, currencyTransferred, currencyWithdrawn } from './mappings/currency';
import { parachainStakingRewarded } from './mappings/parachainStaking';
import { destroyMarkets } from './mappings/postHooks/marketDestroyed';
import { boughtCompleteSet, marketApproved, marketClosed, marketCreated, marketDestroyed, marketDisputed,
marketExpired, marketInsufficientSubsidy, marketRejected, marketReported, marketResolved,
marketStartedWithSubsidy, soldCompleteSet, tokensRedeemed} from './mappings/predictionMarkets';
Expand All @@ -26,7 +27,7 @@ processor.setDataSource({
archive: process.env.INDEXER_ENDPOINT_URL ?? 'https://indexer.zeitgeist.pm/graphql',
chain: process.env.WS_NODE_URL ?? 'wss://bsr.zeitgeist.pm',
});
// processor.setBlockRange({from: 832, to: 832})
//processor.setBlockRange({from: 579140, to: 579140})

processor.addEventHandler('Balances.BalanceSet', ctx => balancesBalanceSet(ctx))
processor.addEventHandler('Balances.DustLost', ctx => balancesDustLost(ctx))
Expand Down Expand Up @@ -76,6 +77,8 @@ if (!process.env.WS_NODE_URL?.includes(`bs`)) {
processor.addEventHandler('Balances.Transfer', {range: {from: 588250}}, ctx => balancesTransfer(ctx))
processor.addEventHandler('System.ExtrinsicFailed', {range: {from: 0, to: 588249}}, ctx => systemExtrinsicFailed(ctx))
processor.addEventHandler('System.ExtrinsicSuccess', {range: {from: 0, to: 588249}}, ctx => systemExtrinsicSuccess(ctx))

processor.addPostHook({range: {from: 579140, to: 579140}}, ctx => destroyMarkets(ctx))
}

processor.run()

0 comments on commit 63e6a43

Please sign in to comment.