-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reconcile destroyed markets on testnet (#217)
* 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
1 parent
f92a146
commit 63e6a43
Showing
2 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters