This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into subspace-testnet-preparation
- Loading branch information
Showing
4 changed files
with
73 additions
and
28 deletions.
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
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
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,42 @@ | ||
import * as fsp from "fs/promises"; | ||
import { BN } from '@polkadot/util'; | ||
|
||
import { ChainName } from './types'; | ||
|
||
// TODO: consider providing fs methods to constructor | ||
class State { | ||
lastBlockPath: string; | ||
feedsPath: string; | ||
|
||
constructor({ folder }: { folder: string; }) { | ||
this.lastBlockPath = `${folder}/last_processed_block.json`; | ||
this.feedsPath = `${folder}/feeds.json`; | ||
} | ||
|
||
async saveLastProcessedBlock(chain: ChainName, number: BN): Promise<void> { | ||
const file = await fsp.readFile(this.lastBlockPath, 'utf8'); | ||
const lastProcessedBlockRecord = JSON.parse(file); | ||
|
||
lastProcessedBlockRecord[chain] = number; | ||
|
||
await fsp.writeFile(this.lastBlockPath, JSON.stringify(lastProcessedBlockRecord, null, 4)); | ||
} | ||
|
||
async getFeedIdByAddress(address: string): Promise<string> { | ||
const file = await fsp.readFile(this.feedsPath, 'utf8'); | ||
const feeds = JSON.parse(file); | ||
|
||
return feeds[address]; | ||
} | ||
|
||
async saveFeedId(address: string, feedId: BN): Promise<void> { | ||
const file = await fsp.readFile(this.feedsPath, 'utf8'); | ||
const feeds = JSON.parse(file); | ||
|
||
feeds[address] = feedId.toBn(); | ||
|
||
await fsp.writeFile(this.feedsPath, JSON.stringify(feeds, null, 4)); | ||
} | ||
} | ||
|
||
export default State; |
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